Algorithms Fundamentals
Algorithms are step-by-step procedures for solving computational problems. This topic covers how to analyze their efficiency, understand common strategies like sorting, searching, divide-and-conquer, and dynamic programming, and choose the right approach for a given problem based on time and space constraints.
itComputer fundamentals | OpenSkills.info
Course pathWalk it in order
Look it upDip in anytime
Go furtherLeaves this page
Don't Panic
Don't Panic — Algorithms Fundamentals
You will almost certainly never write a sorting algorithm. That is not a reason to skip the subject; it is the reason the subject looks the way it does.
The paying skill here is recognition rather than implementation. Sorting routines get written by the people who maintain standard libraries and by almost nobody else; the everyday work is noticing that a problem is an old problem in unfamiliar words — this scheduling mess is a matching problem, this deduplication is a union-find, this "best combination of things" is a knapsack and so has no fast exact answer.
An algorithm is a recipe precise enough for a machine to follow and finish: fixed steps that turn an input into the result somebody wanted. Note what the definition leaves out — the code. Sorting cards, routing a van and ranking search results all sit inside it.
What eventually gets typed in Python is one rendering of something that exists independently of Python — which is why pseudocode exists, so people can argue about the method without arguing about semicolons.
Two questions come before speed, and both get skipped. Will it be right on everything the specification allows through, and is it guaranteed to finish? A handful of passing tests answers neither. The tool for the first is a loop invariant: something true when a pass begins, still true when it ends, and strong enough at the exit to hand you the answer.
Cost is described as a growth shape rather than a duration — linear, linearithmic, quadratic. Big-O notation is the shorthand for those shapes, and it says how the work grows as the input grows, not how many seconds anything takes.
Underneath sits a pattern worth carrying: binary search beats scanning a list item by item only because it demands more of its input, namely that the list already be sorted. Buying speed with structure recurs across the whole field and is never free, because something upstream must maintain the structure.
Nearly everything you meet is one of a few strategies. Brute force: correct, slow, a respectable baseline. Divide and conquer: split, recurse, combine. Greedy: take the best local choice, then prove that rule actually solves the problem, because for many problems it does not.
Dynamic programming: solve each repeated subproblem once and reuse the answer. Backtracking: choose, discover the choice was wrong, return to that decision, choose otherwise. Recursion is not on the list — it is the mechanism several of them run on.
Here is the part that catches people out. The asymptotics are often the wrong guide at the sizes real programs handle. Constants and memory locality dominate below a few thousand elements, which is why no serious library ships a textbook sort: CPython's Timsort handles any array under 64 elements with a plain insertion sort, on the stated reasoning that it is hard to beat once you count the overhead of trying something cleverer.
Two operational notes. Quadratic behaviour enters real code in one shape — a loop over a collection whose length somebody else decides, containing a lookup nobody measured — so hunt the nesting and ask who controls the outer length.
And where input is attacker-controlled, typical-case speed becomes an attack surface, because the worst case is now something an adversary can simply request.
The paradigms sit side by side in the Slides, the fastest way to see how few of them there are, and the growth shapes are tabulated on the Cheatsheet. Field Notes covers how this surfaces in code already running.
Where this skill leads
Relevant careers
See how this topic contributes to broader role-level skill maps.
Sources
- https://xlinux.nist.gov/dads/terms.html
Supports
- NIST DADS is a dictionary of algorithms, techniques, data structures, problems, and related definitions
- Related concepts can be followed through its term indexes and cross-references
- https://xlinux.nist.gov/dads/HTML/algorithm.html
Supports
- An algorithm is a computable set of steps that achieves a desired result
- https://opendsa.cs.vt.edu/ODSA/Books/CS5020/html/AnalPrelim.html
Supports
- A problem maps inputs to outputs, an algorithm supplies a method, and a program implements an algorithm in a programming language
- Algorithms require correctness, concrete and unambiguous steps, a finite description, and termination
- English and pseudocode can describe algorithms with iteration
- Different algorithms can suit different input classes or resource constraints
- https://ocw.mit.edu/courses/6-006-introduction-to-algorithms-spring-2020/477c78e0af2df61fa205bcc6cb613ceb_MIT6_006S20_lec1.pdf
Supports
- An algorithm solves a problem when it returns a correct output for every problem input
- Correctness for repeated computation can be argued with induction
- Efficiency can be analyzed with machine-independent operation counts and asymptotic notation
- Introductory algorithm design includes brute force, divide and conquer, dynamic programming, and greedy methods
- https://www.ocw.mit.edu/courses/6-046j-design-and-analysis-of-algorithms-spring-2015/pages/syllabus/
Supports
- Correctness can be argued with inductive proofs and invariants
- Intermediate study covers divide and conquer, dynamic programming, greedy algorithms, graph algorithms, randomization, amortized analysis, and approximation
- https://ocw.mit.edu/courses/6-046j-design-and-analysis-of-algorithms-spring-2012/b1e5ac3c8f7d60db9b8d5b66c40bc55e_MIT6_046JS12_Notes.pdf
Supports
- A loop invariant states conditions that hold at initialization, remain true through each pass, and hold at termination
- A loop-invariant proof uses initialization, maintenance, and termination reasoning
- https://xlinux.nist.gov/dads/HTML/bigOnotation.html
Supports
- Big-O notation is an asymptotic upper bound
- The formal bound uses fixed positive constants beyond a sufficiently large input size
- Execution measures can include time, memory, comparisons, moves, disk access, or other model-specific operations
- https://xlinux.nist.gov/dads/HTML/linearSearch.html
Supports
- Linear search checks array or list items one at a time
- Its average running time is theta of n divided by two when the item is found
- https://xlinux.nist.gov/dads/HTML/binarySearch.html
Supports
- Binary search requires sorted input and repeatedly halves the search interval
- Binary search has logarithmic running time on a sorted array
- https://xlinux.nist.gov/dads/HTML/insertionSort.html
Supports
- Insertion sort inserts each next item among items already placed
- Its running time is quadratic because of item moves
- It can be implemented in place
- https://algs4.cs.princeton.edu/21elementary/
Supports
- Insertion sort moves larger items to make space for the current item
- Its exchanges correspond to inversions, so partially sorted inputs require less work
- https://xlinux.nist.gov/dads/HTML/mergesort.html
Supports
- Merge sort splits items into two groups, recursively sorts them, and merges the results
- Merge sort runs in theta of n log n time
- https://algs4.cs.princeton.edu/22mergesort/
Supports
- Standard array mergesort uses extra space proportional to the input size
- Mergesort guarantees time proportional to n log n regardless of input order
- Insertion sort can handle small subarrays in a tuned mergesort implementation
- https://xlinux.nist.gov/dads/HTML/quicksort.html
Supports
- Quicksort partitions around a pivot and recursively sorts the partitions
- Its worst case is quadratic and its typical running time is n log n
- Tuned quicksort implementations can perform well in practice
- https://algs4.cs.princeton.edu/23quicksort/
Supports
- Quicksort is an in-place divide-and-conquer sorting method
- Pivot selection and partitioning details affect correctness and performance
- Average and worst-case comparison counts differ materially
- https://xlinux.nist.gov/dads/HTML/bruteforce.html
Supports
- Brute force often tries every one of a wide range of possible solutions
- https://xlinux.nist.gov/dads/HTML/divideAndConquer.html
Supports
- Divide and conquer solves small instances directly or splits larger instances, solves them recursively, and combines their results
- Merge sort, quicksort, and binary search use divide and conquer
- https://xlinux.nist.gov/dads/HTML/greedyalgo.html
Supports
- A greedy algorithm takes the best immediate or local choice
- Greedy choices yield global optima for some problems and suboptimal results for others
- https://xlinux.nist.gov/dads/HTML/dynamicprog.html
Supports
- Dynamic programming caches subproblem solutions instead of recomputing them
- https://opendsa.cs.vt.edu/OpenDSA/Books/Everything/html/DynamicProgramming.html
Supports
- Dynamic programming removes repeated work when recursive subproblems recur
- Memoization and tabulation are two ways to store subproblem results
- https://xlinux.nist.gov/dads/HTML/backtrack.html
Supports
- Backtracking tries choices and returns to a choice point after a failed choice
- It performs a depth-first search of a tree of partial solutions
- https://xlinux.nist.gov/dads/HTML/recursion.html
Supports
- Recursion calls a function on part of the same task
- A recursive solution has base and recursive cases
- https://ocw.mit.edu/courses/6-006-introduction-to-algorithms-spring-2020/
Supports
- The course covers mathematical modeling, algorithms, data structures, performance measures, and analysis
- The course provides lecture notes, videos, practice problems, assignments, quizzes, and solutions
- https://algs4.cs.princeton.edu/home/
Supports
- The booksite covers fundamentals, sorting, searching, graphs, strings, and broader contexts
- It provides excerpts, code, exercises, lectures, and programming assignments
- https://opendsa.cs.vt.edu/OpenDSA/Books/Catalog/html/index.html
Supports
- The catalog contains material on mathematical foundations, algorithm analysis, recursion, sorting, graphs, searching, and dynamic programming
- https://www.ocw.mit.edu/courses/6-046j-design-and-analysis-of-algorithms-spring-2015/
Supports
- The intermediate course covers divide and conquer, randomization, dynamic programming, greedy algorithms, complexity, and cryptography
- It provides lecture notes, videos, recitations, assignments, and exams
- https://leetcode.com/
Supports
- LeetCode provides coding problems used for algorithm implementation practice.
- https://www.hackerrank.com/skills-directory/problem_solving_basic
Supports
- HackerRank Problem Solving covers basic data structures and algorithms, including sorting and searching.
- https://www.codewars.com/
Supports
- Codewars provides code kata, browser-based test feedback, and programming practice across many languages.
- https://codesignal.com/technical-assessments/
Supports
- CodeSignal technical assessments evaluate hands-on coding in an integrated development environment and include general programming and algorithms.
- https://www.codility.com/
Supports
- Codility provides technical assessments with automated analysis of code quality, maintainability, and complexity.
- https://doi.org/10.1090/S0002-9939-1956-0078686-7
Supports
- Kruskal published On the shortest spanning subtree of a graph and the traveling salesman problem in 1956.
- https://doi.org/10.1287/mnsc.3.3.270
Supports
- Bellman published On a Dynamic Programming Approach to the Caterer Problem—I in 1957 and used the functional equation technique of dynamic programming.
- https://doi.org/10.1007/BF01386390
Supports
- Dijkstra published A note on two problems in connexion with graphs in December 1959.
- https://doi.org/10.1093/comjnl/5.1.10
Supports
- Hoare published Quicksort in The Computer Journal in 1962.
- https://cs.stanford.edu/~knuth/taocp.html
Supports
- The first edition of Volume 1 of The Art of Computer Programming appeared in 1968.
- https://doi.org/10.1145/800157.805047
Supports
- Cook published The complexity of theorem-proving procedures in May 1971 and defined reducibility and polynomial degrees of difficulty.
- https://doi.org/10.1145/321879.321884
Supports
- Tarjan published Efficiency of a Good But Not Linear Set Union Algorithm in 1975.
- https://doi.org/10.1007/BF02579150
Supports
- Karmarkar published a new polynomial-time algorithm for linear programming in December 1984.
- https://mitpress.mit.edu/9780262031417/introduction-to-algorithms/
Supports
- The first edition of Introduction to Algorithms by Cormen, Leiserson, and Rivest was published by MIT Press in June 1990.
