Q. In a binary search tree, what is the time complexity for inserting an element in the average case?
-
A.
O(1)
-
B.
O(log n)
-
C.
O(n)
-
D.
O(n log n)
Solution
In a balanced binary search tree, the average-case time complexity for insertion is O(log n).
Correct Answer:
B
— O(log n)
Learn More →
Q. In a binary search tree, what is the time complexity of searching for an element in the average case?
-
A.
O(1)
-
B.
O(log n)
-
C.
O(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:
B
— O(log n)
Learn More →
Q. In a complete binary tree, what is the maximum number of nodes at level 'h'?
-
A.
2^h
-
B.
2^(h+1) - 1
-
C.
h^2
-
D.
h!
Solution
In a complete binary tree, the maximum number of nodes at level 'h' is 2^h.
Correct Answer:
A
— 2^h
Learn More →
Q. What is the space complexity of a recursive function that uses a stack for function calls?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n^2)
Solution
The space complexity of a recursive function is O(n) due to the stack space used for function calls.
Correct Answer:
B
— O(n)
Learn More →
Q. What is the time complexity of a linear search in an array?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n log n)
Solution
Linear search checks each element one by one, resulting in a time complexity of O(n).
Correct Answer:
B
— O(n)
Learn More →
Q. What is the time complexity of a linear search in an unsorted array?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n log n)
Solution
A linear search requires checking each element, leading to a time complexity of O(n).
Correct Answer:
B
— O(n)
Learn More →
Q. What is the time complexity of deleting an element from a doubly linked list?
-
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, the deletion operation can be performed in constant time, O(1).
Correct Answer:
A
— O(1)
Learn More →
Q. What is the time complexity of deleting an element from a singly linked list when the pointer to the node is given?
-
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, the deletion can be done in O(1) time.
Correct Answer:
A
— O(1)
Learn More →
Q. What is the time complexity of the quicksort algorithm in the worst case?
-
A.
O(n)
-
B.
O(n log n)
-
C.
O(n^2)
-
D.
O(log n)
Solution
In the worst case, quicksort can degrade to O(n^2) time complexity, typically when the pivot is the smallest or largest element.
Correct Answer:
C
— O(n^2)
Learn More →
Q. What is the worst-case time complexity for searching an element in a linked list?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n^2)
Solution
In the worst case, you may have to traverse the entire linked list to find an element, resulting in O(n) time complexity.
Correct Answer:
B
— O(n)
Learn More →
Q. Which data structure is used to implement a queue?
-
A.
Array
-
B.
Linked List
-
C.
Both Array and Linked List
-
D.
None of the above
Solution
A queue can be implemented using both arrays and linked lists, depending on the requirements.
Correct Answer:
C
— Both Array and Linked List
Learn More →
Q. Which of the following operations on a stack has a time complexity of O(1)?
-
A.
Push
-
B.
Pop
-
C.
Peek
-
D.
All of the above
Solution
All operations (Push, Pop, and Peek) on a stack are performed in constant time, O(1).
Correct Answer:
D
— All of the above
Learn More →
Showing 1 to 12 of 12 (1 Pages)