DS-chapter1 - factorial int n if n> 0 return n factorial...

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

View Full Document Right Arrow Icon
Textbooks Data Structure and Algorithm Analysis in C Mark Allen Weiss D , D
Background image of page 1

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

View Full DocumentRight Arrow Icon
Work Distribution Homeworks = 10% about10 Tests(attend class)= 10% about9 Project(3)= 25% >=23.5 Final exam = 55% need 49.5 to full grade Bonus >=3 90/100==49.5/55; [email protected] project D : ftp://ds_public:[email protected]
Background image of page 2
CHAPTER 1 INTRODUCTION §1 Mathematics Review Exponents : X N Logarithms : log A B Series : Modular Arithmetic : A mod B Proofs : by Induction by Contradiction by Counterexample = 0 ) ( i i f Self- study How to estimate the running time of a program for large inputs How to compare the running times of two programs without actually coding them.
Background image of page 3

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

View Full DocumentRight Arrow Icon
§2 Recursion e Example e Compute factorials: n ! = n ( n - 1) 2 1, 0! = 1. int factorial ( int n ) { int i, result; result =1; if ( n > 0 ) { for ( i = 1; i <= n; i++ ) result = result * i ; } /* end if */ return result; } int
Background image of page 4
Background image of page 5

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

View Full DocumentRight Arrow Icon
Background image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: factorial ( int n ) { if ( n > 0 ) return n * factorial ( n -1 ); else return 1; } Any iteration can be written recursively, by defining an object in terms of a simple case of itself. Recursion Rules of Recursion: Base cases : You must always have some base cases, which can be solved without recursion. Making progress : For the cases that are to be solved recursively, the recursive call must always be to a case that makes progress toward a base case . Design rule : Assume that all the recursive calls work . Compound interest rule : Never duplicate work by solving the same instance of a problem in separate recursive calls. pay attention to : have some knowledge of C ( C++ ) Programming: including such topics as pointers e recursion and file operation....
View Full Document

This note was uploaded on 02/16/2011 for the course CS 135 taught by Professor Yuechen during the Fall '08 term at Zhejiang University.

Page1 / 6

DS-chapter1 - factorial int n if n> 0 return n factorial...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online