Question

# data structure Recall that the Insertion sort algorithm (for sorting an array A) from low...

# data structure
Recall that the Insertion sort algorithm (for sorting an array A) from low to high has the skeleton form:

for (i = 1; i < A.length; i++) {
details omitted
}

For i = 1 to 6, show how the contents of the array is rearranged if at all) after each iteration of the for-loop.
(10 pts)

the original array A
                                           A
6. 4. 7. 5. 2. 8. 3.
0 1 2 3 4 5 6

after i = 1
                                           A

0 1 2 3 4 5 6

after i = 2
                                           A

0 1 2 3 4 5 6

after i = 3
                                           A

0 1 2 3 4 5 6

after i = 4
                                           A

0 1 2 3 4 5 6

after i = 5
                                           A

0 1 2 3 4 5 6

after i = 6
                                           A

0 1 2 3 4 5 6

Homework Answers

Answer #1

initially:

6 4 7 5 2 8 3

0 1 2 3 4 5 6

after i=1

4 6 7 5 2 8 3

0 1 2 3 4 5 6

after i=2(no change)

4 6 7 5 2 8 3

0 1 2 3 4 5 6

after i=3

4 5 6 7 2 8 3

0 1 2 3 4 5 6

after i=4

2 4 5 6 7 8 3

0 1 2 3 4 5 6

after i=5(no change)

2 4 5 6 7 8 3

0 1 2 3 4 5 6

after i=6

2 3 4 5 6 7 8

0 1 2 3 4 5 6

(NOTE:for any doubt in the solution just leave a comment else please press the like button)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
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 this manually, i.e. step through the algorithm yourself without a computer. This question is related to data structure and algorithm in javascript (.js). Please do not copy from stackabuse or stackoverflow, Please explain that algorithm with comments. i really want to learn this concept.
First, understand the Selection-sort algorithm below: Selection-sort(A: Array [1..n] of numbers) 1       for i=n down to...
First, understand the Selection-sort algorithm below: Selection-sort(A: Array [1..n] of numbers) 1       for i=n down to 2 2                position=i 3                for j=1 to (i–1) 4                          if A[j]>A[position] then position=j 5                if position ≠ i then 6                          temp=A[i] 7                          A[i]=A[position] 8                          A[position]=temp (4 points) If input A=[12,5,11,6,10,7,9,8], what will A be after the 3rd iteration of the outermost for loop of the Selection-sort algorithm completes? A=[__, __, __, __, __, __, __, __] (8 points) Modify the algorithm to solve the...
An online/anytime sorting algorithm is one that reads its input numbers one at a time, and...
An online/anytime sorting algorithm is one that reads its input numbers one at a time, and maintains a sorted array of all the inputs it has seen so far, so that if it is interrupted at any time, it will still output the correct answer for the inputs that it has processed. Not all sorting algorithms are amenable to modification to make them anytime. But one sorting algorithm, Bubble Sort, is easy to so modify. First, understand the ascending order...
Write an application that prompt user to choose Sorting Algorithm (Insertion, Merge, or Heap) in GUI...
Write an application that prompt user to choose Sorting Algorithm (Insertion, Merge, or Heap) in GUI input message, then prompt user to enter numbers in GUI input message also, sort these numbers in descending order using Selected sorting algorithm, and show the result in message dialog as shown in the following figure. The program contains two classes: 1- “Sort” Class which contains 3 methods named as follow: a. InsertionSort(int[] numbers), returns sorted numbers from the passed array using Insertion sort...
Java : Modify the selection sort algorithm to sort an array of integers in descending order....
Java : Modify the selection sort algorithm to sort an array of integers in descending order. describe how the skills you have gained could be applied in the field. Please don't use an already answered solution from chegg. I've unfortunately had that happen at many occasion ....... ........ sec01/SelectionSortDemo.java import java.util.Arrays; /** This program demonstrates the selection sort algorithm by sorting an array that is filled with random numbers. */ public class SelectionSortDemo { public static void main(String[] args) {...
1.) Generate an array of 10 random numbers between 1 - 100 2.) Copy the array...
1.) Generate an array of 10 random numbers between 1 - 100 2.) Copy the array to a temp array 3.) Call each of the methods to sort (bubble, selection, insertion, quick, merge), passing it the array 4.) In-between the calls, you are going to refresh the array to the original numbers. 5.) Inside of each sorting method, you are going to obtain the nanoseconds time, before and after the method Subtract the before time from the after time to...
Implement functions for insertion sort, quicksort, heapsort and merge sort that input an array of integers...
Implement functions for insertion sort, quicksort, heapsort and merge sort that input an array of integers and sort it in-place. Write a program that generates random integer arrays (hint: use seed appropriately to avoid generating same sequences) of lengths 10, 100, 1000, 10,000, 100,000, 1000,000, and then sorts each using each of the sorting functions from (a), and measures the time in nanoseconds. The program will repeat this process 30 times and will compute the average execution time for each...
Complete the following table by specifying algorithm efficiency for : Selection sort, Insertion sort, Binary search,...
Complete the following table by specifying algorithm efficiency for : Selection sort, Insertion sort, Binary search, and Linear search. (Efficiency can be one of : log n, n, n2). List algorithms from the most efficient (fastest) to the least efficient (slowest).    ALGORITHM EFFICENCY 1 most efficient (fastest) 2 3 4 least efficient (slowest)
Write a MIPS assembly program that sorts an array using bubble sort translating the C code...
Write a MIPS assembly program that sorts an array using bubble sort translating the C code int main(void) { int array[] = {10, 2, 7, 5, 15, 30, 8, 6}; // input array int arraySize = sizeof(array)/sizeof(array[0]); bool swapped = true; int j = 0; int tmp; while (swapped) { swapped = false; //Note : "j" , "arraySize - j" are optimizations to the bubble sort algorithm j++; // j= sorted elements int i=0; /* "arraySize - j" is used...
(Data Structure) Suppose we want to store the data of a binary heap in an array....
(Data Structure) Suppose we want to store the data of a binary heap in an array. Show the data of that array after inserting the given keys one by one. Assume that initially binary heap is empty. Show all steps of insertions. Note: No need to show the changes for each step of “percolate up”. The contents of the array must be shown after completing one insertion. Create the “Min Heap” for the following data set 7,      3,      18,    -9,    ...