Cambridge International A Level Computer Science

Published  . 0 views
↓ Download
Cambridge International A Level Computer Science
1 / 1
Cambridge International A Level Computer Science - slide 1 of 30 Cambridge International A Level Computer Science - slide 2 of 30 Cambridge International A Level Computer Science - slide 3 of 30 Cambridge International A Level Computer Science - slide 4 of 30 Cambridge International A Level Computer Science - slide 5 of 30 Cambridge International A Level Computer Science - slide 6 of 30 Cambridge International A Level Computer Science - slide 7 of 30 Cambridge International A Level Computer Science - slide 8 of 30 Cambridge International A Level Computer Science - slide 9 of 30 Cambridge International A Level Computer Science - slide 10 of 30 Cambridge International A Level Computer Science - slide 11 of 30 Cambridge International A Level Computer Science - slide 12 of 30 Cambridge International A Level Computer Science - slide 13 of 30 Cambridge International A Level Computer Science - slide 14 of 30 Cambridge International A Level Computer Science - slide 15 of 30 Cambridge International A Level Computer Science - slide 16 of 30 Cambridge International A Level Computer Science - slide 17 of 30 Cambridge International A Level Computer Science - slide 18 of 30 Cambridge International A Level Computer Science - slide 19 of 30 Cambridge International A Level Computer Science - slide 20 of 30 Cambridge International A Level Computer Science - slide 21 of 30 Cambridge International A Level Computer Science - slide 22 of 30 Cambridge International A Level Computer Science - slide 23 of 30 Cambridge International A Level Computer Science - slide 24 of 30 Cambridge International A Level Computer Science - slide 25 of 30 Cambridge International A Level Computer Science - slide 26 of 30 Cambridge International A Level Computer Science - slide 27 of 30 Cambridge International A Level Computer Science - slide 28 of 30 Cambridge International A Level Computer Science - slide 29 of 30 Cambridge International A Level Computer Science - slide 30 of 30
Description: Cambridge International A Level Computer Science (9618) Revision Notes This pack is intended for students to who are taking CIE A Level in Computer Science, either in preparation for their A Level exam, or more likely alongside year 2 of

Related Topics

Download Presentation

"Cambridge International A Level Computer Science" is the property of its rightful owner. Permission is granted to download and print the materials on this website for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.

Presentation Transcript

slide1. Cambridge International A Level Computer Science (9618) – Revision Notes This pack is intended for students to who are taking CIE A Level in Computer Science, either in preparation for their A Level exam, or more likely alongside year 2 of the course to improve fluency, recall and pace on AS & A topics. It could be used as lesson starters, or supplied to students for independent use. Recursion<br>
slide2. Recursion AS & A Level Computer Science 9618 Chapter 24<br>
slide3. Chapter
Outline The Recursive Approach to Problem Solving 24.1 Building and Visualising Recursive Functions 24.2 Executing Recursive Calls in Programs Evaluating the Pros and Cons of Recursion 24.4 24.3<br>
slide4. 24.1 The Recursive Approach to Problem Solving What is a recursive routine? A recursive routine is a function or algorithm that calls itself during its execution, either directly or indirectly, to solve a smaller instance of the same problem. Eg. The factorial problem 4! = 4 x 3 x 2 x 1<br>
slide5. What is a recursive routine? A recursive routine is a function or algorithm that calls itself during its execution, either directly or indirectly, to solve a smaller instance of the same problem. Eg. The factorial problem 4! = 4 x 3 x 2 x 1 4! = 4 x 3! = 24.1 The Recursive Approach to Problem Solving<br>
slide6. What is a recursive routine? A recursive routine is a function or algorithm that calls itself during its execution, either directly or indirectly, to solve a smaller instance of the same problem. Eg. The factorial problem 4! = 4 x 3! 3! = 3 x 2! 2! = 2 x 1! 1! = 1 x 0! 0! = 1 24.1 The Recursive Approach to Problem Solving<br>
slide7. What is a recursive routine? A recursive routine is a function or algorithm that calls itself during its execution, either directly or indirectly, to solve a smaller instance of the same problem. Eg. The factorial problem 4! = 4 x 3! 3! = 3 x 2! 2! = 2 x 1! 1! = 1 x 0! 0! = 1 Base Case n! = n x (n-1)! General Case 24.1 The Recursive Approach to Problem Solving<br>
slide8. Subtopic 1 24.2 Building and Visualising Recursive Functions Python code for calculating factorial (Recursive method) def factorial(n):
if n == 0 or 1:
return 1
else:
return n * factorial(n - 1)

# Example usage:
number = 5
result = factorial(number)
print(f"The factorial of {number} is: {result}") factorial (5)<br>
slide9. Subtopic 1 Python code for calculating factorial (Recursive method) def factorial(n):
if n == 0 or 1:
return 1
else:
return n * factorial(n - 1)

# Example usage:
number = 5
result = factorial(number)
print(f"The factorial of {number} is: {result}") factorial (5) 5*factorial (4) call 24.2 Building and Visualising Recursive Functions<br>
slide10. Subtopic 1 Python code for calculating factorial (Recursive method) def factorial(n):
if n == 0 or 1:
return 1
else:
return n * factorial(n - 1)

# Example usage:
number = 5
result = factorial(number)
print(f"The factorial of {number} is: {result}") factorial (5) 5*factorial (4) 4*factorial (3) call call 24.2 Building and Visualising Recursive Functions<br>
slide11. Subtopic 1 Python code for calculating factorial (Recursive method) def factorial(n):
if n == 0 or 1:
return 1
else:
return n * factorial(n - 1)

# Example usage:
number = 5
result = factorial(number)
print(f"The factorial of {number} is: {result}") factorial (5) 5*factorial (4) 4*factorial (3) 3*factorial (2) call call call 24.2 Building and Visualising Recursive Functions<br>
slide12. Subtopic 1 Python code for calculating factorial (Recursive method) def factorial(n):
if n == 0 or 1:
return 1
else:
return n * factorial(n - 1)

# Example usage:
number = 5
result = factorial(number)
print(f"The factorial of {number} is: {result}") factorial (5) 5*factorial (4) 4*factorial (3) 3*factorial (2) 2*factorial (1) call call call call 24.2 Building and Visualising Recursive Functions<br>
slide13. Subtopic 1 Python code for calculating factorial (Recursive method) def factorial(n):
if n == 0 or 1:
return 1
else:
return n * factorial(n - 1)

# Example usage:
number = 5
result = factorial(number)
print(f"The factorial of {number} is: {result}") factorial (5) 5*factorial (4) 4*factorial (3) 3*factorial (2) 2*factorial (1) factorial (1) call call call call call 24.2 Building and Visualising Recursive Functions<br>
slide14. Subtopic 1 Python code for calculating factorial (Recursive method) def factorial(n):
if n == 0 or 1:
return 1
else:
return n * factorial(n - 1)

# Example usage:
number = 5
result = factorial(number)
print(f"The factorial of {number} is: {result}") factorial (5) 5*factorial (4) 4*factorial (3) 3*factorial (2) 2*factorial (1) factorial (1) call call call call call return 1 24.2 Building and Visualising Recursive Functions<br>
slide15. Subtopic 1 Python code for calculating factorial (Recursive method) def factorial(n):
if n == 0 or 1:
return 1
else:
return n * factorial(n - 1)

# Example usage:
number = 5
result = factorial(number)
print(f"The factorial of {number} is: {result}") factorial (5) 5*factorial (4) 4*factorial (3) 3*factorial (2) 2*factorial (1) factorial (1) call call call call call return 1 return 2x1 = 2 24.2 Building and Visualising Recursive Functions<br>
slide16. Subtopic 1 Python code for calculating factorial (Recursive method) def factorial(n):
if n == 0 or 1:
return 1
else:
return n * factorial(n - 1)

# Example usage:
number = 5
result = factorial(number)
print(f"The factorial of {number} is: {result}") factorial (5) 5*factorial (4) 4*factorial (3) 3*factorial (2) 2*factorial (1) factorial (1) call call call call call return 1 return 2x1 = 2 return 3x2 = 6 24.2 Building and Visualising Recursive Functions<br>
slide17. Subtopic 1 Python code for calculating factorial (Recursive method) def factorial(n):
if n == 0 or 1:
return 1
else:
return n * factorial(n - 1)

# Example usage:
number = 5
result = factorial(number)
print(f"The factorial of {number} is: {result}") factorial (5) 5*factorial (4) 4*factorial (3) 3*factorial (2) 2*factorial (1) factorial (1) call call call call call return 1 return 2x1 = 2 return 3x2 = 6 return 4x6 = 24 24.2 Building and Visualising Recursive Functions<br>
slide18. Subtopic 1 Python code for calculating factorial (Recursive method) def factorial(n):
if n == 0 or 1:
return 1
else:
return n * factorial(n - 1)

# Example usage:
number = 5
result = factorial(number)
print(f"The factorial of {number} is: {result}") factorial (5) 5*factorial (4) 4*factorial (3) 3*factorial (2) 2*factorial (1) factorial (1) call call call call call return 1 return 2x1 = 2 return 3x2 = 6 return 4x6 = 24 return 5 x 24 = 120 24.2 Building and Visualising Recursive Functions<br>
slide19. 24.3 Executing Recursive Calls in Programs def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)

# Example usage:
number = 3
result = factorial(number)
print(f"The factorial of {number} is: {result}") 0
1
2
3
4
567
8
9<br>
slide20. def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)

# Example usage:
number = 3
result = factorial(number)
print(f"The factorial of {number} is: {result}") 0
1
2
3
4
567
8
9 24.3 Executing Recursive Calls in Programs<br>
slide21. def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)

# Example usage:
number = 3
result = factorial(number)
print(f"The factorial of {number} is: {result}") 0
1
2
3
4
567
8
9 factorial(3) 24.3 Executing Recursive Calls in Programs<br>
slide22. def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)

# Example usage:
number = 3
result = factorial(number)
print(f"The factorial of {number} is: {result}") 0
1
2
3
4
567
8
9 Line number Current content of the local variable factorial(3) stack frame 24.3 Executing Recursive Calls in Programs<br>
slide23. def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)

# Example usage:
number = 3
result = factorial(number)
print(f"The factorial of {number} is: {result}") 0
1
2
3
4
567
8
9 factorial(2) Line number Current content of the local variable 24.3 Executing Recursive Calls in Programs<br>
slide24. def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)

# Example usage:
number = 3
result = factorial(number)
print(f"The factorial of {number} is: {result}") 0
1
2
3
4
567
8
9 factorial(2) 24.3 Executing Recursive Calls in Programs<br>
slide25. def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)

# Example usage:
number = 3
result = factorial(number)
print(f"The factorial of {number} is: {result}") 0
1
2
3
4
567
8
9 factorial(1) 24.3 Executing Recursive Calls in Programs<br>
slide26. def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)

# Example usage:
number = 3
result = factorial(number)
print(f"The factorial of {number} is: {result}") 0
1
2
3
4
567
8
9 factorial(0) - base case reached! 24.3 Executing Recursive Calls in Programs<br>
slide27. def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)

# Example usage:
number = 3
result = factorial(number)
print(f"The factorial of {number} is: {result}") 0
1
2
3
4
567
8
9 Return the value to call #3 24.3 Executing Recursive Calls in Programs<br>
slide28. def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)

# Example usage:
number = 3
result = factorial(number)
print(f"The factorial of {number} is: {result}") 0
1
2
3
4
567
8
9 Return the value to call #2 24.3 Executing Recursive Calls in Programs<br>
slide29. def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)

# Example usage:
number = 3
result = factorial(number)
print(f"The factorial of {number} is: {result}") 0
1
2
3
4
567
8
9 Return the value to call #1 24.3 Executing Recursive Calls in Programs<br>
slide30. 24.4 Evaluating the Pros and Cons of Recursion<br>