Tutorial_4_read_me_first_

# Tutorial_4_read_me_first_ - Output of executing this Java...

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

CC2203 Data Structures and Algorithms Sem 2, 2009-2010 Tutorial 4 Instruction In this tutorial, you are required to submit your tutorial work answer 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 As we know from the lecture, the following is a recursive implementation of the Factorial function in Java when bound = 0 : public class YourFactorial { public int factorial(int n, int bound) { if (n < bound) return -1; else if (n == bound) return 1; else return n * factorial(--n, bound); } /** test program */ public static void main(String [] args) { // test default constructor YourFactorial a = new YourFactorial(); for (int j = -5; j <= 5; j++) { if (j < 0) System.out.println("("+ j +")! = undefined"); else System.out.println(j+"! = " + a.factorial(j, 0));

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: } } } Output of executing this Java code is: (-5)! = undefined (-4)! = undefined (-3)! = undefined (-2)! = undefined (-1)! = undefined 0! = 1 1! = 1 2! = 2 CC2203 Data Structures and Algorithms Sem 2, 2009-2010 3! = 6 4! = 24 5! = 120 The combination ( ) ( ) ( ) ( ) ( ) ( ) ( ) 1 2 3 2 1 1 2 1 ! ! ! , ⋅ ⋅ ⋅ ⋅ ⋅-⋅-⋅ +-⋅ ⋅ ⋅-⋅-⋅ =-=         = k k k k n n n n k n k n k n k n c is called “n choose k”. Write the Java method with the following signature: public double combinatorial(int n, int k) which uses the factorial method to compute ( ) k n c , . Review 1. Double-click on javaIV.zip and javaV.zip to extract the java examples demonstrated in lecture(s). Read the compile.txt in the folders for compilation steps. Study the java source codes, compile them and execute them. Try to understand how the execution results come up from the java codes....
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

Tutorial_4_read_me_first_ - Output of executing this Java...

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

View Full Document
Ask a homework question - tutors are online