question archive 1) a) Use an algorithm to sort elements using Insertion Sort    b)Explain the bubble sort algorithm with an example

1) a) Use an algorithm to sort elements using Insertion Sort    b)Explain the bubble sort algorithm with an example

Subject:Computer SciencePrice:9.82 Bought3

1) a) Use an algorithm to sort elements using Insertion Sort

   b)Explain the bubble sort algorithm with an example. 

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Answer Preview

This paragraph explains about the insertion sort and the bubble sort .

Step-by-step explanation

Ans ) Insertion sort algorithm

Step 1: If first element return 1

Step 2: Take next number and compare with sorted sub list

Step 3: Shift the elements which are greater than the sorted sub list

Step 4 : Insert value

Step 5: Repeat steps 2 to 4 until all elements are sorted.

 

Ans ) Bubble sort is used to arrange the string of numbers in a sorted way which works by analyzing each set of adjacent elements in the string from the left to right if they are out of order. This process is repeated until and unless there are no two elements that needs to be swapped.

Example:

Suppose we have array of length n to sort it using bubble sort the following steps are followed.

Step 1:It starts with very first two elements to check which one is greater

Sep 2: For example lets take if 33 is greater than 14 and if 14 is before 33 then it is already sorted and then it takes another value lets say 27

Step 3: Since 27 is smaller than 33 it swapped the place that is 27 is placed before 33 and later in place of 27

Step 4:Like this all other elements in the array is sorted if any element is smaller than 33 until it gets greater vale lets say 35

Step 5: Now if there is smaller value after 35 lets say 10 then again it is swapped and 10 is put before 35

Step 6: Since as it is known that 10 is also smaller than 33 then again the value of 33 is swapped with 10

Step 7: This process continues until the value of 10 is put at its right place that is no value is greater than 10