Q. Given a linked list, how can you determine if it contains a cycle?
-
A.
Using a hash table
-
B.
Using two pointers
-
C.
Using recursion
-
D.
All of the above
Solution
You can use a hash table to track visited nodes, two pointers to detect cycles, or recursion to check for cycles, making all methods valid.
Correct Answer:
D
— All of the above
Learn More →
Q. What is the space complexity of a recursive function that uses a stack to store function calls?
-
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.
Correct Answer:
B
— O(n)
Learn More →
Q. What is the space complexity of storing a linked list with n nodes?
-
A.
O(1)
-
B.
O(n)
-
C.
O(n^2)
-
D.
O(log n)
Solution
A linked list with n nodes requires O(n) space, as each node stores data and a pointer to the next node.
Correct Answer:
B
— O(n)
Learn More →
Q. What is the time complexity of merging two sorted arrays of sizes m and n?
-
A.
O(m + n)
-
B.
O(m * n)
-
C.
O(log(m + n))
-
D.
O(n)
Solution
Merging two sorted arrays takes linear time, O(m + n), as we traverse both arrays.
Correct Answer:
A
— O(m + n)
Learn More →
Q. What is the worst-case time complexity of 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. Which of the following data structures can be used to implement a queue?
-
A.
Array
-
B.
Linked List
-
C.
Stack
-
D.
Both Array and Linked List
Solution
Both arrays and linked lists can be used to implement a queue, as they can both support FIFO operations.
Correct Answer:
D
— Both Array and Linked List
Learn More →
Showing 1 to 6 of 6 (1 Pages)