Question

In: Computer Science

1. Insertion sort for 12, 2, 3, 21, 11, 10,8 2. Bubble sort for 12, 2,...

1. Insertion sort for 12, 2, 3, 21, 11, 10,8

2. Bubble sort for 12, 2, 3, 21, 11, 10,8

3. selection sort for 12, 2, 3, 21, 11, 10,8

analysis of algorithm

Solutions

Expert Solution

Assuming all the sorting techniques are sorting the data in ascending order.

1) Insertion Sort steps: (Inserting one by one element and sorting like playing cards)

(i) 2, 12, 3, 21, 11, 10, 8 <12 inserted> No. of comparison:1 (comarison between 12 and 2)

(ii) 2, 3, 12, 21, 11, 10, 8 <3 inserted> No. of comparison: 2 (comarison between 12 and 3, then 2 and 3)

(iii) 2, 3, 12, 21, 11, 10, 8 <21 inserted> No. of comparison: 1 (comarison between 12 and 21)

(iv) 2, 3, 11, 12, 21, 10, 8 <11 inserted> No. of comparison: 3 (11 will be compared with 21, 12, 3)

(v) 2, 3, 10, 11, 12, 21, 8 <10 inserted> No. of comparison: 4 (10 will be compared with 21, 12, 11, 3)

(vi) 2, 3, 8, 10, 11, 12, 21 <8 inserted> No. of comparison: 5 (8 will be compared with 21, 12, 11, 10, 3)

Total No. of comparisons: 16

2) Buble Sort steps:

(i) 2, 3, 12, 11, 10, 8, 21 (Here the largest element would be bubbled up to the last slot of the array, for that there will be n - 1 = 7 -1 = 6 many compariosons).

In the next step the second largest element would be bubbled up to the second last slot of the array, which will require 6 - 1 = 5 many comparisons.

So in total number of comparisons would be : n * (n - 1) / 2 = 7 * 6 / 2 = 21 [where n is the number of elements]  

3) Selection Sort steps:

Here we are going to find max among the entire data set, which requires (n - 1) time comparison. Then in the next step we try to find second max from the rest of the data, which requires (n - 2) time comparison and this will go on untill only a single data is left. which turns out to be same as buble sort :  n * (n - 1) / 2 = 7 * 6 / 2 = 21 [where n is the number of elements]

Here the first step is shown:

(i) 12, 2, 3, 8, 11, 10, 21 <swaping takes place between the last element and the max element>


Related Solutions

selection sort for 12, 2, 3, 21, 11, 10,8
selection sort for 12, 2, 3, 21, 11, 10,8
out of the following four: 1.Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort a. Which...
out of the following four: 1.Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort a. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is random? b. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is 90% sorted? c. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is reverse sorted? d. Which sorting methods perform best and...
out of the following four: 1.Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort a. Which...
out of the following four: 1.Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort a. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is random? b. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is 90% sorted? c. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is reverse sorted? d. Which sorting methods perform best and...
2 real-time examples on the Insertion sort, Bubble sort, Selection sort, Quick sort, Shell sort, Merge...
2 real-time examples on the Insertion sort, Bubble sort, Selection sort, Quick sort, Shell sort, Merge sort, Radix sort, Bucket sort, and Counting sort.
come up with at least 2 real-time examples on the Insertion sort, Bubble sort, Selection sort,...
come up with at least 2 real-time examples on the Insertion sort, Bubble sort, Selection sort, Quick sort, Shell sort, Merge sort, Radix sort, Bucket sort, and Counting sort.
come up with at least 2 real-time examples on the Insertion sort, Bubble sort, Selection sort,...
come up with at least 2 real-time examples on the Insertion sort, Bubble sort, Selection sort, Quick sort, Shell sort, Merge sort, Radix sort, Bucket sort, and Counting sort.
give a good explanation of Bubble sort, Insertion sort, Selection sort, and Quicksort.
give a good explanation of Bubble sort, Insertion sort, Selection sort, and Quicksort.
Sort the following set of numbers using bubble sort, insertion sort, and selection sort. Show the...
Sort the following set of numbers using bubble sort, insertion sort, and selection sort. Show the process step-by-step, and find the time complexity in Big-O notation for each method. For sorting, use ascending order. 49, 7, 60, 44, 18, 105
For this assignment, find out how to do a bubble sort, selection sort, or insertion sort...
For this assignment, find out how to do a bubble sort, selection sort, or insertion sort in Java. You have the option to choose but you must label (with comments) the algorithm you choose to implement. Convert that algorithm to a generic algorithm and constraint it to only using numerics. Your method should accept an array as a parameter and sort the content of the array. If you wish, you can throw an exception if the contents of the array...
Sorting – Insertion Sort Sort the list 0, 3, -10,-2,10,-2 using insertion sort, ascending. Show the...
Sorting – Insertion Sort Sort the list 0, 3, -10,-2,10,-2 using insertion sort, ascending. Show the list after each outer loop. Do his manually, i.e. step through the algorithm yourself without a computer. This question is related to data structure and algorithm in javascript (.js). Please give your answer keeping this in your mind.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT