Q. In a binary tree, what is the time complexity of traversing all nodes using in-order traversal?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n log n)
Solution
In-order traversal visits each node exactly once, resulting in a time complexity of O(n).
Correct Answer:
B
— O(n)
Learn More →
Q. In a doubly linked list, what is the time complexity of deleting a node given 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 adjust the pointers of the adjacent nodes in constant time, so the time complexity is O(1).
Correct Answer:
A
— O(1)
Learn More →
Q. What is the average time complexity of searching for an element in an unsorted array?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n^2)
Solution
In an unsorted array, you may need to check each element until you find the target, leading to an average time complexity of O(n).
Correct Answer:
B
— O(n)
Learn More →
Q. What is the space complexity of a linked list?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n^2)
Solution
A linked list requires space for each node, which is proportional to the number of elements, leading to a space complexity of O(n).
Correct Answer:
B
— O(n)
Learn More →
Q. What is the space complexity of a recursive function that uses a stack to perform depth-first search on a graph?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n^2)
Solution
The space complexity is O(n) due to the maximum depth of the recursion stack in the worst case.
Correct Answer:
B
— O(n)
Learn More →
Q. What is the time complexity of deleting an element from a queue implemented using a linked list?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n^2)
Solution
Deleting an element from the front of a queue implemented with a linked list is done in constant time, O(1).
Correct Answer:
A
— O(1)
Learn More →
Q. What is the worst-case time complexity for searching an element in an unsorted 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, leading to O(n) time complexity.
Correct Answer:
B
— O(n)
Learn More →
Q. Which data structure allows for FIFO (First In First Out) access?
-
A.
Stack
-
B.
Queue
-
C.
Array
-
D.
Linked List
Solution
A queue is designed to allow FIFO access, where the first element added is the first one to be removed.
Correct Answer:
B
— Queue
Learn More →
Q. Which of the following operations has the worst time complexity in a singly linked list?
-
A.
Accessing an element
-
B.
Inserting an element
-
C.
Deleting an element
-
D.
Traversing the list
Solution
Accessing an element in a singly linked list requires traversal from the head to the desired node, which takes O(n) time in the worst case.
Correct Answer:
A
— Accessing an element
Learn More →
Showing 1 to 9 of 9 (1 Pages)