# Singly linked list MCQs

What is a singly linked list?

a) A data structure where each node points to the next node

b) A data structure where each node points to both the previous and next nodes

c) A data structure where each node points to the previous node

d) A circular data structure where nodes point to each other

Answer: a) A data structure where each node points to the next node

What is the 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)

Answer: a) O(1)

Which of the following operations requires traversing a singly linked list?

a) Inserting at the beginning

b) Deleting from the beginning

c) Accessing the last element

d) All of the above

Answer: c) Accessing the last element

What is the time complexity of deleting the first element of a singly linked list?

a) O(1)

b) O(n)

c) O(log n)

d) O(n log n)

Answer: a) O(1)

In a singly linked list, each node contains:

a) A data part and a pointer to the previous node

b) Only a data part

c) A data part and a pointer to the next node

d) A data part and pointers to both previous and next nodes

Answer: c) A data part and a pointer to the next node

How do you traverse a singly linked list?

a) By following the pointers from one node to the next

b) By using an index

c) By accessing elements directly

d) By using a stack

Answer: a) By following the pointers from one node to the next

Which of the following is the correct way to delete the node after a given node in a singly linked list?

a) Adjust the pointer of the given node to skip the next node

b) Adjust the pointer of the next node to point to the given node

c) Delete the given node

d) None of the above

Answer: a) Adjust the pointer of the given node to skip the next node

What is the time complexity of searching for an element in a singly linked list?

a) O(1)

b) O(n)

c) O(log n)

d) O(n log n)

Answer: b) O(n)

How do you insert a new node after a given node in a singly linked list?

a) Set the new node’s pointer to the next node, then adjust the given node’s pointer to the new node

b) Set the given node’s pointer to the new node, then set the new node’s pointer to the next node

c) Set the new node’s pointer to the previous node

d) Set the new node’s pointer to the first node

Answer: a) Set the new node’s pointer to the next node, then adjust the given node’s pointer to the new node

Which of the following is true about the head node in a singly linked list?

a) It contains the largest value in the list

b) It points to the first node of the list

c) It points to the last node of the list

d) It is always null

Answer: b) It points to the first node of the list

What is the time complexity of inserting an element at the end of a singly linked list if the tail pointer is not maintained?

a) O(1)

b) O(log n)

c) O(n)

d) O(n log n)

Answer: c) O(n)

What is the key disadvantage of using a singly linked list?

a) It requires more memory than an array

b) It does not allow random access of elements

c) It is difficult to implement

d) It is less efficient for large datasets

Answer: b) It does not allow random access of elements

Which of the following operations is not possible with a singly linked list?

a) Insertion at the end

b) Deletion from the beginning

c) Traversing in reverse order

d) Searching for an element

Answer: c) Traversing in reverse order

What is the time complexity of accessing the nth element in a singly linked list?

a) O(1)

b) O(n)

c) O(log n)

d) O(n log n)

Answer: b) O(n)

Which of the following statements is true about singly linked lists?

a) They can be traversed in both directions

b) They use more memory than doubly linked lists

c) They allow efficient insertion and deletion from both ends

d) They allow efficient insertion and deletion from the beginning

Answer: d) They allow efficient insertion and deletion from the beginning

How do you find the length of a singly linked list?

a) By traversing the list and counting the nodes

b) By accessing the length property

c) By using a counter variable during insertion and deletion

d) Both a and c

Answer: d) Both a and c

In a singly linked list, what is the term used for the last node?

a) Head

b) Tail

c) End

d) Final

Answer: b) Tail

What happens if you try to delete a node from an empty singly linked list?

a) The list becomes undefined

b) The list becomes null

c) An error occurs

d) Nothing happens

Answer: c) An error occurs

Which of the following best describes a node in a singly linked list?

a) It contains a value and two pointers

b) It contains a value and a pointer to the next node

c) It contains only a value

d) It contains a value and a pointer to the previous node

Answer: b) It contains a value and a pointer to the next node

How do you delete a singly linked list?

a) Set the head to null

b) Free each node one by one

c) Use a loop to delete all nodes

d) Both b and c

Answer: d) Both b and c