1. Home
  2. Explore
  3. Computer Science
  4. Introduction to Algorithms

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Introduction to Algorithms

Algorithms: Step-by-Step Computation in Everyday Life

What an algorithm does

An algorithm is a step-by-step computational procedure for solving a problem. It takes information as input, follows a specified process, and produces an output. The procedure is meant to be carried out mechanically: once its steps are defined, the person or computer carrying them out does not need to invent a new solution at each step.

A useful way to picture an algorithm is as a box:

input⟶algorithm⟶output\text{input} \longrightarrow \text{algorithm} \longrightarrow \text{output}input⟶algorithm⟶output

For example, an algorithm for multiplying two integers receives the integers nnn and mmm as input and returns their product, n×mn \times mn×m. This description states what the procedure is supposed to accomplish. It is a specification of the problem: it identifies the valid inputs and the required output.

A problem versus an instance

The multiplication problem describes a whole family of tasks. An instance is one particular task created by choosing actual input values. If the inputs are n=121n = 121n=121 and m=234m = 234m=234, that pair is one instance of multiplication.

The grade-school method provides an algorithm for this instance. It multiplies 121121121 by each digit of 234234234, shifts the partial products according to place value, and adds them:

121×4=484121 \times 4 = 484121×4=484 121×30=3,630121 \times 30 = 3{,}630121×30=3,630 121×200=24,200121 \times 200 = 24{,}200121×200=24,200

Adding these partial products gives:

484+3,630+24,200=28,314484 + 3{,}630 + 24{,}200 = 28{,}314484+3,630+24,200=28,314

The answer is not produced by a single mysterious act. It comes from a sequence of defined operations. That sequence is the algorithm.

An algorithm is a procedure for solving a problem; an instance is one specific case of that problem with particular inputs.

This distinction matters throughout computer science. A problem defines what needs to be solved, while an algorithm describes how to solve it.

Think About It

How is a general multiplication procedure different from the one particular calculation 121×234121 \times 234121×234?

Algorithms have a long history

Algorithms did not begin with computers. People have needed reliable procedures for calculation for thousands of years. They used calculations to measure land, work with numbers, and predict events such as eclipses, full moons, and tides. In each case, a repeatable method made it possible to reach an answer without having to invent the reasoning from scratch each time.

Different mathematical traditions developed procedures suited to the tools and number systems available to them. Chinese mathematicians used the abacus for calculation. Ancient Indian mathematicians developed the place-value number system and arithmetic procedures that made it practical to calculate with that system. Greek mathematicians developed methods such as the Euclidean algorithm for finding the greatest common divisor of two numbers and the sieve of Eratosthenes for identifying prime numbers.

These examples show an important relationship between mathematical ideas and algorithms. A number system or mathematical concept becomes much more useful when there is also a dependable procedure for working with it.

Where the word “algorithm” comes from

The word algorithm is connected to the name of the mathematician al-Khwarizmi, who came from the region of Khwarazm. His writings on arithmetic and equations were translated into Latin and studied in Western Europe. The term associated with his name eventually came to refer to systematic procedures for calculation.

The numeral system often called the Arabic numeral system has a related history: its place-value foundations originated in India and were transmitted westward through Arab scholars and traders. The name used in the West reflects the path by which the system spread, not its earliest place of origin.

Why computers changed the study of algorithms

Before computers, mathematicians developed procedures for solving equations, finding roots, and performing other calculations. Yet algorithms were often treated as less important than the mathematical theorems associated with them. A procedure might be regarded as a practical detail rather than as a significant result in its own right.

Computers changed that emphasis. They made it possible—and increasingly necessary—to carry out calculations on a much larger scale. A person might manage a modest calculation by hand, but multiplying numbers with thousands of digits or examining an enormous number for primality calls for automated computation. At that scale, a method must not only work; it must also be practical to run.

This created a need to study algorithms as a subject in their own right. A computer can follow a procedure quickly, but a poorly chosen procedure may still take too long or require too much work. As a result, computer scientists study both how algorithms solve problems and how efficiently they can do so.

Algorithms are abstract recipes for computation, but they are designed with implementation in mind. They sit at the intersection of mathematics and computer science: mathematical reasoning helps shape the procedures, while the goal is to make those procedures usable by computers.

Defining computation

In the 1930s, Alan Turing proposed a formal model of computation now called a Turing machine. The model helped make the idea of a computational procedure precise: instead of relying only on an informal sense of what a computer can do, computation could be studied through a mathematical model with clearly defined operations.

The Church–Turing thesis, associated with Alonzo Church and Alan Turing, proposes that any computation that can be carried out by a physically realizable computer can also be carried out by a Turing machine. The thesis concerns what is computable in principle, not how quickly a particular machine performs the computation. It provides a foundation for asking which problems can be solved by computation and what counts as a valid computational procedure.

The broader study of algorithms was also shaped by mathematicians and computer scientists who collected, analyzed, and compared procedures systematically. Donald Knuth, for example, helped establish algorithms as a serious and detailed area of computer science. Such work made it easier for researchers and practitioners to understand what methods were known and how different approaches compared.

Think About It

Why does a computer make efficiency important even when an algorithm is mathematically correct?

Algorithms as a technology

Algorithms are not confined to programming. They operate behind many services people use in daily life. Often, a useful result depends on several algorithms working together: one may organize information, another may search it, and another may prepare the result for delivery.

Search engines and location-based results

When someone searches for nearby Greek restaurants, the search engine has to do more than recognize the words in the query. It may use the approximate location of the person searching, identify relevant restaurants, and retrieve information such as reviews.

A search engine can prepare an index in advance to make these lookups fast. The index organizes information so that a location or search term can lead to a relevant set of results. For example, a location can be associated with nearby places, a restaurant category can be associated with matching businesses, and a business can be associated with its reviews.

When a query arrives, the system can use the person’s approximate location and the search terms to find and combine relevant information. The index avoids having to inspect every piece of information from scratch. The search therefore depends not on one algorithm alone, but on multiple procedures working together quickly enough to return results in a useful time.

Route finding and traffic

A navigation service that finds a route between addresses must first connect those addresses to locations on a map. It then uses a shortest-path algorithm to find a route through the available roads. In practice, the service may provide alternative routes as well.

The route with the shortest distance is not necessarily the one that takes the least time. Traffic conditions can change how long different routes take, so the service can combine route information with current traffic data to estimate travel time. Route finding therefore illustrates how algorithms can use several kinds of information to produce a result that better serves a practical goal.

Airports and transportation logistics

Airports have limited resources: there are only so many runways, taxiways, and gates, while many aircraft need to use them. Assigning aircraft to gates is an assignment problem. Deciding when aircraft can use runways or taxiways is a scheduling problem. Similar scheduling decisions arise when planes are waiting to take off.

Airlines also need to assign available aircraft to the routes they must operate. If an aircraft is delayed or develops a technical problem, another aircraft may need to be assigned. These decisions are examples of vehicle assignment and routing problems. Baggage handling adds another layer of logistics: bags must be directed so that they reach the aircraft carrying their owners.

Some of these decisions may involve human judgment, but algorithms can help organize choices and manage complicated constraints. Their role is to help coordinate limited resources across many connected tasks.

Package delivery and the traveling salesperson problem

A delivery company has to move packages between locations efficiently. A package may need to be assigned to appropriate transportation to get from its starting point to its destination. At the local level, a delivery truck may have many stops to make and then need to return to its depot.

Finding an efficient order for visiting a set of locations and returning to the start is a version of the traveling salesperson problem, often abbreviated as TSP. The problem is difficult because the number of possible visit orders can grow very quickly as the number of locations increases. An improvement in the route can save time and resources, so even small efficiency gains may have a substantial practical effect.

Matching people with limited opportunities

Algorithms can also help match people with opportunities when both sides have preferences. In medical residency matching, students seek training positions and hospitals seek trainees. A useful matching should respect preferences while avoiding unstable outcomes.

A matching is stable when there is no unmatched student and position that would both prefer to be paired with each other rather than remain with their assigned matches. The stable-matching idea has applications beyond residency placement, including matching kidney donors with patients. In such settings, the algorithm helps coordinate preferences and limited opportunities in a way that can reduce mismatches and wasted resources.

Think About It

What makes airport scheduling, package delivery, and residency matching different applications of algorithms, even though all involve organizing choices?

Comprehensive review

An algorithm is a defined, step-by-step procedure that takes input and produces output. The problem specification describes what must be accomplished, while an instance supplies particular values to work with. Grade-school multiplication illustrates how a general procedure can be applied mechanically to a specific input.

Algorithms have deep historical roots in calculation, from arithmetic procedures and place-value systems to methods for finding greatest common divisors and identifying primes. The rise of computers made algorithms especially important because automated calculation could operate at scales that are impractical for people to handle by hand. It also made efficiency a central concern.

Turing’s model of computation helped formalize what it means for a procedure to compute, and the Church–Turing thesis describes the computational power of physically realizable computers in terms of that model. Today, algorithms support search, navigation, scheduling, transportation, delivery, and matching. Across all these settings, their shared purpose is to turn a clearly stated task into a repeatable procedure that produces useful results.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent