AlgoBazaAlgoBaza

Algorytmy

Interaktywne tutoriale z wizualizacjami i debuggerem krok po kroku. Kazdy algorytm zawiera animacje i wyjasnienia po polsku.

Binary Search
Podstawowy

Fast searching in a SORTED array: we look at the middle and throw out half of the elements every time. In an array of a million numbers about 20 steps are enough.

O(log n)O(1)
DebuggerWizualizacja
Linear Search
Podstawowy

The simplest way to search: we check the elements one by one, from the first, until we hit the target or run out of array. Works on any array β€” sorted or not.

O(n)O(1)
DebuggerWizualizacja
Bubble Sort
Podstawowy

Compares neighbouring elements and swaps them when they are in the wrong order. After every pass the largest element "floats" to the end β€” like a bubble.

O(n^2)O(1)
DebuggerWizualizacja
Selection Sort
Podstawowy

In every pass it selects the smallest element of the unsorted part and puts it in the next position. It makes at most n - 1 swaps.

O(n^2)O(1)
DebuggerWizualizacja
Insertion Sort
Podstawowy

Takes the numbers one by one and inserts each into its place in the already sorted part, shifting bigger numbers to the right. Very fast for almost sorted data.

O(n^2)O(1)
DebuggerWizualizacja
Counting Sort
Podstawowy

Instead of comparing numbers, it counts how many times each value appears and then writes them out in order. Lightning fast when the values come from a small range (e.g. grades 1-6).

O(n + k)O(k)
DebuggerWizualizacja
Euclidean Algorithm (GCD)
Podstawowy

The fastest way to get the GCD β€” the greatest common divisor of two numbers. Instead of checking every divisor, we replace the pair (a, b) with (b, a % b) until b is zero.

O(log min(a, b))O(1)
DebuggerWizualizacja
Prefix Sums
Podstawowy

A preprocessing technique that allows for fast calculation of range sums in an array.

O(n) budowa, O(1) zapytanieO(n)
DebuggerWizualizacja
Two Pointers
Sredni

An algorithmic technique using two pointers moving through an array to solve a problem.

O(n)O(1)
DebuggerWizualizacja
Breadth-First Search (BFS)
Sredni

A graph traversal algorithm that visits all neighbors at the current depth before moving to nodes at the next depth level.

O(V + E)O(V)
DebuggerWizualizacja
Depth-First Search (DFS)
Sredni

A graph traversal algorithm that explores as far as possible along each branch before backtracking.

O(V + E)O(V)
DebuggerWizualizacja
Cycle Detection (Directed Graph)
Sredni

Algorithm for detecting cycles in a directed graph using DFS with two sets: visited and in_path.

O(V + E)O(V)
DebuggerWizualizacja
Cycle Detection (Undirected Graph)
Sredni

Algorithm for detecting cycles in an undirected graph using DFS with a parent parameter.

O(V + E)O(V)
DebuggerWizualizacja
Topological Sort
Sredni

Topological sort arranges vertices of a directed acyclic graph (DAG) in an order such that every edge goes from an earlier vertex to a later one.

O(V+E)O(V)
DebuggerWizualizacja
Pre-order List
Sredni

The pre-order list algorithm records vertices in the order they are first discovered by DFS β€” each vertex is added to the list upon entry, BEFORE checking neighbors.

O(V+E)O(V)
DebuggerWizualizacja
In-order List
Sredni

The in-order list algorithm records binary tree vertices in the order: left subtree β†’ vertex β†’ right subtree. On a BST it produces a sorted list!

O(V)O(V)
DebuggerWizualizacja
Post-order List
Sredni

The post-order list algorithm records vertices in the order they are completed by DFS β€” each vertex is added to the list AFTER processing ALL its neighbors (at function exit).

O(V+E)O(V)
DebuggerWizualizacja
Connected Components
Sredni

Algorithm for finding connected components in an undirected graph. Uses DFS with an outer loop over all vertices β€” each unvisited vertex starts a new component, and DFS visits all vertices in that component.

O(V+E)O(V)
DebuggerWizualizacja
Bipartite Check
Sredni

The algorithm checks whether an undirected graph is bipartite β€” meaning vertices can be split into two groups so that every edge connects vertices from different groups. Uses DFS with vertex coloring.

O(V+E)O(V)
DebuggerWizualizacja
Strongly Connected Component (Naive)
Sredni

Naive algorithm for finding the Strongly Connected Component (SCC) from a single vertex. Performs forward DFS to find reachable vertices, then a separate backward DFS for each candidate. Introduction to more efficient algorithms (Kosaraju, Tarjan).

O(V Γ— (V+E))O(V+E)
DebuggerWizualizacja
SCC (Edge Flip Trick)
Zaawansowany

Finding the Strongly Connected Component (SCC) of a given vertex using the edge flip trick. Instead of checking each candidate separately (naive), we reverse all edges and run just 2 DFS searches! Complexity: O(V+E) instead of O(VΓ—(V+E)).

O(V+E)O(V+E)
Wizualizacja
Kosaraju's Algorithm (all SCCs)
Zaawansowany

Kosaraju's algorithm finds ALL strongly connected components (SCC) in a directed graph using two DFS passes. The first pass records the finish order of vertices. The second pass processes vertices in reverse finish order on the reversed graph β€” each DFS in the second pass finds exactly one SCC!

O(V+E)O(V+E)
DebuggerWizualizacja