Se ha denunciado esta presentación.
Se está descargando tu SlideShare. ×
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Cargando en…3
×

Eche un vistazo a continuación

1 de 4 Anuncio

Más Contenido Relacionado

Presentaciones para usted (19)

Anuncio

Más reciente (20)

Anuncio

Chap02alg

  1. 1. CHAPTER 2 Mathematics for Algorithms
  2. 2. Example 2.2.6 Factorial This algorithm computes the factorial of n . factorial ( n ) { i = 1 fact = 1 while ( i < n ) { i = i + 1 fact = fact * i } return fact }
  3. 3. Example 2.3.1 Finding the Maximum Value in an Array Using a While Loop This algorithm finds the largest number in the array s [1], s [2], ... , s [ n ]. Input Parameter: s Output Parameters: None array_max_ver1 ( s ) { large = s [1] i = 2 while ( i ≤ s . last ) { if ( s [ i ] > large ) // larger value found large = s [ i ] i = i + 1 } return large }
  4. 4. Example 2.4.3 example ( n ) { if ( n == 1) return for i = 1 to n x = x + 1 example( n /2) }

×