Data Structure On Sorting and Searching
Data Structure On Sorting and Searching
14 27 95 12 26 5 33 15 9 99
[0] [1] [2] [3] [4] [5] [6] [7] [8] [9]
9. What are the conditions under which sequential search of a list is preferred over binary search?
10. An interpolation search is a rarely used search. This search assumes that the data must not only be
sorted, but it must also be fairly uniformly distributed. For example, a phone book is fairly uniformly
distributed. The interpolation search requires that we spend more time to make an accurate guess of
where the item might be. The binary search always uses the midpoint. However, searching for Bekele
Dawit in the middle of the phone book would be silly; somewhere near the start clearly would be
more appropriate. Thus, instead of mid, we use next to indicate the next item that we will try to access.
The applicable formula is
next=low +¿The subtraction of 1 is a technical adjustment that performs well in practice. Write the
interpolation search algorithm. And analyze the algo performance.
11. Given the array below, show the contents of the array
43 7 10 23 18 4 19 5 66 14
[0] [1] [2] [3] [4] [5] [6] [7] [8] [9]
for the first three iteration of the outer loop of
a. Selection sort
b. Bubble sort
c. Insertion sort
d. Shell sort
12. An ordered list is disordered by adding small number of elements at the end of the list. Which simple
sorting algorithm do you recommend to sort this list? Justify your answer.
13. Which sorting algorithm is best if the list is already sorted? Why?
14. If the cost to do swap is high, which simple sorting algorithm do you recommend to sort a list?
a. In the best case scenario
b. In the worst case scenario
15. Bubble sort algorithm is inefficient because it continues execution even after an array is sorted by
performing unnecessary comparisons. Therefore, the number of comparisons in the best and worst
cases is the same. Modify the algorithm in such a fashion that it will not make the next pass when the
array is already sorted.
16. Modify insertion sort so that it uses Binary search to locate the position within the first i -1 elements of
the array into which element i should be inserted. How would using such Binary search affect the Big-
Oh for Insertion Sort?
17. Write an algorithm to merge two sorted arrays into a third array. The merged array should be sorted..
18. Design algorithm to sort a two dimensional array A[n][n] (all elements in a row is sorted and all the
elements in the ith row are less than the elements in the ith +1 row ) using Selection Sort. And
determine its running time complexity and its Big-Oh.
19. Repeat problem 17 for Bubble sort and Insertion sort.