Interview Questions on Linked Lists in Data Structures Set 2

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. 2 in this series.

Last Reviewed and Updated on August 18, 2019
Posted by Parveen(Hoven),
Aptitude Trainer and Software Developer

Advertisement

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 to insert a node at the end of the doubly-linked list.

  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 node marked as LAST point to the new node.
  4. Make the prev field of new node point to node marked LAST.
  5. Make the next field of the new node point to NULL.
  6. Mark the new node as LAST.

Write an algorithm for traversing a singly-linked list

The algorithm for traversing a singly-linked list is as follows:

  1. Make currentNode point to the first node in the list.
  2. Repeat step 3 and 4 until currentNode becomes NULL.
  3. Display the information contained in the node marked as currentNode.
  4. Make currentNode point to thr next node in sequence.
Advertisement

Write an algorithm to insert a node at the end of the list, when the list is not empty.

The algorithm for inserting a node at the end of the list as follows:

  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 successor of LAST.
  4. Make the next field of LAST point to new node.
  5. Make LAST point to the new node.

Write an algorithm to insert a node between two nodes in the doubly-linked list.

  1. Identify the nodes between which the new node is to be inserted. Mark them as previous and current respectively. To locate previous and current, execute the following steps:
    1. Make current point to the first node.
    2. Make previous point to NULL.
    3. Repeat step d and e until current.info>newnode.info or current=NULL.
    4. Make previous point to current.
    5. Make current point to the next node in sequence.
  2. Allocate memory for the new node.
  3. Assign value to the data field of the new node.
  4. Make the next field of the new node point to current.
  5. Make the prev field of the new node point to previous.
  6. Make the prev field of current point to the new node.
  7. Make the next field of previous point to the new node.

Write an algorithm for traversing a singly-linked list

The algorithm for traversing a singly-linked list is as follows:

  1. Make currentNode point to the first node in the list.
  2. Repeat step 3 and 4 until currentNode becomes NULL.
  3. Display the information contained in the node marked as currentNode.
  4. Make currentNode point to thr next node in sequence.

Write an algorithm for inserting a node in a Singly-Linked list, if list is 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 node point to NULL.
  4. Make START point to the new node

Write an algorithm for deleting a node between two nodes of the singly-linked list.

The algorithm to delete a node between two nodes of the singly-linked list is as follows:

  1. Locate the node to be deleted. Mark the node to be deleted as current and its predecessor as previous. To locate current and previous, execute the following steps:
    1. Set previous=START.
    2. Set current=START.
    3. Repeat steps d and e until either the node is found or current becomes NULL.
    4. Make previous point to current.
    5. Make current point to the next node in sequence.
  2. Make the next field of previous point to the successor of current.
  3. Release the memory for the node marked as current

Write an algorithm for inserting nodes in doubly-linked list, if the list is empty.

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

  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 NULL.
  4. Make the prev field of the new node point to NULL.
  5. Make START point to the new node.

How do you define singly-linked list?

Singly linked lists contain nodes which have a data field as well as a next field, which points to the next node in the linked list.

A singly linked list whose nodes contain two fields: an integer value and a link to the next node.

Write an algorithm for deleting a node from the beginning of the doubly 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. If START is not NULL:
    1. Assign NULL to the prev field of the node marked as START.
  4. Release the memory of the node marked as current.

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.