Sort and Searching Interview Questions and Answers

1

What is linear search?

Linear search is the simplest form of search. It searches for the element sequentially starting from the first element. This search has a disadvantage if the element is located at the end. Advantage lies in the simplicity of the search. Also it is most useful when the elements are arranged in a random order.

2

Tell me what is quick sort?

Quick sort is one the fastest sorting algorithm used for sorting a list. A pivot point is chosen. Remaining elements are portioned or divided such that elements less than the pivot point are in left and those greater than the pivot are on the right. Now, the elements on the left and right can be recursively sorted by repeating the algorithm.

3

What is binary search?

Binary search is most useful when the list is sorted. In binary search, element present in the middle of the list is determined. If the key (number to search) is smaller than the middle element, the binary search is done on the first half. If the key (number to search) is greater than the middle element, the binary search is done on the second half (right). The first and the last half are again divided into two by determining the middle element.

4

What is bubble sort algorithm?

Bubble sort algorithm is used for sorting a list. It makes use of a temporary variable for swapping. It compares two numbers at a time and swaps them if they are in wrong order. This process is repeated until no swapping is needed. The algorithm is very inefficient if the list is long.

E.g. List: - 7 4 5 3

7 and 4 are compared

Since 4 < 7, 4 is stored in a temporary variable.

the content of 7 is now stored in the variable which was holding 4

Now, the content of temporary variable and the variable previously holding 7 are swapped.

5

What is Mergesort and Hashtable?

In short:
Mergesort is a sorting algorithm that follows the paradigm of: divide and conquer:

recursivly split the array in 2

until the array length is 1 ( or the pointers start and end are equal)

FOLLOW US