27.4k views
4 votes
An array contains the elements shown below. The first two elements have been sorted using a bubble sort. What would be the value of the elements in the array after three more passes of the bubble sort algorithm? Use the version of bubble sort that starts from the end and bubbles up the smallest element. 7, 12, 30, 50, 21, 23, 56, 87 B. An array contains the elements shown below. Using a quick sort show the contents of the array after the first pivot has been placed in its correct location. Identify the three sub lists that exist at that point. 44,78, 22,7,98,56, 34, 2, 38, 35, 45 C. After two passes of a sorting algorithm, the following array: 80, 72, 66, 44, 21, 33 Has been rearranged as shown below. 21, 33, 80, 72, 66,44 Which sorting algorithm is being used (straight selection, bubble, straight insertion)?

User Pei
by
8.7k points

1 Answer

1 vote

Final answer:

After three more bubble sort passes, the array would remain unchanged as the smallest values are already sorted. In quick sort, the array would see the pivot moved to its proper place with elements arranged on either side. The sorting algorithm implied in part C is straight selection sort.

Step-by-step explanation:

For part A, if we perform three more passes of the bubble sort algorithm, we'll end up with the following array:

First pass: 7, 12, 21, 30, 23, 50, 56, 87
Second pass: 7, 12, 21, 23, 30, 50, 56, 87
Third pass: 7, 12, 21, 23, 30, 50, 56, 87

Since the smallest elements are already at the front, the remaining passes simply confirm that no further swaps are needed.

For part B, after one partition in the quick sort algorithm, the array might look like:

7, 22, 2, 34, 35, 38, 44, 45, 56, 78, 98,
with the pivot 44 placed in its correct location. The three sublists now are:

  • Left sublist: 7, 22, 2, 34, 35, 38
  • Pivot: 44
  • Right sublist: 45, 56, 78, 98

Finally, for part C, the array has been partially sorted in such a way that suggests the straight selection sort algorithm is being used since the smallest elements are clearly moved to the front, one position at a time.

User Chetan Ahuja
by
8.3k points