Question
Need help with this in c programming You will implement the Heap Data Structure and HeapSort algorithm from the lecture/readings. Implement the algorithms as described
Need help with this in c programming
You will implement the Heap Data Structure and HeapSort algorithm from the lecture/readings. Implement the algorithms as described in the lecture notes or you will not receive full credit.
The following files are provided:
main.c containing the main program. DO NOT EDIT THIS FILE
sortTests.c a file containing tests to verify the sorts work correctly. DO NOT EDIT THIS FILE
sortTests.h The function prototypes for the sorting tests. DO NOT EDIT THIS FILE
heap.h All function prototypes and the Heap Data Structure. DO NOT EDIT THIS FILE
heap.c You will need to create this file and implement everything you need.
The heap.c file does not even exist. It has no working code.
If you complete your implementations correctly, the main program will work with no changes needed.
Here is a printHeap function you can use to debug your code. It is not needed, but extremely useful for testing.
//A gift to the student: void printHeap(Heap* H){ printf("Heap Current Size: %d ",H->currentSize); printf("Heap Max Size: %d ",H->maxSize); printf("Contents: "); for(int i=0; i currentSize; i++) { printf("%d ",H->data[i]); } printf(" "); }
Example Execution
You can run the code and it will provide a menu. You can collect timings or test the sort.
If your algorithm fails, information about what went wrong will be printed.
Example 1
Select Which Test to Run: 0.) Time All Algorithms 1.) Test Heap Sort 1 Testing Heap Sort Enter Size of Arrays to Test: 100 Enter Number of Tests to Run: 50 Passed 50 out of 50 tests.
Example 2
Select Which Test to Run: 0.) Time All Algorithms 1.) Test Heap Sort 1 Testing Heap Sort Enter Size of Arrays to Test: 10 Enter Number of Tests to Run: 3 Passed 3 out of 3 tests.
Example 3
Select Which Test to Run: 0.) Time All Algorithms 1.) Test Heap Sort 1 Testing Heap Sort Enter Size of Arrays to Test: 9 Enter Number of Tests to Run: 11 Passed 11 out of 11 tests.
Timings
Once all your algorithms work correctly, run the program and select 0 to collect timings.
Place the output of the program in a file readme.md
You must also make a chart timings.png comparing heapsort to the algorithms from Homework 3. The y axis should be time and the x axis should be log2(size). Since the sizes grow so fast, the chart will be easier to read if you use the log2 of the size along the x axis.
Only compare Heap Sort with your Quick Sort and Merge Sort results from Homework 3. You can ignore Bubble Sort and Insertion Sort.
You can just copy-paste your timings from Homework 3.
Below the timings answer the following questions in readme.md:
What was the fastest algorithm?
What was the slowest algorithm?
Did the timings match the analysis from class?
What was the hardest part of this assignment?
Template Table
Size | Merge | Quick | Heap |
---|---|---|---|
8 | ? | ? | ? |
16 | ? | ? | ? |
32 | ? | ? | ? |
64 | ? | ? | ? |
128 | ? | ? | ? |
256 | ? | ? | ? |
512 | ? | ? | ? |
1024 | ? | ? | ? |
2048 | ? | ? | ? |
4096 | ? | ? | ? |
8192 | ? | ? | ? |
16384 | ? | ? | ? |
32768 | ? | ? | ? |
65536 | ? | ? | ? |
131072 | ? | ? | ? |
C main C main > No Selection heap No Selection h heap h heap > No Selection 115116117118119120121122123124125voidswap(Heap*H,inti,intj);/Thisfunctionprintstheheapandwillhelpyoudebug.eparamHistheheaptoprint/voidprintHeap(Heap*H);#endif| h sortTests > No Selection C main C main > No Selection heap No Selection h heap h heap > No Selection 115116117118119120121122123124125voidswap(Heap*H,inti,intj);/Thisfunctionprintstheheapandwillhelpyoudebug.eparamHistheheaptoprint/voidprintHeap(Heap*H);#endif| h sortTests > No Selection
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started