Tutorial_6-for-viewing-printing

# Tutorial_6-for-viewing-printing - int[] e = {5, 4, 3, 11,...

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

CC2203 Data Structures and Algorithms Sem 2, 2009-2010 Page 1 of 2 Tutorial 6 Instruction In this tutorial, you are required to submit your tutorial work answer(s) for the exercises 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 AnArray { public void computeSum(int[] item, int n) { int i, j, sum; for (i = 0; i < n; i++) { sum = item[0]; for (j = 1; j <= i; j++) sum += item[j]; System.out.println("Sum for array " + i + " is " + sum); } } } public class AnArrayTest { public static void main(String [] args) {

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.

Unformatted text preview: int[] e = {5, 4, 3, 11, 9}; AnArray ArrayObject = new AnArray(); ArrayObject.computeSum(e, e.length); } } (a) What is the function of the method computeSum() ? (b) Compute the time complexity in big-O notation of the step counts for the statement: sum += item[j] ; in terms of the variable n in the method computeSum() . (c) Show the output of executing java AnArrayTest . CC2203 Data Structures and Algorithms Sem 2, 2009-2010 Page 2 of 2 Exercise 2 Show the steps of obtaining the big-O notation in customary way for EACH of the following step counts (a) ( ) ( ) ( ) 109 lg lg 11 lg 18 4 3 3 + + + a ab a a b a b a (b) ( ) n n n log 7 19 31 2 5 . 2 + +...
View Full 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 / 2

Tutorial_6-for-viewing-printing - int[] e = {5, 4, 3, 11,...

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

View Full Document
Ask a homework question - tutors are online