Answer the following - java related: What is the worst case time complexity for
ID: 3910256 • Letter: A
Question
Answer the following - java related:
What is the worst case time complexity for accessing an element in an array?
O(1) - Constant Time
O(N) - Linear Time
O(N^2) - Quadratic Time
O(Log N) - Logarithmic Time
What is the worst-case time complexity to find the index of an object in an array?
O(1) - Constant Time
O(N) - Linear Time
O(N^2) - Quadratic Time
O(Log N) - Logarithmic Time
Which properties do circular doubly linked lists have?
Forward pointer
Backwards pointer
Last node points back to the first node
First node points back to the last node
What is the worst-case time complexity to find the index of an object in a linked list?
O(1) - Constant Time
O(N) - Linear Time
O(N^2) - Quadratic Time
O(Log N) - Logarithmic Time
What value is printed out from the code below?
public void square(double x) {
double x = x * x;
}
:
double val = 10;
square(val);
System.out.println(val);
O(1) - Constant Time
O(N) - Linear Time
O(N^2) - Quadratic Time
O(Log N) - Logarithmic Time
Explanation / Answer
What is the worst case time complexity for accessing an element in an array? :: It will be constant for array to access any index.
So time complexity will be :: O(1) - Constant Time
What is the worst-case time complexity to find the index of an object in an array? : : :
There may be the case that the element will be at the end. In that case need to access the last element . So worst case time complexity is Worst-case performance O(n)
Which properties do circular doubly linked lists have? :::
As it is doubly linked lists last node will point to first node and first node will point to last node
Last node points back to the first node
First node points back to the last node
What is the worst-case time complexity to find the index of an object in a linked list?
In this case also need to traval all node so it will take linear time so time complexity will be : O(n)Linear Time
Below line of code will cause error.
public void square(double x) {
//below again declaring variable x that will cause the problem in compilation
double x = x * x;
}
:
double val = 10;
square(val);
System.out.println(val);