DocsHub

Data Structures & Algorithms

A complete guide to DSA — from arrays and linked lists to trees, graphs, sorting, and dynamic programming.

Data Structures & Algorithms

Data structures and algorithms are the foundation of computer science. Every program you write uses them — whether you realize it or not. Understanding them makes you a better programmer in any language, helps you write faster code, and is essential for technical interviews.

This section is language-agnostic. The concepts apply everywhere. All code examples are written in Python.


What is a data structure?

A data structure is a way of organizing and storing data so it can be accessed and modified efficiently. Different structures are designed for different kinds of problems.

Choosing the wrong data structure can turn a fast program into a slow one. Choosing the right one can make an impossible problem trivial.


What is an algorithm?

An algorithm is a step-by-step process for solving a problem. The same problem can be solved by many different algorithms — with dramatically different speeds and memory usage.


How to measure performance — Big O

Before diving in, one concept appears everywhere: Big O notation. It describes how the performance of an algorithm scales as the input grows.

NotationNameExample
O(1)ConstantAccess array by index
O(log n)LogarithmicBinary search
O(n)LinearLoop through array
O(n log n)LinearithmicMerge sort
O(n²)QuadraticNested loops
O(2ⁿ)ExponentialRecursive Fibonacci

A program that takes O(1) time for 1 element still takes O(1) time for 1,000,000 elements. A program that takes O(n²) time for 10 elements takes 100x longer for 100 elements.


What is covered


How to use this section

Each topic starts with an introduction — what it is, a real-world analogy, and a visual. Then individual files cover specific techniques and patterns with animated walkthroughs showing exactly how the algorithm runs step by step.

Do not rush. Spend time on arrays and recursion before moving to trees and dynamic programming. The later topics build on the earlier ones.

On this page