In: Computer Science

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

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>

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 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 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 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, 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, 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.

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 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 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

Latest Questions

- william brown is 30 years and wants to retire when he is 65. so far he...
- 1. List and elaborate on the reasons that there more singles today than ever before. 2....
- During December of the current year, Teletex Systems, Inc., a company based in Seattle, Washington, entered...
- Which FTP command allows you to retrieve a file from within an FTP session? 39. Company...
- When would a sequential colormap work well in a heatmap? Select an answer: when you want...
- Write a synopsis about the CPU in 300 words
- C++ program Dairy Farm decided to ship milk in containers in the form of cubes rather...

ADVERTISEMENT