Professional Documents
Culture Documents
Linked List MCQ
Linked List MCQ
Linked List MCQ
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) O(n2)
View Answer
advertisement
https://www.sanfoundry.com/data-structure-questions-answers-single-linked-lists/ 1/13
28/11/2023, 09:18 Linked List MCQ - Sanfoundry
4. Which of the following performs deletion of the last element in the list? Given below is the Node
class.
class Node
{
protected Node next;
protected Object ele;
Node(Object e,Node n)
{
ele = e;
next = n;
}
public void setNext(Node n)
{
next = n;
}
public void setEle(Object e)
{
ele = e;
}
public Node getNext()
{
return next;
}
public Object getEle()
{
return ele;
}
}
class SLL
{
Node head;
int size;
SLL()
{
size = 0;
}
}
a)
https://www.sanfoundry.com/data-structure-questions-answers-single-linked-lists/ 2/13
28/11/2023, 09:18 Linked List MCQ - Sanfoundry
b)
advertisement
https://www.sanfoundry.com/data-structure-questions-answers-single-linked-lists/ 3/13
28/11/2023, 09:18 Linked List MCQ - Sanfoundry
{
temp = cur;
cur = cur.getNext();
}
temp.setNext(null);
return cur;
}
c)
advertisement
d)
https://www.sanfoundry.com/data-structure-questions-answers-single-linked-lists/ 4/13
28/11/2023, 09:18 Linked List MCQ - Sanfoundry
Node temp;
cur = head;
while(cur.getNext() != null)
{
cur = cur.getNext();
temp = cur;
}
temp.setNext(null);
return cur;
}
View Answer
7. How would you delete a node in the singly linked list? The position to be deleted is given.
a)
https://www.sanfoundry.com/data-structure-questions-answers-single-linked-lists/ 5/13
28/11/2023, 09:18 Linked List MCQ - Sanfoundry
if(pos < 0)
pos = 0;
if(pos > size)
pos = size;
if( size == 0)
return;
if(pos == 0)
head = head.getNext();
else
{
Node temp = head;
for(int i=1; i<pos; i++)
{
temp = temp.getNext();
}
temp.setNext(temp.getNext().getNext());
}
size--;
}
b)
c)
if( size == 0)
return;
if(pos == 0)
head = head.getNext();
else
{
Node temp = head;
for(int i=1; i<pos; i++)
{
temp = temp.getNext().getNext();
}
temp.setNext(temp.getNext().getNext());
}
size--;
}
d)
View Answer
https://www.sanfoundry.com/data-structure-questions-answers-single-linked-lists/ 7/13
28/11/2023, 09:18 Linked List MCQ - Sanfoundry
9. Which of the following piece of code has the functionality of counting the number of elements in
the list?
a)
b)
c)
d)
https://www.sanfoundry.com/data-structure-questions-answers-single-linked-lists/ 8/13
28/11/2023, 09:18 Linked List MCQ - Sanfoundry
{
size++;
cur = cur.getNext().getNext();
}
return size;
}
View Answer
b)
c)
d)
https://www.sanfoundry.com/data-structure-questions-answers-single-linked-lists/ 9/13
28/11/2023, 09:18 Linked List MCQ - Sanfoundry
View Answer
To practice all areas of Data Structure, here is complete set of 1000+ Multiple Choice Questions and
Answers.
« Prev - Data Structure Questions and Answers » Next - Data Structure Questions and Answers –
– Singly Linked List Operations – 3 Doubly Linked List
https://www.sanfoundry.com/data-structure-questions-answers-single-linked-lists/ 10/13
28/11/2023, 09:18 Linked List MCQ - Sanfoundry
Related Posts:
advertisement
Recommended Articles:
1. Data Structure Questions and Answers – Singly Linked List Operations – 1
2. Data Structure Questions and Answers – Singly Linked List Operations – 2
3. Data Structure Questions and Answers – Skip List
4. Data Structure Questions and Answers – Xor Linked List
5. Data Structure Questions and Answers – Doubly Linked List
6. Data Structure Questions and Answers – Circular Linked List
7. Data Structure Questions and Answers – Singly Linked List Operations – 3
8. Data Structure Questions and Answers – Stack using Linked List
9. Data Structure Questions and Answers – Queue using Linked List
https://www.sanfoundry.com/data-structure-questions-answers-single-linked-lists/ 11/13
28/11/2023, 09:18 Linked List MCQ - Sanfoundry
10. Data Structure Questions and Answers – Search an Element in a Linked List using Recursion
advertisement
Additional Resources:
Linked List Programs in Python
Data Structure MCQ Questions
Linked List Programs in C
Data Structures in C
Data Structures in C++
Popular Pages:
Data Structures in Java
Data Science MCQ Questions
Design & Analysis of Algorithms MCQ Questions
HTML MCQ Questions
Visual Basic MCQ Questions
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is
Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on
development of Linux Kernel, SAN Technologies, Advanced C, Data
Structures & Alogrithms. Stay connected with him at LinkedIn.
https://www.sanfoundry.com/data-structure-questions-answers-single-linked-lists/ 13/13