Q. In a singly linked list, how do you insert a new node at the beginning?
-
A.
Create a new node and point it to the head
-
B.
Point the head to the new node
-
C.
Insert at the end
-
D.
None of the above
Solution
To insert a new node at the beginning, create a new node and set its next pointer to the current head.
Correct Answer:
A
— Create a new node and point it to the head
Learn More →
Q. What is the time complexity of bubble sort in the worst case?
-
A.
O(n)
-
B.
O(n log n)
-
C.
O(n^2)
-
D.
O(log n)
Solution
Bubble sort has a worst-case time complexity of O(n^2) due to the nested loops.
Correct Answer:
C
— O(n^2)
Learn More →
Q. What is the time complexity of inserting an element at the end of a dynamic array?
-
A.
O(1)
-
B.
O(n)
-
C.
O(log n)
-
D.
O(n^2)
Solution
Inserting at the end of a dynamic array is O(1) on average, but can be O(n) if resizing is needed.
Correct Answer:
A
— O(1)
Learn More →
Q. Which data structure is more efficient for implementing a queue?
-
A.
Array
-
B.
Linked List
-
C.
Stack
-
D.
Tree
Solution
A linked list is more efficient for implementing a queue as it allows dynamic size and easy insertion/removal.
Correct Answer:
B
— Linked List
Learn More →
Showing 1 to 4 of 4 (1 Pages)