{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Tutorial_12_v02-for-viewing-and-printing

# Tutorial_12_v02-for-viewing-and-printing - CC2203 Data...

This preview shows pages 1–2. Sign up to view the full content.

CC2203 Data Structures and Algorithms Sem 2, 2009-2010 Tutorial 12 Instruction In this tutorial, you are required to submit your tutorial work answers for exercise to me. Tutorial work will not be graded unless your coursework fails (coursework below D grade). If one’s coursework fails, that tutorial work will be graded to see if condone pass should be issued or not. Exercise 1 Given the following Java code: public class MaxHeap { int[] mheap; // array for complete binary tree int size; // number of elements in max heap public MaxHeap(int[] mheap, int size) { this.mheap = mheap; this.size = 0; } public void heapify(int[] mheap, int currentNode, int size) { int last = mheap[currentNode]; int child = currentNode * 2 + 1; // set left child while (child < size) { if (child + 1 < size && mheap[child] < mheap[child + 1]) child++; if (last >= mheap[child]) break; mheap[currentNode] = mheap[child]; // move child up currentNode = child; // move down a level child = currentNode * 2 + 1; // set left child } mheap[currentNode] = last; } public int deleteMax(int[] mheap, int size) { // code to be completed }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 3

Tutorial_12_v02-for-viewing-and-printing - CC2203 Data...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online