Welcome to Data Structures & Algorithms

Every course on this site teaches a specific language’s syntax. This course is different — it teaches ways of organizing data and solving problems that apply across every one of them. A data structure is a way of organizing data so it can be used efficiently; an algorithm is a step-by-step procedure for solving a […]

Big O Notation: Measuring Efficiency

Big O notation describes how an algorithm’s running time (or memory use) grows as the input size grows — not the exact number of seconds, which depends on the specific computer, but the underlying pattern of growth. Common complexities, from best to worst O(1) constant — looking up a value by key in a dictionarynO(log […]

Stacks, Queues and Linked Lists

Stacks — Last In, First Out stack = []nstack.append(“Lesson 1”) # pushnstack.append(“Lesson 2”)nstack.append(“Lesson 3”)nlast = stack.pop() # “Lesson 3” — removes and returns the most recently added item A stack only ever adds or removes from one end — think of a stack of plates, where you can only take from the top. The browser’s […]

Trees and Hash Tables

Binary trees class TreeNode:n def __init__(self, value):n self.value = valuen self.left = Nonen self.right = Nonennroot = TreeNode(50)nroot.left = TreeNode(30)nroot.right = TreeNode(70) A tree organizes data hierarchically — each node can have child nodes, and a binary tree specifically allows at most two children per node. File systems, HTML’s own DOM (covered in the JavaScript […]

Searching and Sorting Algorithms

Linear search — O(n) def linear_search(items, target):n for i, item in enumerate(items):n if item == target:n return in return -1 Checks every item one at a time until it finds a match, or reaches the end. Works on any list, sorted or not, but scales poorly on large data. Binary search — O(log n) def […]

Recursion and What’s Next

A recursive function is one that calls itself, working toward a base case that stops the recursion — you already saw this in the previous lesson’s merge_sort, which calls itself on smaller and smaller halves of the list. A classic first example: factorial def factorial(n):n if n <= 1: # base case — stops the […]