0% found this document useful (0 votes)
235 views10 pages

Circular Linked Lists Questions and Answers

The document contains 9 multiple choice questions about circular linked lists. Some key points: - A circular linked list differs from a normal linked list in that the 'next' pointer of the last node points to the head node, making it cyclic. - To count the number of elements, one traverses the list until reaching the starting node again. - Searching for an element has time complexity O(n) as each element may need to be checked once.

Uploaded by

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

Circular Linked Lists Questions and Answers

The document contains 9 multiple choice questions about circular linked lists. Some key points: - A circular linked list differs from a normal linked list in that the 'next' pointer of the last node points to the head node, making it cyclic. - To count the number of elements, one traverses the list until reaching the starting node again. - Searching for an element has time complexity O(n) as each element may need to be checked once.

Uploaded by

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

28/11/2023, 09:25 Circular Linked Lists Questions and Answers - Sanfoundry

-25%

Data Structure Questions and Answers –


Circular Linked List
This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Circular Linked
List”.

1. What differentiates a circular linked list from a normal linked list?


a) You cannot have the ‘next’ pointer point to null in a circular linked list
b) It is faster to traverse the circular linked list
c) You may or may not have the ‘next’ pointer point to null in a circular linked list
d) Head node is known in circular linked list
View Answer

2. How do you count the number of elements in the circular linked list?
a)

public int length(Node head)


{
int length = 0;
if( head == null)
return 0;
Node temp = head.getNext();
while(temp != head)
{
temp = temp.getNext();
length++;
}
return length;
}

b)

advertisement

https://www.sanfoundry.com/data-structure-questions-answers-circular-linked-lists/ 1/10
28/11/2023, 09:25 Circular Linked Lists Questions and Answers - Sanfoundry

public int length(Node head)


{
int length = 0;
if( head == null)
return 0;
Node temp = head.getNext();
while(temp != null)
{
temp = temp.getNext();
length++;
}
return length;
}

c)

Note: Join free Sanfoundry classes at Telegram or Youtube

public int length(Node head)


{
int length = 0;
if( head == null)
return 0;
Node temp = head.getNext();
while(temp != head && temp != null)
{
temp = head.getNext();
length++;
}
return length;
}

d)

advertisement

https://www.sanfoundry.com/data-structure-questions-answers-circular-linked-lists/ 2/10
28/11/2023, 09:25 Circular Linked Lists Questions and Answers - Sanfoundry

public int length(Node head)


{
int length = 0;
if( head == null)
return 0;
Node temp = head.getNext();
while(temp != head && temp == null)
{
temp = head.getNext();
length++;
}
return length;
}

View Answer

3. What is the functionality of the following piece of code? Select the most appropriate.

advertisement

https://www.sanfoundry.com/data-structure-questions-answers-circular-linked-lists/ 3/10
28/11/2023, 09:25 Circular Linked Lists Questions and Answers - Sanfoundry

public void function(int data)


{
int flag = 0;
if( head != null)
{
Node temp = head.getNext();
while((temp != head) && (!(temp.getItem() == data)))
{
temp = temp.getNext();
flag = 1;
break;
}
}
if(flag)
System.out.println("success");
else
System.out.println("fail");
}

a) Print success if a particular element is not found


b) Print fail if a particular element is not found
c) Print success if a particular element is equal to 1
d) Print fail if the list is empty
View Answer

4. What is the time complexity of searching for an element in a circular linked list?
a) O(n)
b) O(nlogn)
c) O(1)
d) O(n2)
View Answer

5. 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) Implement Hash Tables
View Answer

6. Choose the code snippet which inserts a node to the head of the list?
a)

public void insertHead(int data)


{
Node temp = new Node(data);

https://www.sanfoundry.com/data-structure-questions-answers-circular-linked-lists/ 4/10
28/11/2023, 09:25 Circular Linked Lists Questions and Answers - Sanfoundry

Node cur = head;


while(cur.getNext() != head)
cur = cur.getNext()
if(head == null)
{
head = temp;
head.setNext(head);
}
else
{
temp.setNext(head);
head = temp;
cur.setNext(temp);
}
size++;
}

b)

public void insertHead(int data)


{
Node temp = new Node(data);
while(cur != head)
cur = cur.getNext()
if(head == null)
{
head = temp;
head.setNext(head);
}
else
{
temp.setNext(head.getNext());
cur.setNext(temp);
}
size++;
}

c)

public void insertHead(int data)


{
Node temp = new Node(data);
if(head == null)
{
head = temp;
head.setNext(head);
}
else
{
temp.setNext(head.getNext());
head = temp;
}
https://www.sanfoundry.com/data-structure-questions-answers-circular-linked-lists/ 5/10
28/11/2023, 09:25 Circular Linked Lists Questions and Answers - Sanfoundry

size++;
}

d)

public void insertHead(int data)


{
Node temp = new Node(data);
if(head == null)
{
head = temp;
head.setNext(head.getNext());
}
else
{
temp.setNext(head.getNext());
head = temp;
}
size++;
}

View Answer

7. What is the functionality of the following code? Choose the most appropriate answer.

public int function()


{
if(head == null)
return Integer.MIN_VALUE;
int var;
Node temp = head;
while(temp.getNext() != head)
temp = temp.getNext();
if(temp == head)
{
var = head.getItem();
head = null;
return var;
}
temp.setNext(head.getNext());
var = head.getItem();
head = head.getNext();
return var;
}

a) Return data from the end of the list


b) Returns the data and deletes the node at the end of the list
c) Returns the data from the beginning of the list

https://www.sanfoundry.com/data-structure-questions-answers-circular-linked-lists/ 6/10
28/11/2023, 09:25 Circular Linked Lists Questions and Answers - Sanfoundry

d) Returns the data and deletes the node from the beginning of the list
View Answer

8. What is the functionality of the following code? Choose the most appropriate answer.

public int function()


{
if(head == null)
return Integer.MIN_VALUE;
int var;
Node temp = head;
Node cur;
while(temp.getNext() != head)
{
cur = temp;
temp = temp.getNext();
}
if(temp == head)
{
var = head.getItem();
head = null;
return var;
}
var = temp.getItem();
cur.setNext(head);
return var;
}

a) Return data from the end of the list


b) Returns the data and deletes the node at the end of the list
c) Returns the data from the beginning of the list
d) Returns the data and deletes the node from the beginning of the list
View Answer

9. 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) We can traverse the whole circular linked list by starting from any point
View Answer

10. 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
https://www.sanfoundry.com/data-structure-questions-answers-circular-linked-lists/ 7/10
28/11/2023, 09:25 Circular Linked Lists Questions and Answers - Sanfoundry

d) Circular linked list itself represents a cycle. So no new cycles cannot be generated
View Answer

Sanfoundry Global Education & Learning Series – Data Structure.

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 –
– Doubly Linked List Stack using Array

Related Posts:

Apply for Information Technology Internship


Apply for Data Structure Internship
Practice Computer Science MCQs
Check Programming Books
Apply for Computer Science Internship

Data Structure MCQ, DS MCQ - Abstract Datatype

advertisement

Recommended Articles:
1. Data Structure Questions and Answers – Doubly Linked List
2. Data Structure Multiple Choice Questions – Linked List
https://www.sanfoundry.com/data-structure-questions-answers-circular-linked-lists/ 8/10
28/11/2023, 09:25 Circular Linked Lists Questions and Answers - Sanfoundry

3. Data Structure Questions and Answers – Singly Linked List Operations – 3


4. Data Structure Questions and Answers – Stack using Linked List
5. C Program to Convert Singly Linked List to Circular List
6. Data Structure Questions and Answers – Singly Linked List Operations – 1
7. Data Structure Questions and Answers – Length of a Linked List using Recursion
8. C program to Swap Two Nodes in a Circular Linked List
9. Data Structure Questions and Answers – Double Ended Queue (Dequeue)
10. C Program to Implement Doubly Linked List using Singly Linked List

advertisement

Additional Resources:
Linked List Programs in C
Linked List Programs in Python
Data Structure MCQ Questions
Data Structures in C
Data Structures in Java

Popular Pages:
Data Structures in C++
C Programs on Recursion
C Tutorial

https://www.sanfoundry.com/data-structure-questions-answers-circular-linked-lists/ 9/10
28/11/2023, 09:25 Circular Linked Lists Questions and Answers - Sanfoundry

Python Programming Examples


JavaScript MCQ Questions

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to


get free Certificate of Merit. Join our social networks below and stay updated with latest contests,
videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest

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.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram


SanfoundryClasses.

About | Certifications | Internships | Jobs | Privacy Policy | Terms | Copyright | Contact

     

© 2011-2023 Sanfoundry. All Rights Reserved.

https://www.sanfoundry.com/data-structure-questions-answers-circular-linked-lists/ 10/10

You might also like