Lect05 Algorithm PDF
Lect05 Algorithm PDF
Can you think of a day in your life which goes without problem solving?
Can you think of a day in your life which goes without problem solving?
Can you think of a day in your life which goes without problem solving?
Can you think of a day in your life which goes without problem solving?
Can you think of a day in your life which goes without problem solving?
Can you think of a day in your life which goes without problem solving?
Algorithm: FindLargest
Input: A list of positive integers
Start
1: Set Largest to 0
2: while (more integers)
2.1: FindLarger
End while
3: Return Largest
End
Subalgorithm: FindLarger
Algorithm: FindLargest Input: Largest and current
Input: A list of positive integers integer
Start Start
1: Set Largest to 0 1: if (the integer is greater than
2: while (more integers) Largest)
2.1: FindLarger then
End while 1.1: Set Largest to the value of
the integer
3: Return Largest
End if
End
End
Factorial
Input: A positive integer num
Factorial
Input: A positive integer num
Start
Factorial
Input: A positive integer num
Start
1: Set FactN to 1
Factorial
Input: A positive integer num
Start
1: Set FactN to 1
2: Set i to 1
Factorial
Input: A positive integer num
Start
1: Set FactN to 1
2: Set i to 1
3: while (i is less than or equal to num)
3.1: Set FactN to FactN × i
3.2: Increment i
End while
Factorial
Input: A positive integer num
Start
1: Set FactN to 1
2: Set i to 1
3: while (i is less than or equal to num)
3.1: Set FactN to FactN × i
3.2: Increment i
End while
4: Return FactN
End
Factorial
Input: A positive integer num
Factorial
Input: A positive integer num
Start
Factorial
Input: A positive integer num
Start
1: if (num is equal to 0)
then
Factorial
Input: A positive integer num
Start
1: if (num is equal to 0)
then
1.1: return 1
Factorial
Input: A positive integer num
Start
1: if (num is equal to 0)
then
1.1: return 1
else
Factorial
Input: A positive integer num
Start
1: if (num is equal to 0)
then
1.1: return 1
else
1.2: return num × Factorial(num − 1)
End if
Factorial
Input: A positive integer num
Start
1: if (num is equal to 0)
then
1.1: return 1
else
1.2: return num × Factorial(num − 1)
End if
End
Thank You