Q. In a binary search tree, what is the time complexity for searching for an element in the average case?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n log n)
Solution
In a balanced binary search tree, the average time complexity for searching an element is O(log n).
Correct Answer:
C
— O(log n)
Learn More →
Q. In a binary tree, what is the maximum number of nodes at level k?
-
A.
k
-
B.
2^k
-
C.
2^(k+1)
-
D.
k^2
Solution
In a binary tree, the maximum number of nodes at level k is 2^k, as each node can have two children.
Correct Answer:
B
— 2^k
Learn More →
Q. In a singly linked list, what is the time complexity to insert an element at the beginning?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n^2)
Solution
Inserting an element at the beginning of a singly linked list is done by adjusting the head pointer, which takes constant time, O(1).
Correct Answer:
A
— O(1)
Learn More →
Q. What is the average time complexity for searching an element in a sorted array using binary search?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(n log n)
-
D.
O(1)
Solution
Binary search divides the array in half each time, leading to a time complexity of O(log n) for searching.
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of deleting a node from a linked list when you have a pointer to that node?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n^2)
Solution
If you have a pointer to the node to be deleted, you can delete it in constant time O(1) by adjusting pointers.
Correct Answer:
A
— O(1)
Learn More →
Q. What is the time complexity of inserting an element into a stack implemented using an array?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n log n)
Solution
Inserting an element into a stack (push operation) implemented using an array takes constant time, O(1).
Correct Answer:
A
— O(1)
Learn More →
Q. Which of the following operations has a time complexity of O(n) in a linked list?
-
A.
Accessing an element
-
B.
Inserting at the end
-
C.
Deleting a node
-
D.
Searching for a value
Solution
Searching for a value in a linked list requires traversing the list, which takes O(n) time in the worst case.
Correct Answer:
D
— Searching for a value
Learn More →
Showing 1 to 7 of 7 (1 Pages)