0% found this document useful (0 votes)
7 views2 pages

Factorial Algorithms & Game Recursion

Here are five practical uses of recursion in game development: 1. World generation: Recursive algorithms can generate complex, natural-looking game worlds, like the diamond-square algorithm. 2. Fractal generation: Recursion creates fractal patterns and structures seen in game art, levels, and textures. 3. Maze generation: Recursive algorithms like recursive backtracking or divide-and-conquer generate random mazes. 4. Tree structures: Games often involve hierarchical structures like scene graphs, object hierarchies, or decision trees for AI. 5. Pathfinding: Recursive algorithms like A* and Dijkstra's algorithm find optimal paths by exploring graphs through recursion and backtracking routes.

Uploaded by

nehalbagda98
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Factorial Algorithms & Game Recursion

Here are five practical uses of recursion in game development: 1. World generation: Recursive algorithms can generate complex, natural-looking game worlds, like the diamond-square algorithm. 2. Fractal generation: Recursion creates fractal patterns and structures seen in game art, levels, and textures. 3. Maze generation: Recursive algorithms like recursive backtracking or divide-and-conquer generate random mazes. 4. Tree structures: Games often involve hierarchical structures like scene graphs, object hierarchies, or decision trees for AI. 5. Pathfinding: Recursive algorithms like A* and Dijkstra's algorithm find optimal paths by exploring graphs through recursion and backtracking routes.

Uploaded by

nehalbagda98
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Program list 8:

1) Implementation and time analysis of factorial program using iterative and recursive method.
Program:

import time
def factorial_iterative(n):
result = 1
for i in range(1, n + 1):
result *= i
return result
def factorial_recursive(n):
if n == 0:
return 1
else:
return n * factorial_recursive(n - 1)
def measure_time(func, *args):
start_time = time.time()
result = func(*args)
end_time = time.time()
execution_time = end_time - start_time
return result, execution_time
input_values = [5, 10]
for n in input_values:
print(f"Factorial of {n} (Iterative):")
result_iterative, time_iterative = measure_time(factorial_iterative, n)
print(f"Result: {result_iterative}, Execution Time: {time_iterative:.6f} seconds\n")
print(f"Factorial of {n} (Recursive):")
result_recursive, time_recursive = measure_time(factorial_recursive, n)
print(f"Result: {result_recursive}, Execution Time: {time_recursive:.6f} seconds\n")
print("-" * 50)
Output:
Factorial of 5 (Iterative):
Result: 120, Execution Time: 0.000001 seconds
Factorial of 5 (Recursive):
Result: 120, Execution Time: 0.000003 seconds

Question 1: A practical use for recursion in game development (At least 5 usage).

Here are five practical uses of recursion in game development:

1. World Generation:
Recursive algorithms can be used to generate complex and natural-looking game worlds. For
example, the diamond-square algorithm.
2. Fractal Generation:
Recursion is used to create fractal patterns and structures, which can be seen in game art,
level design, or even procedural textures.
3. Maze Generation:
Recursive algorithms like the recursive backtracking or divide-and-conquer can be used to
generate random mazes for games.
4. Tree Structures:
Game development often involves hierarchical structures, such as scene graphs, object
hierarchies, or decision trees for AI.
5. Pathfinding:
Recursive algorithms like A* and Dijkstra's algorithm can be used for pathfinding in games.
These algorithms involve exploring possible paths through a graph, which can be implemented
using recursion to backtrack and explore alternative routes until the optimal path is found.

You might also like