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

Lab_Assignment-9

The document outlines a lab assignment consisting of multiple programming tasks focused on sorting algorithms, including insertion sort, selection sort, and bubble sort, along with performance analysis. It also includes tasks for sorting two-dimensional arrays, implementing binary search, and creating recursive search functions. The assignment emphasizes understanding algorithm efficiency through comparisons and swaps in various scenarios, including already sorted arrays.

Uploaded by

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

Lab_Assignment-9

The document outlines a lab assignment consisting of multiple programming tasks focused on sorting algorithms, including insertion sort, selection sort, and bubble sort, along with performance analysis. It also includes tasks for sorting two-dimensional arrays, implementing binary search, and creating recursive search functions. The assignment emphasizes understanding algorithm efficiency through comparisons and swaps in various scenarios, including already sorted arrays.

Uploaded by

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

Lab Assignment-9

1. Write a program to implement insertion sort algorithm for sorting an array.


2. Write a program to implement selection sort algorithm for sorting an array.
3. Write a program to sort an array implementing each of the following
a. bubble sort,
b. insertion sort and
c. selection sort
At the end print the comparative analysis on number of comparisons and swapping
performed while executing the algorithms on given array.
4. Write a program to implement each of the following
a. bubble sort,
b. insertion sort and
c. selection sort
Where the input array is already sorted. Following the steps of the above algorithms
analyze the difference in performance (considering number of comparisons and swapping) and
print your analysis as output.
5. The bubble sort is inefficient for large arrays. Make the following simple modifications
to improve its performance taking the array a[10] = {2, 6, 4, 8, 10, 12, 89, 68, 45, 37}.
a. After the first pass, the largest number is guaranteed to be in the highest-
numbered element of the array; after the second pass, the two highest numbers
are in place, and so on. Instead of making nine comparisons on every pass,
modify the bubble sort to make eight comparison on the second pass, seven on
the third pass and so on.
b. The data in the array may already be in the proper or near proper order, so why
make nine passes if fewer will suffice? Modify the sort to check at the end of
each pass whether any swaps have been made. If none has been made, then the
data must already be in the proper order, so the program should terminate. If
swaps have been made, then at least one more pass is needed.

6. Write a program to sort a two dimensional array of characters (strings) containing 10


words and sort them in alphabetical order.

7. Write a program to implement insertion sort algorithm for sorting an already sorted
array. Then sort the array in descending order. Compare both the approaches and print
your analysis as output.

8. Write a program to implement binary search to find a string. Given a sorted array of
String and a String x, find index of x if it is present in the array else return -1.
9. Write a recursive function to implement linear search algorithm. The function should
receive an integer array, the size of the array and the search key as arguments. If the
search key is found, return the array subscript, else return -1.
10. Write a recursive function to implement binary search algorithm. The function should
receive an integer array, the starting subscript, the ending subscript and the search key
as arguments. If the search key is found, return the array subscript, else return -1.

You might also like