0% found this document useful (0 votes)
137 views21 pages

MCQS Linked List

The document contains 20 multiple choice questions about linked lists. It covers topics such as time complexities of various operations on different types of linked lists like singly linked lists, doubly linked lists, and circular linked lists. It also discusses memory efficient implementations of doubly linked lists that use only one pointer per node. The key aspects summarized are: 1) The document contains 20 MCQ questions about concepts related to linked lists like time complexities, operations on different types of linked lists, and memory efficient implementations. 2) It covers topics such as time complexities of operations on singly linked lists, doubly linked lists, and circular linked lists. 3) It also discusses the concept of a memory efficient doubly linked list that

Uploaded by

Ali Obaid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
137 views21 pages

MCQS Linked List

The document contains 20 multiple choice questions about linked lists. It covers topics such as time complexities of various operations on different types of linked lists like singly linked lists, doubly linked lists, and circular linked lists. It also discusses memory efficient implementations of doubly linked lists that use only one pointer per node. The key aspects summarized are: 1) The document contains 20 MCQ questions about concepts related to linked lists like time complexities, operations on different types of linked lists, and memory efficient implementations. 2) It covers topics such as time complexities of operations on singly linked lists, doubly linked lists, and circular linked lists. 3) It also discusses the concept of a memory efficient doubly linked list that

Uploaded by

Ali Obaid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 21

MCQS on 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?

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 end node of the linked list

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?

a) Deleting a node whose location in given


b) Searching of an unsorted list for a given item
c) Inverting a node after the node with given location
d) Traversing a list to process each node

Solution: (a)
3. Linked lists are best suited …………………………

A. for relatively permanent collections of data.


B. for the size of the structure and the data in the structure
are constantly changing.
C. data structure
D. for none of above situation

Solution: (b)
4. What does the following function do for a given Linked List
with first node as head?

Solution: (B)

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
5. 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

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?

A. Delete the first element


B. Insert a new element as a first element
C. Delete the last element of the list
D. Add a new element at the end of the 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?

A. singly linked list


B. doubly linked list
C. circular doubly linked list
D. array implementation of lists

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?

A. Delete the first element of the list


B. Interchange the first two elements of the list
C. Delete the last element of the list
D. Add an element at the end of the lis

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?

A. Deleting a node whose location is given


B. Searching an unsorted list for a given item
C. Inserting a node after the node with a given location
D. Traversing the list to process each node

Solution: (A)
16. Which of the following application makes use of a circular
linked list?

a) Undo operation in a text editor


b) Recursive function calls
c) Allocating CPU to resources
d) All of the mentioned

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?

a) Every node has a successor


b) Time complexity of inserting a new node at the head of the
list is O(1)
c) Time complexity for deleting the last node is O(n)
d) None of the mentioned

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?

a) head XOR tail


b) pointer to previous node XOR pointer to next node
c) pointer to previous node – pointer to next node
d) pointer to next node – pointer to previous node

Solution: (B)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy