Q. In a binary tree, what is the maximum number of nodes at depth d?
-
A.
d
-
B.
2^d
-
C.
2^(d+1) - 1
-
D.
d^2
Solution
The maximum number of nodes at depth d in a binary tree is 2^d.
Correct Answer:
B
— 2^d
Learn More →
Q. In a graph represented by an adjacency list, what is the space complexity?
-
A.
O(V)
-
B.
O(E)
-
C.
O(V + E)
-
D.
O(V * E)
Solution
The space complexity of a graph represented by an adjacency list is O(V + E), where V is the number of vertices and E is the number of edges.
Correct Answer:
C
— O(V + E)
Learn More →
Q. In a queue implemented using two stacks, what is the time complexity of the dequeue operation in the worst case?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n log n)
Solution
In the worst case, the dequeue operation may require transferring all elements from one stack to another, resulting in O(n) time complexity.
Correct Answer:
B
— O(n)
Learn More →
Q. In a singly linked list, how can you find the middle element in one pass?
-
A.
Use two pointers
-
B.
Count nodes first
-
C.
Use recursion
-
D.
Use a stack
Solution
By using two pointers, where one moves twice as fast as the other, you can find the middle element in one pass.
Correct Answer:
A
— Use two pointers
Learn More →
Q. What is the average time complexity of accessing an element in an array?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n log n)
Solution
Accessing an element in an array by index is a constant time operation, O(1).
Correct Answer:
A
— O(1)
Learn More →
Q. What is the space complexity of a recursive function that uses a linked list to store n elements?
-
A.
O(1)
-
B.
O(n)
-
C.
O(n^2)
-
D.
O(log n)
Solution
The space complexity is O(n) due to the storage of n elements in the linked list.
Correct Answer:
B
— O(n)
Learn More →
Q. What is the time complexity of finding the maximum element in an unsorted array?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(n log n)
-
D.
O(1)
Solution
To find the maximum element in an unsorted array, you must check each element, resulting in O(n) time complexity.
Correct Answer:
A
— O(n)
Learn More →
Q. What is the worst-case time complexity for inserting an element at the beginning of a singly linked list?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n log n)
Solution
Inserting at the beginning of a singly linked list is a constant time operation, O(1).
Correct Answer:
A
— O(1)
Learn More →
Q. What is the worst-case time complexity of insertion sort?
-
A.
O(n)
-
B.
O(n log n)
-
C.
O(n^2)
-
D.
O(log n)
Solution
The worst-case time complexity of insertion sort occurs when the array is sorted in reverse order, resulting in O(n^2).
Correct Answer:
C
— O(n^2)
Learn More →
Q. Which algorithm is used to detect a cycle in a linked list?
-
A.
Depth First Search
-
B.
Breadth First Search
-
C.
Floyd's Cycle Detection
-
D.
Dijkstra's Algorithm
Solution
Floyd's Cycle Detection algorithm, also known as the tortoise and hare algorithm, is used to detect cycles in a linked list.
Correct Answer:
C
— Floyd's Cycle Detection
Learn More →
Q. Which data structure is best suited for implementing a priority queue?
-
A.
Array
-
B.
Linked List
-
C.
Heap
-
D.
Stack
Solution
A heap is the most efficient data structure for implementing a priority queue, allowing for O(log n) insertion and deletion.
Correct Answer:
C
— Heap
Learn More →
Q. Which of the following operations can be performed in O(1) time on a stack?
-
A.
Push
-
B.
Pop
-
C.
Peek
-
D.
All of the above
Solution
All operations (push, pop, and peek) can be performed in O(1) time on a stack.
Correct Answer:
D
— All of the above
Learn More →
Showing 1 to 12 of 12 (1 Pages)