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

- Mark the first node in the list as current.
- Make START POINT to the next node in its sequence.
- 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.

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

- Make current point to LAST.
- mark the predecessor of LAST as previous. To locate the predecessor of LAST execute the following steps:
- Make previous point to the successor of LAST.
- Repeat step c until the successor of previous becomes LAST.
- Make previous point to the next node in sequence.

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

- Allocate memory for the new node.
- Assign value to the data field of the new node.
- If START is NULL,then:
- Make START point to the new node.
- Go to step 6.

- Locate the last node in the list, and mark it as currentNode.To locate the last node in the list,execute the following steps:
- Mark the first node as currentNode.
- Repeat step c until the
*successor*of currentNode becomes NULL. - Make currentNode point to the next node in sequence.

- Make the next field of currentNode point to the new node.
- 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:

- 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 the first node in the list.
- 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:

- If the node to be deleted is the only node in the list:
- Mark LAST as NULL
- Exit

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

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