Download presentation
Presentation is loading. Please wait.
Published byJeffrey Fletcher Modified over 9 years ago
1
Recursion and Combinatorial Algorithms academy.zariba.com 1
2
Lecture Content 1.Combinatorics Review 2.Recursion 3.Combinatorial Algorithms 4.Homework 2
3
3 Combinatorics Review Combinatorics is a branch of Mathematics concerning the study of finite or countable data structures. Aspects of combinatorics include counting the structures of a given kind and size, deciding when a certain criteria can be met, finding largest/smallest or optimal objects… We will revise the basic definitions of permutations, variations and combinations. Algorithms on generating the above can be met in various scenarios in game development and databases, among others.
4
4 Combinatorics Review - Permutations Imagine that you have n objects that you have to place in n different positions. The order matters. The number of permutations of an n-set is n!. The factorial function is defined as follows: n! = n*(n-1)*…*2*1, with the following condition 0! = 1. If we want to place n objects in k different positions, where k<n, the formula is slightly different. These are called k-permutations on n. The formula is: n k =n*(n-1)*…*(n-k+1)
5
5 Combinatorics Review - Permutations Imagine that you have n objects that you have to place in n different positions. The order matters. The number of permutations of an n-set is n!. The factorial function is defined as follows: n! = n*(n-1)*…*2*1, with the following condition 0! = 1. If we want to place n objects in k different positions, where k<n, the formula is slightly different. These are called k-permutations on an n-set. The formula is: n k =n*(n-1)*…*(n-k+1) There are also permutations with repetitions.
6
6 Combinatorics Review - Combinations
7
7 Recursion A recursion is when a method calls itself. It is a very powerful method for implementing combinatorial, searching, sorting algorithms (others as well). Recursion can be direct (when the method calls itself) or indirect (when methods are chained). Every recursion should have an exit condition (bottom). Otherwise you get infinite loop. We run out of memory and we get StackOverflowException. We should think of recursion when our calculation is defined recursively, i.e. with respect to a previous step.
8
8 Recursion - Factorial
9
9 Recursion – 8-bit Numbers
10
10 Recursion - Combinations
11
11 Recursion - Permutations
12
12 Recursion - Labyrinth
13
13 Homework 1.) Find the n-th Tribonacci number with recursion (find it on Google) 2.) Given a set of names { “Fuzzy”, “Wuzzy”, “Mini”, “Bugs”, “Fluffy”…} implement algorithms to find the permutations and combinations of these sets (both with and without repetitions). Hint: you can find the solutions within the demos (a total of 4 problems). 3.) Implement an algorithm for finding the SHORTEST path within a labyrinth, where you can move up, down, left, right and in all diagonals. Give the solution both with a table and with directions.
14
14 References
15
15 Zariba Academy Questions
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.