## 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.

- Allocate memory for the new node.
- Assign value to the data field of the new node.
- Make the next field of the node marked as LAST point to the new node.
- Make the prev field of new node point to node marked LAST.
- Make the next field of the new node point to NULL.
- 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:

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

## 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:

- Allocate memory for the new node.
- Assign value to the data field of the new node
- Make the next field of the new node point to successor of LAST.
- Make the next field of LAST point to new node.
- Make LAST point to the new node.

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

- 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:
- Make current point to the first node.
- Make previous point to NULL.
- Repeat step d and e until current.info>newnode.info or current=NULL.
- Make previous point to current.
- Make current point to the next node in sequence.

- Allocate memory for the new node.
- Assign value to the data field of the new node.
- Make the next field of the new node point to current.
- Make the prev field of the new node point to previous.
- Make the prev field of current point to the new node.
- 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:

- Make currentNode point to the first node in the list.
- Repeat step 3 and 4 until currentNode becomes NULL.
- Display the information contained in the node marked as currentNode.
- 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 .

- Allocate memory for the new node.
- Assign a value to the data field of the new node.
- Make the next field of the new node point to NULL.
- 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:

- 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:
- Set previous=START.
- Set current=START.
- Repeat steps d and e until either the node is found or current becomes NULL.
- Make previous point to current.
- Make current point to the next node in sequence.

- Make the next field of previous point to the successor of current.
- 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:

- Allocate memory for the new node.
- Assign a value to the data field of the new node.
- Make the next field of the new point to NULL.
- Make the prev field of the new node point to NULL.
- 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:- Mark the first node in the list as current.
- Make START point to the next node in its sequence.
- If START is not NULL:
- Assign NULL to the prev field of the node marked as START.

- 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.