Project Tasks:

1. Create a class for the heap data structure, where a heap (min-order) is implemented using an array.

  • a. Implement a method for building a heap, given a regular binary tree represented as an array with the elements as 11, 6, 4, 5, 8, 10, 19, 17, 43, 31, 49.
  • b. Implement a method for inserting a new element in a given heap.
  • c. Implement a method for removal of the minimum element (root) from the heap.

2. Create another class for testing your data structure, where in the Main method, do the following:

  • . Create an object of the heap class to create a heap. Call the appropriate method from your heap class to build a heap from the elements given as 11, 6, 4, 5, 8, 10, 19, 17, 43, 31, 49. Display the contents of the created heap by listing the elements of the array.
  • b. Call the appropriate method to insert a new element (value = 25) into the heap created in step 2a. Display the contents of the modified heap by listing the elements of the array.
  • c. Delete the root node to remove the minimum element from the heap resulting after step 2b. Display the contents of the modified heap by listing the elements of the array.

3. Create a method to display the heap by drawing it as a binary tree on screen. Use Graphics to draw the heap.

For Example, if the binary tree array is 11, 6, 4, 5, 8, 10, 19, 17, 43, 31, 49. You are supposed to draw a tree shown as follows: see image.

You can design the shape of your tree. For example, you can decide where to positon nodes and lines. The following example shows you how to use graphics to define the size and color of the circle and draw a circle on a form.

//Define pen, brush and graphics
Pen bluePen = new Pen(Color.Blue, 3);
SolidBrush drawBrush = new SolidBrush(Color.Azure);
Graphics graphics = this.CreateGraphics();
graphics.DrawEllipse(bluePen, 100, 200, 50, 50);
graphics.FillEllipse(drawBrush, 100, 200, 50, 50);
The following example shows you how to use graphics to draw a line:
graphics.DrawLine(bluePen, 225, 325, 375, 325);

The following example shows you how to use graphics to display a string:

// Create font and brush.
Font drawFont = new Font("Arial", 16);
SolidBrush drawBrush = new SolidBrush(Color.Black);
RectangleF drawRect = new RectangleF(x, y, width, width);
// Set format of string.
StringFormat drawFormat = new StringFormat();
drawFormat.Alignment = StringAlignment.Center;
// Draw string to screen.
graphics.DrawString(“test”, drawFont, drawBrush, drawRect, drawFormat);

* More details about Graphics class can be found though the following URL:

https://msdn.microsoft.com/en-us/library/System.Drawing.Graphics(v=vs.110).aspx
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.