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

## Definitions

How do you define terms:

- Siblings/Brothers
- Internal node
- Level of a node
- Depth of a tree

- Siblings/Brothers: Children of the same node are called siblings of each other. In the preceding figure:
- Nodes 7 and 3 are siblings of each other
- Nodes 2 and 6 are siblings of each other

- Internal Node: An intermediate node between the root and the leaf nodes is called an internal node. It is also referred to as a non terminal node. In preceding figure, nodes 7,3,6 and 9 are internal nodes
- Level of a node: The distance of a node from the root is called the level of a node. The root always lies at level 0. As move down the tree, the level of a node increases in such a way that if a node is at level n, then its children are at level n+1. In preceding figure, level of node 1 is 0, level of nodes 7 and 3 are 1 and so on.
- Depth of a tree: The maximum number of levels in a tree is called the depth of a tree. In other words, depth of a tree is one more than maximum level of the tree. The depth of a tree in above figure is 4

## Binary searches can be done on an array[Yes/No]?

Yes.

## What is the worst case performance of selection sort?

The worst case performance of selection sort is O(n^{2}).

## Suppose an array A with elements indexed 1 to n is to be searched for a value x. Write pseudo code that performs a forward search, returning n + 1 if the value is not found.

- Set i to 1.
- Repeat this loop:
- If i > n, then exit the loop.
- If A[i] = x, then exit the loop.
- Set i to i + 1.

- Return i.

## Selection sort is suitable for which type of list.

Selection sort is suitable for small list.

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

## What is the best case efficiency of binary search?

The best case efficiency of binary search is O(1).

## What are steps for postorder traversing a binary tree?

The steps for post order traversing a binary tree are as follows:

- Traverse the left subtree
- Traverse the right subtree
- Visit the root

## How does the representation of a node in a doubly-linked list differ from that in a singly-linked list?

Unlike singly-linked list, in which each node stores the address of only the next node in the list, each node in a doubly-linked list holds the address of its previous node also.

## Which is the fundamental principle of hashing?

The fundamental principle of hashing is to convert a given key value to an offset address to retrieve a record.

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