Binary heap in java

timer Asked: Apr 30th, 2017
account_balance_wallet $70

Question description


1. Understand the structure of a binary heap.

2. Be able to analyze the complexities of an algorithm through experiments.

Task Description:

In this project, you are going to build a max-heap. You will use an array to implement the heap. Your program should:

• Allow the user to select one of the following two choices (Note that your program needs to implement both choices): o

(1) test your program with 100 randomly generated integers (no duplicates, positive numbers with proper range); o

(2) test your program with the following 100 fixed values from 1, 2, 3, ..., and 100.

• Implement both methods of building a max heap: o Using sequential insertions (see slide 27); o Using the optimal method (see slide 32 – the smart way). For both methods, you need to keep track of how many swaps (swapping parent and child) are required to build a heap.

• For choice (1), you need to generate 20 sets of randomly generated integers; compute, print and document (in your project report) the average number of swaps for both methods. Your program should output the average number of swaps for both methods (an average over 20 sets).

• For choice (2), your program should output the first 10 integers in your array and the number of swaps for both methods. Then perform 10 removals on the heap and output the first 10 integers.


Please select how to test the program: (1) 20 sets of 100 randomly generated integers (2) Fixed integer values 1-100 Enter choice: 1 Average swaps for series of insertions: 107 Average swaps for optimal method: 87 =====================================================================

Please select how to test the program:

(1) 20 sets of 100 randomly generated integers

(2) Fixed integer values 1-100 Enter choice: 2 Heap built using series of insertions: 100,94,99,77,93,98,61,68,76,84,... Number of swaps: 480 Heap after 10 removals: 90,89,62,77,88,53,61,68,76,84,... Heap built using optimal method: 100,95,99,79,94,98,63,71,78,87,... Number of swaps: 96 Heap after 10 removals: 90,89,63,79,88,55,62,71,78,87,...

What to Submit?

1. All java source code (, which contains the main method and other supported java files).

2. Please zip all documents

Tutor Answer

School: University of Maryland

Here is the final version of co...

flag Report DMCA

Outstanding Job!!!!

Similar Questions
Hot Questions
Related Tags

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors