Tutorial Sheet 1
Instructions
1. Tutorials in DAA course would majorly be doubt removal sessions.
2. Students are advised to come prepared in tutorial by revising the lectures of that particular week so that
doubts related to topics covered in that week are resolved.
3. Few practice questions will also be posted as Tutorial Sheet on your Google Classrooms. You can try
solving them before the scheduled tutorial and discuss the doubts.
4. As tutorials will be purely problem solving based, always join the tutorial with a notebook and pen with
you.
5. Whatever questions are discussed in tutorial, you are supposed to submit them on your respective
classrooms every week.
Review of Searching and Sorting Techniques
Q1) Use selection sort , insertion sort and bubble sort algorithms to sort the given arrays in ascending order. While
you apply these algorithms, count the number of comparisons and number of swaps made by each algorithm for
each of the array given below and fill them in table 1 and table 2. Comment on your observations and conclusions.
Array 1 Array 2
index 0 1 2 3 4 5 6 7 index 0 1 2 3 4 5 6 7
value 90 80 70 60 50 40 30 20 value 10 20 30 40 50 60 70 80
Table 1 : Number of Comparisons Table 2 : Number of Swaps
Array 1 Array 2 Array 1 Array 2
Selection Sort Selection Sort
Bubble Sort Bubble Sort
Insertion Sort Insertion Sort
Q2) Apply quick sort algorithm on below array containing 15 elements. Always take first element as the pivot
element. Which case (Best/Worst) does this example represents?
8 1 3 2 6 5 7 4 12 9 11 10 14 13 15
Q3) Given the following list of numbers:
[21, 1, 26, 45, 29, 28, 2, 9, 16, 49, 39, 27, 43, 34, 46,40].
What will be the array after 3 recursive calls to merge sort?
Q4) Given a sorted array of integers, propose an efficient scheme for finding the first occurrence of a given
number. Ex Input: Array = [2 4 4 4 8 8 10 10 10] , Target: 4 Output: Index of first occurrence of 4 is 1 .