Interview Questions on Linked Lists in Data Structures Set 4

Linked Lists interview questions for beginners. Answers to all of them have been provided. This is subjective type short answers question and answer set no. 4 in this series.

Last Reviewed and Updated on February 7, 2020
Posted by Parveen(Hoven),
Aptitude Trainer and Software Developer

Interview and Exam Questions and Answers

This set contains a list of commonly asked questions. They are short interview questions aimed at freshers interview, campus placement drives, and also for job interviews. You can use these to have a quick grasp and brush-up of your fundamentals. These questions can be viewed on a mobile phone also because this website is built on responsive web design.

Write an algorithm for deleting a node from the beginning of the singly-linked list.

The algorithm to delete a node from the beginning of the list is as follows:

  1. Mark the first node in the list as current.
  2. Make START POINT to the next node in its sequence.
  3. Release he memory for the node marked as current.

Write an algorithm for inserting a node in a circular linked list when the list is empty.

If the list is empty, the following algorithm is used to insert a node in the linked list.

  1. Allocate a memory fo new node.

  2. Assign a value to the data field of the new node.
  3. Make LAST point to the new node.
  4. Make the next field of new node point to new node

Write an algorithm to delete a node from the end of the circular -linked list.

The algorithm to delete a node from the end of the circular -linked list:

  1. Make current point to LAST.
  2. mark the predecessor of LAST as previous. To locate the predecessor of LAST execute the following steps:
    1. Make previous point to the successor of LAST.
    2. Repeat step c until the successor of previous becomes LAST.
    3. Make previous point to the next node in sequence.
  3. Make the next field of previous point to successor of LAST.
  4. Mark previous as LAST.
  5. Release the memory of node marked as current.

What is the difference between a singly linked list and circular linked list?

In a singly linked list, the last node points to Null. However, in a circular linked list, the last node point to the first node of the the list, forming the circular structure.

What are different types of linked list?

Singly-linked list, Doubly-linked list and Circular linked list

Write algorithm for inserting node at end of Singly-Linked list, if list is not empty .

To insert a node at the and of the linked list algorithm is:

  1. Allocate memory for the new node.
  2. Assign value to the data field of the new node.
  3. If START is NULL,then:
    1. Make START point to the new node.
    2. Go to step 6.
  4. Locate the last node in the list, and mark it as currentNode.To locate the last node in the list,execute the following steps:
    1. Mark the first node as currentNode.
    2. Repeat step c until the successor of currentNode becomes NULL.
    3. Make currentNode point to the next node in sequence.
  5. Make the next field of currentNode point to the new node.
  6. Make the next field of the new node point to NULL.

How singly-linked list is represented in a program?

A linked list is represented in a program by defining two classes:

a) Node class: A node is the basic building block in a linked list.The Node class represents a node in a linked list

b) List class: This class consists of a set of operations implemented on a linked list. These operations are insertion, deletion, search, and traversal.

Write algorithm for inserting node at the beginning of Singly-Linked list, if list is not empty .

To insert a node at the beginning of the linked list algorithm is:

  1. Allocate memory for the new node.
  2. Assign value to the data field of the new node.
  3. Make the next field of the new node point to the first node in the list.
  4. Make START point to the new node.

Write an algorithm to delete a node from the beginning of a circular list.

The algorithm to delete a node from beginning of the list:

  1. If the node to be deleted is the only node in the list:
    1. Mark LAST as NULL
    2. Exit
  2. Make current point to the successor of LAST.
  3. Make the next field of LAST point to the successor of current
  4. Release the memory for the node marked as current

Write an algorithm for inserting node at the beginning of the doubly-linked list, when list is not empty.

  1. Allocate memory for the new node.
  2. Assign a value to the data field of the new node.
  3. Make the next field of the new point to the first node in the list.
  4. Make the prev field of START point to the new node.
  5. Make the prev field of the new node point to NULL.
  6. Make START point to the new node.

My C/C++ Videos on Youtube

Here is the complete playlist for video lectures and tutorials for the absolute beginners. The language has been kept simple so that anybody can easily understand them. I have avoided complex jargon in these videos.