• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Quiz On Circular Linked List

Question 1

Find the functionality of the given code-

C++
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");
}
  • Print success if a particular element is not found

  • Print fail if a particular element is not found

  • Print success if a particular element is equal to 1

  • Print fail if the list is empty

Question 2

What is the time complexity of searching for an element in a circular linked list?

  • O(n)

  • O(nlogn)

  • O(1)

  • O(n2)

Question 3

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

  • public void insertHead(int data)
    {
    Node temp = new Node(data);
    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++;
    }
     

  • 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++;
    }

  • 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;
    }
    size++;
    }

  • 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++;
    }

Question 4

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

C++
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;
}
  • Return data from the end of the list

  • Returns the data and deletes the node at the end of the list

  • Returns the data from the beginning of the list

  • Returns the data and deletes the node from the beginning of the list

Question 5

Consider a small circular linked list. How to detect the presence of cycles in this list effectively?

  • Keep one node as head and traverse another temp node till the end to check if its ‘next points to head

  • 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

  • Cannot determine, you have to pre-define if the list contains cycles

  • Circular linked list itself represents a cycle. So no new cycles cannot be generated

Question 6

Which of the following application makes use of a circular linked list?

  • Undo Operation

  • Recursive function calls

  • Allocating CPU to resources

  • Implement Hash Tables

Question 7

In a circular linked list, How many nodes are containing NULL as the address?

  • Only one node

  • Only Two node

  • Every Node

  • No, any node

Question 8

What is the time complexity to insert a node at the beginning of the list?

  • O(LogN)

  • O(N)

  • O(1)

  • None

Question 9

Consider the below program, and identify which Operation is performed.

C++
int solve(struct Node* head)
{
    if (head == NULL)
        return 1;
    struct Node* ptr;
    ptr = head->next;
    while (ptr != NULL && ptr != head)
        ptr = ptr->next;
    return (ptr == head);
}
  • Checking for List is empty of not

  • Checking for the list is Circular or not

  • count the number of elements in the list

  • None

Question 10

Which of the following Statement is correct about Circular Linked List?

P1: Every Node has a successor.
P2: TIme complexity for deleting the first node is O(N).
P3: Last Node points to the NULL.
P4: Every Node contains the data and a next pointer to traverse the list.

  • Only P4

  • Only P1

  • P1 and P2

  • P1 and P4.

There are 10 questions to complete.

Last Updated :
Take a part in the ongoing discussion