adplus-dvertising

Welcome to the Linked Lists MCQs Page

Dive deep into the fascinating world of Linked Lists with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Linked Lists, a crucial aspect of Data Structures and Algorithms. In this section, you will encounter a diverse range of MCQs that cover various aspects of Linked Lists, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within Data Structures and Algorithms.

frame-decoration

Check out the MCQs below to embark on an enriching journey through Linked Lists. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of Data Structures and Algorithms.

Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Linked Lists. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Linked Lists MCQs | Page 13 of 17

Q121.
What is the space complexity for deleting a linked list?
Discuss
Answer: (a).O(1)
Q122.
How would you delete a node in the singly linked list? The position to be deleted is given.
a)

public void delete(int pos)
{
 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)

public void delete(int pos)
{
 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());
 }
     size--;
}

c)

public void delete(int pos)
{
        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().getNext();
            }
     temp.setNext(temp.getNext().getNext());
 }
     size--;
}

d)

public void delete(int pos)
{
        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=0; i<pos; i++)
     {
  temp = temp.getNext();
     }
     temp.setNext(temp.getNext().getNext());
 }
 size--;
}

a.

a

b.

b

c.

c

d.

d

Discuss
Answer: (a).a
Discuss
Answer: (d).All of the mentioned
Q124.
Which of the following piece of code has the functionality of counting the number of elements in the list?
a)

public int length(Node head)
{
 int size = 0;
 Node cur = head;
 while(cur!=null)
 {
     size++;
     cur = cur.getNext();
 }
 return size;
}

b)

public int length(Node head)
{
        int size = 0;
 Node cur = head;
 while(cur!=null)
 {
     cur = cur.getNext();
     size++;
 }
 return size;
}

c)

public int length(Node head)
{
 int size = 0;
 Node cur = head;
 while(cur!=null)
 {
     size++;
     cur = cur.getNext();
 }
}

d)

public int length(Node head)
{
 int size = 0;
 Node cur = head;
 while(cur!=null)
 {
     size++;
     cur = cur.getNext().getNext();
 }
 return size;
}

a.

a

b.

b

c.

c

d.

d

Discuss
Answer: (a).a
Q125.
How do you insert an element at the beginning of the list?
a)

public void insertBegin(Node node)
{
 node.setNext(head);
 head = node;
 size++;
}

b)

public void insertBegin(Node node)
{
 head = node;
 node.setNext(head);
 size++;
}

c)

public void insertBegin(Node node)
{
 Node temp = head.getNext()
 node.setNext(temp);
 head = node;
 size++;
}

d) None of the mentioned

a.

a

b.

b

c.

c

d.

d

Discuss
Answer: (a).a
Q126.
What is the functionality of the following piece of code?
public int function(int data)
{
 Node temp = head;
 int var = 0;
 while(temp != null)
 {
  if(temp.getData() == data)
  {
   return var;
  }
  var = var+1;
  temp = temp.getNext();
 }
 return Integer.MIN_VALUE;
}
Discuss
Answer: (c).Find and return the position of the given element in the list
Discuss
Answer: (c).You may or may not have the ‘next’ pointer point to null in a circular linked list
Q128.
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)

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)

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) None of the mentioned

a.

a

b.

b

c.

c

d.

d

Discuss
Answer: (a).a
Q129.
What is the functionality of the following piece of code? Select the most appropriate
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");
}
Discuss
Answer: (b).Print fail if a particular element is not found
Q130.
What is the time complexity of searching for an element in a circular linked list?
Discuss
Answer: (a).O(n)

Suggested Topics

Are you eager to expand your knowledge beyond Data Structures and Algorithms? We've curated a selection of related categories that you might find intriguing.

Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!