[Solved] CH08-320201-Homework 4 Bubble Sort & Stable and Adaptive Sorting.s and Heap Sort

$25

File Name: CH08-320201-Homework_4_Bubble_Sort_&_Stable_and_Adaptive_Sorting.s_and_Heap_Sort.zip
File Size: 753.6 KB

SKU: [Solved] CH08-320201-Homework 4 Bubble Sort & Stable and Adaptive Sorting.s and Heap Sort Category: Tag:
5/5 - (1 vote)

Problem 1: Bubble Sort & Stable and Adaptive Sorting.s

  • Bubble Sort is a comparison sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items, and swapping them if they are in the wrong order. This is repeated until no swaps are needed, which indicates that the list is sorted. Write the Bubble Sort algorithm in pseudocode including comments to explain the steps.
  • Derive the asymptotic worst-case, average-case, and best-case running time of Bubble Sort.
  • Stable sorting algorithms maintain the relative order of records with equal keys (i.e., values). Thus, a sorting algorithm is stable if whenever there are two records R and S with the same key and with R appearing before S in the original list, R will appear before S in the sorted list. Which of the sorting algorithms Insertion Sort, Merge Sort, Heapsort, and Bubble Sort are stable? Explain your answer.
  • A sorting algorithm is adaptive, if it takes advantage of existing order in its input. Thus, it benefits from the pre-sortedness in the input sequence and sorts faster. Which of the sorting algorithms Insertion Sort, Merge Sort, Heapsort, and Bubble Sort are adaptive? Explain your answer.

Problem 2: Heap Sort

  • Implement the Heap Sort algorithm as presented in class.
  • Implement a variant of the Heap Sort that works as follows: In the first step it also builds a max-heap. In the second step, it also proceeds as the Heap Sort does, but instead of calling MAX-HEAPIFY, it always floats the new root all the way down to a leaf level. Then, it checks whether that was actually correct and if not fixes the max-heap by moving the element up again. This strategy makes sense when considering that the element that was swapped to become the new root is typically small and thus would float down to a leaf level in most cases. Hence, one would save the additional tests when floating down the element. And, the fixing step (moving the element upwards again) would be a rare case.
  • Compare the original Heap Sort and its variant in (b) for input sequences of different lengths (including larger input sequences). What can you observe?

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CH08-320201-Homework 4 Bubble Sort & Stable and Adaptive Sorting.s and Heap Sort
$25