DS-chapter1

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

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

Textbooks Data Structure and Algorithm Analysis in C Mark Allen Weiss D , D

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

View Full Document
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]
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.

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

View Full Document
§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

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: 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
Ask a homework question - tutors are online