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
Intro
Algorithms Fundamentals
An algorithm is a computable set of steps that produces a desired result. The definition covers sorting cards, finding a route, and ranking search results. The same design ideas appear across many different problems. You split a problem, choose greedily, cache repeated work, or search a tree of choices.
This course gives you that vocabulary. It is not a data structures course. Arrays, lists, trees, and hash tables appear only as containers that algorithms operate on. It is not a formal complexity-analysis course either. Big-O notation appears as vocabulary, while a dedicated course covers the mathematics. Here you learn to read a method, judge its correctness, recognize its design paradigm, and compare alternatives.
Reading pseudocode
Pseudocode describes steps without committing to one programming language. It uses familiar ideas such as assignment, loops, conditions, and function calls. It leaves out syntax that does not affect the method.
function linear-search(list, target):
for each item at index i in list:
if item equals target:
return i
return not-found
You can translate the method into any suitable programming language. The program changes, but the algorithm does not.
Correctness and termination
An algorithm is correct when it produces the required result for every valid input. Passing a few tests does not establish that claim. Termination means the algorithm finishes for every valid input. A loop that never reaches its exit condition violates that requirement.
An invariant is a condition that remains true while a loop runs. A correctness argument can show that the invariant starts true, remains true after each step, and implies the result at termination.
You will not prove every algorithm you use. You should still ask two questions. Does it always stop? Does it produce the required output for every valid input?
Measuring cost without the math
Two correct algorithms can require very different amounts of work. Big-O notation describes an asymptotic upper bound. Saying a running time is O(g(n)) means that a constant multiple of g(n) bounds it once n is large enough. You will see O(n), O(n log n), and O(n²) as linear, linearithmic, and quadratic growth labels. A dedicated course covers their formal derivation.
Search: two strategies, two costs
Linear search checks items one at a time until it finds the target or runs out of items; on average it examines about half the list before finding a match. It works on any list, sorted or not.
Binary search requires a sorted array. It compares the target with the middle item, then keeps only the half that can contain the target. It stops when it finds the value or empties the interval. Repeated halving gives it O(log n) running time.
That trade — a precondition (sortedness) in exchange for a faster algorithm — is a pattern you will see across the whole field.
Sorting: same goal, different trade-offs
A sort arranges items into a predetermined order. Three classic sorting algorithms illustrate how differently "the same problem" can be solved.
Insertion sort takes each next item and inserts it among the items already placed. Its running time is O(n²) because an insertion can move many items. It works in place and performs well on partially sorted input.
Merge sort splits the input into halves, recursively sorts each half, and merges the results. It runs in Θ(n log n) time. A standard array implementation uses extra space proportional to the input size.
Quicksort picks a pivot, partitions the other items around it, and recursively sorts each partition. Its worst case is Θ(n²), but its typical running time is O(n log n). A tuned implementation often performs well in practice. Worst-case and typical cost can lead to different choices.
Design paradigms
Most algorithms you meet are an instance of a handful of reusable strategies.
Brute force tries every one of a wide range of possible solutions. It is usually the easiest approach to get correct and the slowest to run; treat it as a baseline and a fallback, not a first choice for large inputs.
Divide and conquer solves a problem directly when the instance is small enough to be easy, and otherwise splits it into smaller instances, solves each recursively, and combines the results into a solution for the original problem. Merge sort and binary search are both divide-and-conquer algorithms.
Greedy algorithms always take the best immediate, or local, choice available at each step. That local choice can build a globally optimal solution for some problems, and a merely acceptable one for others — the paradigm is fast and simple, but you have to verify it actually solves the problem you have, not assume it.
Dynamic programming stores solutions to repeated subproblems. Each distinct subproblem is solved once, then reused. It pays off when the same subproblems recur.
Backtracking finds a solution by trying one of several choices at each decision point; when a choice turns out to be wrong, computation backtracks to that decision point and tries a different choice. It is commonly implemented with recursion and amounts to a depth-first search through a tree of possible choices.
Recursion — a function calling itself on a smaller part of the same task — is the technique that makes divide and conquer, backtracking, and many dynamic programming implementations possible. It is not itself a design paradigm; it is the mechanism several paradigms are built on.
Where this course stops
You now have the vocabulary to read an algorithm description, judge its correctness informally, name the paradigm it follows, and reason about why one correct algorithm might still be the wrong choice for your data. Formal complexity analysis, the data structures these algorithms operate on, and graph-specific algorithms (shortest paths, traversal) are each large enough to be their own course — follow the links at the end of this course to continue in that order.
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
