HOMEWORK 3: CS 425 (THEORY OF ALGORITHMS) DUE DATE: September 30, 2020, 7 pm 1. Build a MaxHeap using the following data. Show all steps, make a table similar to all other problems. Keep a column for...

1 answer below »
Table for order# 68067 (Neha agreed to $30). No reference till needed.


HOMEWORK 3: CS 425 (THEORY OF ALGORITHMS) DUE DATE: September 30, 2020, 7 pm 1. Build a MaxHeap using the following data. Show all steps, make a table similar to all other problems. Keep a column for runtime. The data given are as below: 67, 39, 100, 54, 200, 80, 91, 198 Step 1: Step 2: Step 3: Step 4: Step 5: 2. Write a C++ Program to implement the Build MaxHeap Algorithm. Use the pseudocode given in the notes. #include using namespace std; void heapify(int arr[], int n, int i) { int largest = i; int left = 2 * i + 1; int right = 2 * i + 2; if (left < n="" &&="" arr[left]=""> arr[largest]) largest = left; if (right < n="" &&="" arr[right]=""> arr[largest]) largest = right; if (largest != i) { swap(arr[i], arr[largest]); heapify(arr, n, largest); } } void heapSort(int arr[], int n) { for (int i = n / 2 - 1; i >= 0; i--) heapify(arr, n, i); for (int i = n - 1; i >= 0; i--) { swap(arr[0], arr[i]); heapify(arr, i, 0); } } int main() { int arr[] = {22,11,55,2,0,5,10}; int n = sizeof(arr) / sizeof(arr[0]); heapSort(arr, n); cout < "sorted="" array="" is="" \n";="" for="" (int="" i="0;" i="">< n;="" ++i)="" cout="">< arr[i]="">< "="" ";="" cout="">< "\n";="" }="" 3.="" using="" the="" maxheap="" constructed="" in="" problem="" 1,="" show="" (a)="" how="" you="" would="" you="" add="" 178="" and="" (b)="" then="" show="" how="" you="" would="" delete="" the="" second="" node.="" a)="" 4.="" using="" the="" max="" heap="" as="" given="" below:="" 100,="" 90,="" 70,="" 40,="" 15,="" 65="" illustrate="" heap="" sort="" algorithm.="" step="" 2:="" step="" 3:="" step="" 4:="" step="" 5:="" step="" 6:="" step="" 7:="" step="" 8:="" the="" final="" sorted="" order="" is="" 15,40,65,70,90,100.="" 5.="" write="" a="" program="" in="" c++="" to="" implement="" heap="" sort="" algorithm.="" #include=""> using namespace std; void heapify(int arr[], int n, int i) { int largest = i; int l = 2*i + 1; int r = 2*i + 2; if (l < n="" &&="" arr[l]=""> arr[largest]) largest = l; if (r < n="" &&="" arr[r]=""> arr[largest]) largest = r; if (largest != i) { swap(arr[i], arr[largest]); heapify(arr, n, largest); } } void heapSort(int arr[], int n) { for (int i = n / 2 - 1; i >= 0; i--) heapify(arr, n, i); for (int i=n-1; i>0; i--) { swap(arr[0], arr[i]); heapify(arr, i, 0); } } int main() { int arr[] = {1,5,2,4,3,9,5,8,6,7}; int n = sizeof(arr)/sizeof(arr[0]); heapSort(arr, n); cout < "sorted="" array="" is="" \n";="" for="" (int="" i="0;">< arr[i]="">< "="" ";="" cout="">< "\n"; } "\n";="">
Answered Same DayOct 16, 2021

Answer To: HOMEWORK 3: CS 425 (THEORY OF ALGORITHMS) DUE DATE: September 30, 2020, 7 pm 1. Build a MaxHeap...

Neha answered on Oct 17 2021
139 Votes
HOMEWORK 3: CS 425 (THEORY OF ALGORITHMS)
DUE DATE: September 30, 2020, 7 pm
1. Build a MaxHeap us
ing the following data. Show all steps, make a table similar to all other problems. Keep a column for runtime.
The data given are as below:
67, 39, 100, 54, 200, 80, 91, 198
    1
    2
    3
    4
    5
    6
    7
    8
    Runtime
    67
    39
    100
    54
I
    200
    80
    91
    198
L
    1
    67
    39
I
    100
    198
    200
R
    80
    91
    54
    
    67
I
    200
L
    100
R
    198
    39
    80
    91
    54
    
    200
    67
I
    100
    198
L
    39
    80
    91
    54
    
    200
    198
    100
    67
    39
    80
    91
    54
    
2. Write a C++ Program to implement the Build MaxHeap Algorithm. Use the pseudocode given in the notes.
#include
using namespace std;

void heapify(int arr[], int n, int i) {
int largest = i;
int left = 2 * i + 1;
int right = 2 * i + 2;

if (left < n && arr[left] > arr[largest])
largest = left;

if (right < n && arr[right] >...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here