MCQS Linked List
MCQS Linked List
Prepared by:
Mehak(23837)
SEEE-CSE
1. Consider an implementation of unsorted doubly linked list.
Suppose it has its representation with a head pointer and tail
pointer. Given the representation, which of the following
operation can be implemented in O(1) time?
a) I and II
b) I and III Solution: d)
c) I,II and III
d) I,II,III and IV
2. Which of the following operations is performed more
efficiently by doubly linked list than by singly linked list?
Solution: (a)
3. Linked lists are best suited …………………………
Solution: (b)
4. What does the following function do for a given Linked List
with first node as head?
Solution: (B)
A. log 2 n
B. n/2
C. log 2 n – 1
D. n
Solution: (D)
the element to be searched has to be compared with all
elements of linked list.
6. What are the time complexities of finding 8th element
from beginning and 8th element from end in a singly linked
list? Let n be the number of nodes in linked list, you may
assume that n > 8.
A. O(1) and O(n)
B. O(1) and O(1)
C. O(n) and O(1)
D. O(n) and O(n)
Solution: (a)
Finding 8th element from beginning requires 8 nodes to be traversed which takes
constant time. Finding 8th from end requires the complete list to be traversed.
7. Is it possible to create a doubly linked list using only one
pointer with every node?
A. Not Possible
Yes, possible by storing XOR of addresses of previous and next
B.
nodes.
C. Yes, possible by storing XOR of current node and next node
D. Yes, possible by storing XOR of current node and previous node
Solution: (B)
An ordinary Doubly Linked List requires space for two address fields to store the
addresses of previous and next nodes. A memory efficient version of Doubly Linked
List can be created using only one space for address field with every node. This
memory efficient Doubly Linked List is called XOR Linked List or Memory Efficient as
the list uses bitwise XOR operation to save space for one address. In the XOR linked
list, instead of storing actual memory addresses, every node stores the XOR of
addresses of previous and next nodes.
8. 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?
Possible if X is not last node. Use following two steps (a) Copy
A.
the INFO of LINK of X to X. (b) Delete LINK of X.
B. Possible if size of linked list is even.
C. Possible if size of linked list is odd
Possible if X is not first node. Use following two steps (a) Copy
D.
the INFO of LINK of X to X. (b) Delete LINK of X.
Solution: (A)
Following are simple steps:
struct node *temp = X->LINK;
X->INFO = temp->INFO;
X->LINK = temp->LINK;
free(temp);
9. You are given pointers to first and last nodes of a singly
linked list, which of the following operations are dependent
on the length of the linked list?
Solution: (C)
10. Consider the following function to traverse a linked list.
void traverse(struct Node *head)
{
while (head->next != NULL) Solution: (C)
{
printf("%d ", head->data);
head = head->next;
}
}
Which of the following is FALSE about above function?
A. The function may crash when the linked list is empty
The function doesn't print the last node when the linked list is
B.
not empty
The function is implemented incorrectly because it changes
C.
head
D. None of the above
11. The concatenation of two lists is to be performed in O(1)
time. Which of the following implementations of a list should
be used?
Solution: (C)
Singly linked list cannot be answer because we cannot find last element of a singly
linked list in O(1) time. Doubly linked list cannot also not be answer because of the
same reason as singly linked list.
12. In a doubly linked list, the number of pointers affected for
an insertion operation will be:
A. 4
B. 0
C. 1
D. None of these
Solution: (D)
This depends on whether we are inserting the new node in the middle of the list
(surrounded by two nodes), or at the head or tail of the list. Insertion at the middle
node will affect 4 pointers whereas at the head or tail will affect only 2 pointers. So,
option (D) is correct.
13. Consider a single linked list where F and L are pointers to
the first and last elements respectively of the linked list. The
time for performing which of the given operations depends
on the length of the linked list?
Solution: (C)
14. The time required to search an element in a linked list of
length n is:
A. O (log n)
B. O (n)
C. O (1) Solution: (B)
D. O(n2)
15. Which of the following operations is performed more
efficiently by doubly linked list than by linear linked list?
Solution: (A)
16. Which of the following application makes use of a circular
linked list?
Solution: (C)
Generally, round robin fashion is employed to allocate CPU time to
resources which makes use of the circular linked list data structure.
17. Consider a small circular linked list. How to detect the
presence of cycles in this list effectively?
a) Keep one node as head and traverse another temp node till
the end to check if its ‘next points to head
b) Have fast and slow pointers with the fast pointer advancing
two nodes at a time and slow pointer advancing by one node
at a time
c) Cannot determine, you have to pre-define if the list
contains cycles
d) None of the mentioned
Solution: (B)
Advance the pointers as mentioned in ‘b’, check to see if at any given instant of time
if the fast pointer points to slow pointer or if the fast pointer’s ‘next’ points to the
slow pointer. Note that this trick is useful only if the list is small.
18. Which of the following is false about a circular linked list?
Solution: (B)
Time complexity of inserting a new node at the head of the list is O(n)
because you have to traverse through the list to find the tail node.
19. What is a memory efficient double linked list?
a) Each node has only one pointer to traverse the list back
and forth
b) The list has breakpoints for faster traversal
c) An auxiliary singly linked list acts as a helper list to traverse
through the doubly linked list
d) None of the mentioned
Solution: (a)
Memory efficient doubly linked list has been proposed recently which has only one
pointer to traverse the list back and forth. The implementation is based on pointer
difference.
20. How do you calculate the pointer difference in a memory
efficient double linked list?
Solution: (B)