Data Structure MCQ - Linked List

This section focuses on the "Linked List" of the Data Structure. These Multiple Choice Questions (mcq) should be practiced to improve the Data Structure skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

1. What does the following function do for a given Linked List with first node as head?

 
void fun1(struct node* head)
{
if(head == NULL)
return;
fun1(head->next);
printf("%d ", head->data);
}

A. Prints all nodes of linked lists
B. Prints all nodes of linked list in reverse order
C. Prints alternate nodes of Linked List
D. Prints alternate nodes in reverse order

View Answer


2. A linear collection of data elements where the linear node is given by means of pointer is called?

A. linked list
B. node list
C. primitive list
D. None of these

View Answer


3. What is the time complexity to count the number of elements in the linked list?

A. O(1)
B. O(n)
C. O(logn)
D. None of the mentioned

View Answer


4. What would be the asymptotic time complexity to add a node at the end of singly linked list, if the pointer is initially pointing to the head of the list?

A. O(1)
B. O(n)
C. θ (n)
D. θ (1)

View Answer


5. What is the output of following function for start pointing to first node of following linked list? 1->2->3->4->5->6

 
void fun(struct node* start)
{
if(start == NULL)
return;
printf("%d ", start->data);
if(start->next != NULL )
fun(start->next->next);
printf("%d ", start->data);
}

A. 1 4 6 6 4 1
B. 1 3 5 1 3 5
C. 1 2 3 5
D. 1 3 5 5 3 1

View Answer


6. What is the functionality of the following piece of code?

 
public int function(int data)
{
Node temp = head;
int var = 0;
while(temp != null)
{
if(temp.getData() == data)
{
return var;
}
var = var+1;
temp = temp.getNext();
}
return Integer.MIN_VALUE;
}

A. Find and delete a given element in the list
B. Find and return the given element in the list
C. Find and return the position of the given element in the list
D. Find and insert a new element in the list

View Answer


7. Linked lists are not suitable to for the implementation of?

A. Insertion sort
B. Radix sort
C. Polynomial manipulation
D. Binary search

View Answer


8. In the worst case, the number of comparisons needed to search a singly linked list of length n for a given element is

A. log 2 n
B. n/2
C. log 2 n – 1
D. n

View Answer


9. Which of these is an application of linked lists?

A. To implement file systems
B. For separate chaining in hash-tables
C. To implement non-binary trees
D. All of the mentioned

View Answer


10. In circular linked list, insertion of node requires modification of?

A. One pointer
B. Two pointer
C. Three pointer
D. None

View Answer


11. Consider an implementation of unsorted singly linked list. Suppose it has its representation with a head pointer only.
Given the representation, which of the following operation can be implemented in O(1) time?

i) Insertion at the front of the linked list
ii) Insertion at the end of the linked list
iii) Deletion of the front node of the linked list
iv) Deletion of the last node of the linked list

A. I and II
B. I and III
C. I, II and III
D. I, II and IV

View Answer


12. In linked list each node contain minimum of two fields. One field is data field to store the data second field is?

A. Pointer to character
B. Pointer to integer
C. Pointer to node
D. Node

View Answer


13. What would be the asymptotic time complexity to find an element in the linked list?

A. O(1)
B. O(n)
C. O(n2)
D. None of the mentioned

View Answer


14. The concatenation of two list can performed in O(1) time. Which of the following variation of linked list can be used?

A. Singly linked list
B. Doubly linked list
C. Circular doubly linked list
D. Array implementation of list

View Answer


15. Consider the following definition in c programming language.Which of the following c code is used to create new node?

 
struct node
{
int data;
struct node * next;
}
typedef struct node NODE;
NODE *ptr;

A. ptr = (NODE*)malloc(sizeof(NODE));
B. ptr = (NODE*)malloc(NODE);
C. ptr = (NODE*)malloc(sizeof(NODE*));
D. ptr = (NODE)malloc(sizeof(NODE));

View Answer


16. What kind of linked list is best to answer question like "What is the item at position n"?

A. Singly linked list
B. Doubly linked list
C. Circular linked list
D. Array implementation of linked list

View Answer


17. Linked lists are not suitable to for the implementation of?

A. Insertion sort
B. Radix sort
C. Polynomial manipulation
D. Binary search

View Answer


18. Linked list is considered as an example of ___________ type of memory allocation.

A. Dynamic
B. Static
C. Compile time
D. None of the mentioned

View Answer


19. In Linked List implementation, a node carries information regarding

A. Data
B. Link
C. Data and Link
D. None of the mentioned

View Answer


20. Linked list data structure offers considerable saving in

A. Computational Time
B. Space Utilization
C. Space Utilization and Computational Time
D. None of the mentioned

View Answer


21. Which of the following points is/are true about Linked List data structure when it is compared with array

A. Arrays have better cache locality that can make them better in terms of performance
B. It is easy to insert and delete elements in Linked List
C. Random access is not allowed in a typical implementation of Linked Lists
D. All of the mentioned

View Answer


22. Which of the following sorting algorithms can be used to sort a random linked list with minimum time complexity?

A. Insertion Sort
B. Quick Sort
C. Heap Sort
D. Merge Sort

View Answer


23. Given pointer to a node X in a singly linked list. Only one pointer is given, pointer to head node is not given, can we delete the node X from given linked list?

A. Possible if X is not last node
B. Possible if size of linked list is even
C. Possible if size of linked list is odd
D. Possible if X is not first node

View Answer


24. The following function reverse() is supposed to reverse a singly linked list. There is one line missing at the end of the function.What should be added in place of "/*ADD A STATEMENT HERE*/", so that the function correctly reverses a linked list.

 
struct node
{
int data;
struct node* next;
};
static void reverse(struct node** head_ref)
{
struct node* prev = NULL;
struct node* current = *head_ref;
struct node* next;
while (current != NULL)
{
next = current->next;
current->next = prev;
current = next;
}
/*ADD A STATEMENT HERE*/
}

A. *head_ref = prev;
B. *head_ref = current;
C. *head_ref = next;
D. *head_ref = NULL;

View Answer


25. he following C function takes a single-linked list of integers as a parameter and rearranges the elements of the list.
The function is called with the list containing the integers 1, 2, 3, 4, 5, 6, 7 in the given order. What will be the contents of the list after the function completes execution?

 
struct node
{
int value;
struct node *next;
};
void rearrange(struct node *list)
{
struct node *p, * q;
int temp;
if ((!list) || !list->next)
return;
p = list;
q = list->next;
while(q)
{
temp = p->value;
p->value = q->value;
q->value = temp;
p = q->next;
q = p?p->next:0;
}
}

A. 1, 2, 3, 4, 5, 6, 7
B. 2, 1, 4, 3, 6, 5, 7
C. 1, 3, 2, 5, 4, 7, 6
D. 2, 3, 4, 5, 6, 7, 1

View Answer






Also Check :


Discussion



* You must be logged in to add comment.