Q. In a doubly linked list, what is the time complexity for deleting a node given a pointer to that node?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
Deletion of a node in a doubly linked list can be done in O(1) time if you have a pointer to the node.
Correct Answer:
A
— O(1)
Learn More →
Q. In a singly linked list, how do you find the middle element?
A.
Traverse the list twice
B.
Use two pointers
C.
Count elements first
D.
Use a stack
Show solution
Solution
Using two pointers, where one moves twice as fast as the other, allows you to find the middle element in O(n) time.
Correct Answer:
B
— Use two pointers
Learn More →
Q. What is the average time complexity for inserting an element at the end of a dynamic array?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
While inserting at the end is O(1) on average, it can be O(n) when the array needs to be resized.
Correct Answer:
B
— O(n)
Learn More →
Q. What is the space complexity of a recursive function that uses a stack?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
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 deleting the last element from a singly linked list?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
To delete the last element from a singly linked list, you must traverse the list to find the second-to-last element, resulting in O(n) time complexity.
Correct Answer:
B
— O(n)
Learn More →
Q. Which of the following operations has a time complexity of O(n) in a singly linked list?
A.
Insertion at head
B.
Insertion at tail
C.
Deletion at head
D.
Accessing an element by index
Show solution
Solution
Accessing an element by index in a singly linked list requires traversing the list, which takes O(n) time.
Correct Answer:
D
— Accessing an element by index
Learn More →
Showing 1 to 6 of 6 (1 Pages)