Linked List MCQ
LinkedList is a linear data structure like arrays. In a Linked List each element is actually a separate object linked to the next element using a reference stored in a pointer.
A Linked List is composed of nodes, which are connected to the next node, using memory references or addresses. A Linked List node usually contains 2 properties stored in it. They are:
- The value to be stored in the current node.
- The reference or address of the next node, or NULL if it is the last node.
Linked Lists are of 2 types usually:
- Singly Linked Lists: They are the standard linked list, where the value of the current node and the reference of the next node is only stored. The reference stored in the last node of the list is NULL.
- Doubly Linked Lists: This type of linked list stores all the information of the Singly Linked Lists, along with the reference or memory address of the previous node too if it exists, else NULL.
Useful Resources
Linked List MCQs
Which of the following can be done with LinkedList?
What is the space complexity needed to store a linked list of n nodes?
What is the time complexity of a program to reverse a linked list?
What is the time complexity of adding 2 numbers as a linked list?
What is the time complexity to insert an element to the front of a LinkedList(head pointer given)?
Learn via our Video Courses
What is the time complexity to insert an element to the rear of a LinkedList(head pointer given)?
What will be the output of the following code snippet for 1->2->3->4->5?
void solve (ListNode* head) {
while(head != NULL) {
cout << head -> data << " ";
head = head -> next;
}
}
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);
}
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;
}
Which data structure is used in a compiler for managing information about variables and their attributes?
Which of the following algorithm is the optimal way to find the middle element of the linked list?
Which of the following algorithms is not feasible to implement in a linked list?
Which of the following are applications of linked lists?
What is the space complexity for deleting a linked list?
Which of the following information is stored in a doubly-linked list’s nodes?
Which of the following is optimal to find an element at kth position at the linked list?
Which of the following is similar about singly and doubly linked list?
Which of the following linked list operation takes O(1) time?
Which of the following problems can be solved using 2 pointers on linked list?
Which of the following sorting algorithms can be applied to linked lists?
Which of the following sorting algorithms is preferred to sort a linked list?
Which of the following statements are true?
Which of the following statements are true?
Which of the following variations of linked lists can we use to search a sorted list in better than amortized O(n) complexity?
Which type of linked list stores the address of the head node in the next pointer of the last node?
Rotating a linked list by some places clockwise will take a time complexity of?
A linked list node can be implemented using?
Concatenation of 2 linked list will take a time complexity of?
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?
How can we destroy a pointer in C++?
In a circular linked list insertion of a record requires the modification of?
In the worst case, the number of comparisons needed to search a singly linked list of length n for a given element will be?
In which type of linked lists traversals can be performed in both directions?
Insertion of an element at the ends of a linked list requires the modification of how many pointers?
Insertion of an element at the middle of a linked list requires the modification of how many pointers?
Polynomial addition can be implemented using which of the following datastructure?
Polynomial addition is implemented using which data structure?
Rotating a linked list by some places clockwise will take a space complexity of?
A linked list in which none of the nodes contains a NULL pointer is?
The time complexity of dequeue operation of a queue implemented by a singly linked list is?
The time complexity of enqueue operation of a queue implemented by a singly linked list is?
The type of pointer used to point to the address of the next element in a linked list?
What are the information stored by linked lists which are used to implement binary trees?
What does the following code snippet do?
int solve (ListNode* list) {
ListNode* fast = list;
ListNode* slow = list;
while(fast -> next != NULL && fast -> next -> next != NULL) {
fast = fast -> next -> next;
slow = slow -> next;
}
return slow -> data;
}
What does the following code snippet do?
ListNode* solve(ListNode* head) {
ListNode* prev = NULL;
if(head == NULL) {
return head;
}
if(head -> next == NULL) {
return head;
}
ListNode* curr = head -> next;
while(head != NULL) {
head -> next = prev;
prev = head;
head = curr;
if(curr != NULL) {
curr = curr -> next;
}
}
return prev;
}
What does the following code snippet do?
void solve(ListNode* node) {
node = node -> next;
}
What does the following code snippet do?
ListNode* solve(ListNode* head, int x) {
ListNode* front = head;
int count = 1;
while(front != NULL) {
cout << front -> data << " " << head -> data << endl;
if(count <= x) {
front = front -> next;
}
else {
head = head -> next;
front = front -> next;
}
count++;
}
return head;
}
What is the optimal complexity we can achieve when removing duplicates from an sorted linked list?
What is the optimal complexity we can achieve when removing duplicates from an unsorted linked list?
What is the optimal time complexity to count the number of nodes in a linked list?