Guide · Algorithm examples
Algorithm Examples – a Guide to the Tasks
Tasks in which it is not enough to just "write a program" – you have to come up with a good method: mathematical algorithms, speeding up a program with a formula, recursion, generating combinatorial objects and search with going back (backtracking).
Before these tasks you should confidently solve the tasks from the basic examples – especially loops, arrays and functions.
- Grades 7–8 and secondary school
- C++
- Preparation for the district and national competition
Some lessons linked below are available only in Serbian for now. They are marked (SR).
1 Mathematical algorithms and complexity
GCD and LCM, prime numbers, factorization and how to replace a slow loop with a formula.
2 Recursion
A function that calls itself: the power, the Fibonacci sequence, binary notation, the inverse matrix.
3 Combinatorics and backtracking
How to systematically list all possibilities and how to discard those that do not lead to a solution.
4 Lessons for these tasks
Theory worth reading before or while solving.
Algorithms – guide
All lessons on algorithms in one place.
Open lesson →Replacing iteration with a formula (SR)
The complexity of an algorithm through examples.
Open lesson →Recursive algorithms
How recursion works and when to use it.
Open lesson →Fast exponentiation
A power in log n steps.
Open lesson →Recursion and dynamic programming
The next step after recursion.
Open lesson →5 Next
Competition tasks by level.
Suggested order
Useful external resources
- Petlja – the "Advanced algorithms" collections and competition tasks with automatic checking (in Serbian)
- CSES Problem Set – classic algorithmic tasks, the Introductory and Complete Search sections
- VisuAlgo – animations of algorithms: recursion, sorting, searching
