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

## How many comparisons are performed in the second pass of the selection sort algorithm?

n-2 comparisons are performed in the second pass of the selection sort algorithm.

## Write a program in c for linear search.

#include<stdio.h> int main() { int array[100], search, c, number; printf("Enter the number of elements in array\n"); scanf("%d",&number); printf("Enter %d numbers\n", number); for ( c = 0 ; c < number ; c++ ) { scanf("%d",&array[c]); } printf("Enter the number to search\n"); scanf("%d",&search); for ( c = 0 ; c < number ; c++ ) { /* if required element found */ if ( array[c] == search ) { printf("%d is present at location %d.\n", search, c+1); break; } } if ( c == number ) { printf("%d is not present in array.\n", search); } return 0; }

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

Yes.

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

## What do you mean by *Binary Search Tree*?

A binary search tree is a binary tree in which the value of the left child of a node is always less than the value of the node, and the value of the right child of a node is always greater than the value of the node.

The root node contains 52. All the nodes in the left subtree of the root have a value less than 52. Similarly, all the nodes in the right sub-tree of the root node have values greater than 52.

## What are the basic criteria for selecting appropriate algorithm?

- Execution Time.
- Storage Space.
- Programming Effort.

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

## What do you understand by folding method?

In this method, an address is calculated by breaking the keys into parts and then adding them. Consider the following keys:

4766934,5656975,4685637,3547807,7569664

_{}

Keys | Dividing the keys | Result |
---|---|---|

4766934 | 47+6634+4 | 6744 |

5656975 | 56+5697+5 | 5758 |

4685637 | 46+8563+7 | 8616 |

3547807 | 35+4780+7 | 4822 |

7569664 | 75+6966+4 | 7045 |

Now, truncate the result up to the digit based on the sizeof the hash table.Suppose the size of the table is 1000. Therfore, the hash address will be from 0 to 999. In the given example the result consists of four digits. Therefore, truncate the first digit of the result to obtain the address, as shown in fig below:

Keys | Address |
---|---|

47669334 | 744 |

5656975 | 758 |

4685637 | 616 |

3547807 | 822 |

7569664 | 045 |

## How do you define *tree* in a data structure?

A tree is a nonlinear data structure that represents a hierarchical relationship among the various data elements, as shown in the following figure.

Each data elements in a tree is called a node. The topmost node of the tree is called a root

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