Linked List MCQs
Linked List MCQs
2) What is the optimal time complexity to count the number of nodes in a linked
list?
A)O(n)
B)O(1)
C)O(log n)
D)None of the above
Answer:A
3) What will be the output of the following code snippet for the list 1->2->3->4->5->6?
void solve(struct node* start)
{
if(start == NULL)
return;
printf("%d ", start->data);
if(start->next != NULL )
solve(start->next->next);
printf("%d ", start->data);
}
A)1 2 3 4 5 6
B)1 3 5 5 3 1
C)1 3 5 1 3 5
D)2 4 6 1 3 5
Answer:B
4)Which of the following are applications of linked lists?
A)Implementing file systems
B)Chaining in hash tables
C)Binary Trees implementation
D)All of the above
Answer:D
5)Insertion of an element at the middle of a linked list requires the modification of how
many pointers?
A)2
B)1
C)3
D)4
Answer:A
6)Insertion of an element at the ends of a linked list requires the modification of how
many pointers?
A)2
B)1
C)3
D)4
Answer: B
7.
In the worst case, the number of comparisons needed to search a singly linked list of
length n for a given element will be?
A)O(log n)
B)O(n)
C)O(1)
D)None of the above
Answer:B
8)Which of the following algorithms is not feasible to implement in a linked list?
A)Linear Search
B)Merge Sort
C)Insertion Sort
D)Binary Search
Answer: D
9.
What will be the value of “sum” after the following code snippet terminates?
void solve(ListNode* root) {
/*
The LinkedList is defined as:
root-> val = value of the node
root-> next = address of next element from the node
The List is 1 -> 2 -> 3 -> 4 -> 5
*/
int sum = 0;
while (root != NULL) {
sum += root -> val;
root = root -> next;
}
cout << sum << endl;
}
A)15
B)20
C)5
D)1
Answer: A
10)
Which of the following can be done with LinkedList?
A)Implementation of Stacks and Queues.
B)Implementation of Binary Trees.
C)Implementation of Data Structures that can simulate Dynamic Arrays.
D)All of the above.
Answer: D
11.
What is the time complexity to insert an element to the front of a LinkedList(head pointer
given)?
A)O(n)
B)O(1)
C)O (logn)
D)None of the above
Answer: B
12.
What is the time complexity to insert an element to the rear of a LinkedList(head pointer
given)?
A)O(n)
B)O(1)
C)O(logn)
D)None of the above
Answer: A
13)A linked list node can be implemented using?
A)Structs
B)Class
C)Both A and B
D)None of the above
Answer: C
14.
Which type of linked list stores the address of the head node in the next pointer of the
last node?
A)Singly Linked List
B)Doubly Linked List
C)Hashed List
D)Circular Linked List
Answer: D
15.
Polynomial addition can be implemented using which of the following datastructure?
A)Linked List
B)Trees
C)Stacks
D)None of the above
Answer: A
Answer: B
20)Which of the following algorithm is the optimal way to find the middle element of the
linked list?
A)Find length, and then traverse to length / 2 th node.
B)Fast and slow pointer method
C)Find the distance of all nodes, and print middle nodes.
D)None of the above
Answer: B
21.
A linked list in which none of the nodes contains a NULL pointer is?
A)Singly Linked List
B)Doubly Linked List
C)Circular Linked List
D)None of the above
Answer: C
22
Which of the following statements are true?
A)Random access of elements at a linked list is not possible.
B)Arrays have better cache locality than linked list.
C)The size of linked list is dynamic and can be changed as needed.
D)All of the above
Answer: D
23.
What is the optimal complexity we can achieve when removing duplicates from an
unsorted linked list?
A)O(n)
B)O(n^2)
C)O(n * log n)
D)None of the above
Answer: A
24
What is the optimal complexity we can achieve when removing duplicates from an
sorted linked list?
A)O(n)
B)O(n ^ 2)
C)O(n * logn)
D)None of the above
Answer: A
25.
Which of the following sorting algorithms can be applied to linked lists?
A)Merge Sort
B)Insertion Sort
C)Quick Sort
D)All of the above
Answer: D
26
Which of the following is optimal to find an element at kth position at the linked list?
A)Singly Linked List
B)Doubly Linked List
C)Circular Linked List
D)Array implementation of linked list.
Answer: D
31.
What does the following code snippet do?
void solve(ListNode* node) {
node = node -> next;
}
A)Deletes the given node from the linked list
B)Deletes head of the list
C)Deletes last node of the list
D)None of the above
Answer: D
32.
What is the time complexity of adding 2 numbers as a linked list?
A)O(max(n, m)) // n and m are sizes of the list
B)O(n + m)
C)O(min(n, m))
D)None of the above
Answer: A
33.
Which of the following problems can be solved using 2 pointers on the linked list?
A)Detecting cycle in a linked list
B)Finding intersection of 2 linked lists
C)Finding middle element of a linked list
D)All of the above
Answer: D
34.
Which of the following is similar about singly and doubly linked list?
A)Both of them are not able to access the data at a random position in constant time.
B)Both of them can add a new node after a given node or at the beginning of the list
inO(1) time.
C)Both of them can delete the first node in O(1) time.
D)All of the above
Answer: D
35.
Rotating a linked list by some places clockwise will take a time complexity of?
A)O(1)
B)O(n)
C)O(n^2)
D)None of the above
Answer: B
36
Rotating a linked list by some places clockwise will take a space complexity of?
A)O(1)
B)O(n)
C)O(n^2)
D)None of the above
Answer: A
37.
The time complexity of enqueue operation of a queue implemented by a singly linked
list is?
A)O(1)
B)O(n)
C)O(logn)
D)None of the above
Answer: A
38.
The time complexity of dequeue operation of a queue implemented by a singly linked
list is?
A)O(1)
B)O(n)
C)O(logn)
D)None of the above
Answer: B
39
Which data structure is used in a compiler for managing information about variables and
their attributes?
A)Abstract Syntax Tree
B)Symbol Table
C)Semantic Stack
D)Parse Table
Answer: B
40.
Polynomial addition is implemented using which data structure?
A)Queue
B)Linked List
C)Trees
D)Stack
Answer: B
41
In a circular linked list insertion of a record requires the modification of?
A)1 pointer
B)2 pointer
C)3 pointer
D)4 pointer
Answer: B
42.
Consider the following code snippet:
struct node
{
int data;
struct node * next;
}
typedef struct node NODE;
NODE *ptr;
How can we create a new node?
A)ptr=(NODE*)malloc(sizeof(NODE));
B)ptr=(NODE*)malloc(NODE);
C)ptr=(NODE*)malloc(sizeof(NODE*));
D)ptr=(NODE)malloc(sizeof(NODE));
Answer: A
43.
How can we destroy a pointer in C++?
A)Delete keyword
B)free keyword
C)calloc
D)malloc
Answer: A
44.
Which of the following statements are true?
A)delete is a keyword.
B)free is a library function.
C)Both A and B
D)None of the above
Answer: C
45.
What is the space complexity for deleting a linked list?
A)O(1)
B)O(n)
C)O(n^2)
D)None of the above
Answer: A
46
What is the space complexity needed to store a linked list of n nodes?
A)O(1)
B)O(n)
C)O(n^2)
D)None of the above
Answer: B
47.
Which of the following linked list operation takes O(1) time?
A)Insert element at start of linked list.
B)Insert element at end of linked list.
C)Find length of linked list.
D)None of the above.
Answer: A
48.
What are the information stored by linked lists which are used to implement binary
trees?
A)Value of current node
B)Pointer to left child
C)Pointer to right child
D)All of the above
Answer: D
49.
Which of the following variations of linked lists can we use to search a sorted list in
better than amortized O(n) complexity?
A)Singly Linked Lists
B)Circular Linked Lists
C)Skip List
D)None of the above
Answer: C
50.
Which of the following sorting algorithms is preferred to sort a linked list?
A)Merge Sort
B)Quick Sort
C)Insertion Sort
D)None of the above
Answer: A