Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this assignment you need to implement a min - heap data structure in C + + , and use it to sort a vector

For this assignment you need to implement a min-heap data structure in C++, and use it to sort a vector of distinct integers into ascending order. While doing so, count the number of swap operations performed during insert and delete. The initial insertion (during insert) or replacement of the removed element (during deletion) do not count towards this. The input vector is to be read from standard input, in the format n value 1 value 2... value n Instead of just sorting the original input vector, you also need to (re-)sort vectors with elements already sorted in ascending or descending order. Afterwards, report swap counts for insertion and deletion for each of these three input vectors. For example: Here the three outputs (original/ascending/descending) correspond to the input vectors: 211570702215701151 Note that some sorting algorithms perform particularly poorly or well for sorted inputs (e.g. bubble sort). Running your code on some larger inputs can give you an idea whether or not (or to what degree) that's the case for heapsort. You can use CodeRunner to test your work, but must submit your assignment as usual. If teamwork is permitted and you work in a team, you must include the names and student IDs of all team members as comments in your submission, and each team member must submit the same assignment separately. Working Example For the original input [2,7,0,15,1], the heap vector representing the tree is updated as follows:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Azure SQL Database For Modern Developers Building Applications In The Microsoft Cloud

Authors: Davide Mauri, Silvano Coriani, Anna Hoffma, Sanjay Mishra, Jovan Popovic

1st Edition

1484263693, 978-1484263693

More Books

Students also viewed these Databases questions