Conquer:
Recursively sort the two sub arrays.
Combine:
Combine all the sorted elements in a group to form a list of sorted elements.
7. What is a pivot element?
Pivot element is a key value that is selected and shuffled continuously as per the quick sort
algorithm until it attains its final position in the list.
8. What are the advantages and disadvantages of quick sort?
Advantages:
i) It is one of the fastest sorting algorithms.
ii) Quick sort reduces unnecessary swaps and moves an item.
ii) Its implementation does not require any additional memory.
Disadvantages:
i) The worst case efficiency of O(n2) is not well suited for large sized lists.
ii) Little more complex than other sorting algorithms.
9. What are the techniques used to choose the pivot element for quick sort and how many pointers
are used for quick sort?
The various techniques are First element, Random pick Median of three portioning
Quick sort requires two scans one from left to right and another from right to left, so two pointers
needed for the scans.
10. What is meant by merge sort?
Merge sort is based on divide-and-conquer approach.
It divides a list into several sub lists of equal sizes and sorts them individually.
It merges the various sub lists in pairs to eventually form the original list.
11. How many pointers are used in merge sort?
Three pointers are used in merge sort. i - ptr for the first sorted sub array, j - ptr for the second
sorted sub array and k - ptr for the merged sorted sub array.
12. What are the advantages and disadvantages of merge sort?
Advantages:
i) It is a fast and stable sorting method
ii) It always ensures an efficiency of O(n log(n))
Disadvantages:
i) It requires additional memory space to perform sorting.
ii) The number of comparisons made by merge sort is nearly optimal; its performance is slightly lesser
than quick sort.
13. Discuss the efficiency of different sorting algorithms.
Sorting Algorithms
Insertion sort
Bubble sort
Selection sort
Quick sort
Best case
O(n)
O(n)
O(n2)
O(n log(n))
Average Case
O(n2)
O(n2)
O(n2)
O(n log(n))
Worst Case
O(n2)
O(n2)
O(n2)
O(n2)
Merge sort
O(n log(n))
O(n log(n))
O(n log(n))
Big Oh notation
Omega notation
Theta notation.
1.
2.
3.
4.
5.
6.
7.
For each element in the array, check whether the element is same as the element to be searched
If the element is equal to e, then display its position.
Else, the element is not found.
Time complexity
O(n)
O(log(n))
Part B
1.
2.
3.
4.
5.
6.
7.