0% found this document useful (0 votes)
23 views

Data Structure On Sorting and Searching

This document contains 19 problems related to searching and sorting algorithms. The problems cover topics like sequential search, binary search, selection sort, bubble sort, insertion sort, and merging sorted arrays. Performance analysis and time complexity is discussed for several of the sorting algorithms.

Uploaded by

bina
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Data Structure On Sorting and Searching

This document contains 19 problems related to searching and sorting algorithms. The problems cover topics like sequential search, binary search, selection sort, bubble sort, insertion sort, and merging sorted arrays. Performance analysis and time complexity is discussed for several of the sorting algorithms.

Uploaded by

bina
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

HiLCoE

School of Computer Science and Technology


Data Structure and Algorithm Analysis (CS221)
Worksheet 2(Simple Searching & Sorting)
1. Fill in the following table, showing the number of comparisons needed either to find the value or to
determine that the value is not in the array, given the following array of values.

14 27 95 12 26 5 33 15 9 99
[0] [1] [2] [3] [4] [5] [6] [7] [8] [9]

Sequential Search Sequential Search Binary Search


Values Unsorted Data Values Sorted Data Values Sorted Data Values
15
17
14
5
99
100
0
2. Modify sequential search for an array which is sorted(improving performance)
a. In ascending order. b. Descending order.
3. The element being searched is not in array of 100 elements. What is the maximum number of
comparisons needed in the following cases
a. if the search is sequential and the elements are completely unsorted?
b. if the search is sequential and the elements are sorted in ascending order?
c. if the search is sequential and the elements are sorted in descending order?
d. if the search is a binary search and the elements are sorted in ascending order?
4. Implement linear search recursively.
5. Binary search can only work on array data type. Why?
6. Develop a Ternary search algorithm that divides a list in to three parts and analyze the efficiency of the
code.
Show that Ti+1(n) >T i (n) for i >=2 where T representing the running time and i is the number of division.
7. Design an algorithm to search an element in two dimensional array of integer with row and column
size m and n respectively,
a. If the array is not sorted.
b. If the array is sorted only in column wise.
c. If the array is sorted in both column and row wise
8. For each of the cases of problem 7, determine the big-Oh.
HiLCoE
School of Computer Science and Technology
Data Structure and Algorithm Analysis (CS221)

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.

You might also like