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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/18/2011 for the course COMP 3868 taught by Professor Keithchan during the Summer '97 term at Hong Kong Polytechnic University.

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 Right Arrow Icon
Ask a homework question - tutors are online