Computer Algorithms: Definition, How They Work & Examples

Understanding Algorithms: A Simple Explanation
For those not versed in mathematics or computer science, the term algorithm may seem unfamiliar. However, these processes are fundamental to the operation of virtually every technology you encounter, including the one you're currently using to view this article.
It's important to note that this explanation is geared towards accessibility. While some mathematical concepts are inherent to the topic, the aim is to present them in plain language, avoiding overly technical jargon.
What Exactly is an Algorithm?
At its core, an algorithm is a set of well-defined instructions designed to accomplish a specific task. Think of it as a recipe, but instead of ingredients and cooking steps, it involves data and operations.
These instructions are executed in a specific order, and when followed precisely, they guarantee a predictable outcome. The clarity and precision of each step are crucial for the algorithm to function correctly.
How Do Algorithms Work?
Algorithms take input, process it according to the defined instructions, and then produce output. This process can be illustrated with a simple example.
Consider an algorithm designed to find the largest number in a list. The algorithm would examine each number in the list, comparing it to the current largest number found. If a larger number is encountered, it becomes the new largest number.
Key Characteristics of Algorithms
- Finiteness: An algorithm must terminate after a finite number of steps.
- Definiteness: Each step must be clearly and unambiguously defined.
- Input: An algorithm must accept zero or more inputs.
- Output: An algorithm must produce one or more outputs.
These characteristics ensure that algorithms are reliable and predictable. Without them, the results would be inconsistent and potentially unusable.
While a complete understanding requires some mathematical background, the fundamental concept of an algorithm is surprisingly straightforward: a series of steps to solve a problem.
Image by Ian Ruotsala
Understanding Algorithms
The term 'algorithm' shares a historical root with 'algebra,' originating from the name of the 9th-century Arabic mathematician, al-Khwarizmi – a fascinating piece of linguistic history.
For those unfamiliar with programming, an algorithm represents a defined sequence of steps designed to transform input data, denoted as A, into a specific output, B.
Diverse Applications of Algorithms
Algorithms are incredibly versatile and find application across numerous fields. They are fundamental to mathematical calculations, enabling the determination of functions from data points and supporting far more complex operations.
Beyond their core role in software development, algorithms are crucial components in technologies such as file compression and data encryption.
- They facilitate the reduction of file sizes.
- They ensure secure data transmission.
Essentially, an algorithm provides a methodical approach to problem-solving, ensuring a predictable and consistent result when applied to a given set of inputs.
How Algorithms Function
The core function of an algorithm is to manipulate data. This manipulation can involve a variety of processes, from simple arithmetic operations to complex logical comparisons.
The effectiveness of an algorithm is often judged by its efficiency – how quickly and with how few resources it can achieve the desired output.
Understanding Computer Algorithms
Imagine providing directions to a friend meeting you at a supermarket. You might instruct them to "enter via the doors on the right," "walk past the seafood counter located on your left," or "know you've gone too far if you spot the dairy section." This is fundamentally how algorithms function.
A flowchart serves as a visual representation of these instructions, outlining the steps to take based on pre-defined criteria or information gathered during the process.

(Image titled "Icebreaking Routine" - credit: Trigger and Freewheel)
How Flowcharts Relate to Algorithms
Starting from a designated "START" point, one progresses along a defined path. The direction taken is determined by specific conditions, leading to a final outcome.
Flowcharts are valuable tools for visually depicting the instructions that computers execute. Algorithms, however, often employ more complex, mathematically-oriented models to achieve similar results.
Graphs
Consider a graph as a means of visually representing directional information.
This graphical representation can be defined by the relationships between its constituent points. Providing a set of instructions allows for the reconstruction of this image by another individual.
Method 1
One approach involves defining the graph as a collection of coordinate pairs, following the standard format of graph = {(x1, y1), (x2, y2), ..., (xn, yn)}.
graph = {(0,0), (3,0), (3,3), (5,5), (7,10), (8,7), (9,4), (10,1)}
Plotting each point sequentially and connecting it to the preceding one is a straightforward process. However, imagine a graph comprised of a thousand points, or numerous segments extending in various directions. Such a list would contain a substantial amount of data, and the iterative connection of each point could prove cumbersome.
Method 2
Alternatively, we can specify a starting point, the slope of the line segment leading to the next point, and indicate the subsequent point's location using the form graph={(starting point}, [m1, x1, h1], ..., [mn, xn, hn]}. Here, 'm' denotes the slope, 'x' indicates the direction of counting (along the x or y axis), and 'h' specifies the number of units to count in that direction. Remembering to plot a point after each movement is crucial.
graph = {(0,0), [0,x,3], [0,y,3], [1,x,2], [2.5,x,2], [-3,x,1], [-3,x,1], [-3,x,1]}
The resulting graph will be identical. Notice the repetition of the final three terms; this could be streamlined by introducing a repetition indicator, 'R', signifying the repetition of the preceding element. This allows us to express it as:
graph = {(0,0), [0,x,3], [0,y,3], [1,x,2], [2.5,x,2], [-3,x,1], [R=2]}
If the individual points are irrelevant and only the overall graph structure is important, we can further consolidate these sections:
graph = {(0,0), [0,x,3], [0,y,3], [1,x,2], [2.5,x,2], [-3,x,3]}
This results in a more concise representation.
Method 3
Let's explore a different approach.
y=0, 0≤x≤3
x=0, 0≤y≤3
y=x, 3≤x≤5
y=2.5x-7.5, 5≤x≤7
y=-3x+29, 7≤x≤8
y=-3x+29, 8≤x≤9
y=-3x+29, 9≤x≤10
This expresses the graph using purely algebraic terms. Again, if only the graph's form matters, the last three items can be combined.
y=0, 0≤x≤3
x=0, 0≤y≤3
y=x, 3≤x≤5
y=2.5x-7.5, 5≤x≤7
y=-3x+29, 7≤x≤10
The optimal method depends on individual strengths. Those proficient in mathematics and graphing may prefer the final option. Those skilled in navigation might favor the second. However, computers perform a wide range of tasks with consistent capabilities; therefore, algorithms are designed for optimized task completion.
A crucial consideration is that each method relies on a key or set of rules. Instructions are ineffective without understanding their application. Without knowing to plot points and connect them, the first set of coordinates is meaningless. Similarly, the second method requires understanding the variables, akin to deciphering a code. This key is an essential component of algorithms, often established through community consensus or a defined standard.
File Compression
The process of extracting a .zip file allows access to its contained data. Modern operating systems generally handle this automatically, presenting .zip files as standard folders. However, older systems, like my Windows 95 machine, required manual extraction before the files within could be viewed.
This is because the data within a .zip file isn't immediately usable in its compressed state. A useful analogy is a pull-out couch; it must be unfolded to function as a bed, increasing its size. Conversely, it can be folded up for storage or transport, minimizing its footprint.
Compression algorithms are tailored to specific file types for optimal efficiency. Different audio formats, for instance, employ unique data storage methods.
When decoded by the appropriate audio codec, these methods reconstruct a sound file closely resembling the original waveform. Further details on these distinctions can be found in our prior article, "What Are the Differences Between All Those Audio Formats?".
Lossy vs. Lossless Compression
Both lossless audio formats and .zip files share a key characteristic: they allow for complete data recovery during decompression, yielding the original data exactly.
Lossy audio codecs, however, prioritize space savings through different techniques. These include removing inaudible frequencies and simplifying waveform details.
While the difference between a compressed file like an MP3 and a CD track may be imperceptible to the human ear, a reduction in information is undeniably present in the compressed version.
Data Encryption
Algorithms play a crucial role in safeguarding data and communication channels. Rather than optimizing data for reduced storage space, they transform it into an unrecognizable format for unauthorized programs.
Even after file deletion, remnants of data can often be recovered through scanning a hard drive, as the data itself persists despite the removal of its directory entry. However, encryption alters the stored information, rendering it unintelligible.
Encrypted data typically appears random, resembling the effects of file fragmentation. Furthermore, data can be concealed by disguising it as another file type.
Utilizing File Types for Concealment
Large media files, such as image files and music files, are particularly suitable for this purpose due to their size and ability to avoid raising suspicion. This process relies on the application of complex mathematical algorithms.
These algorithms function by accepting an input and converting it into a predetermined, distinct output. For a more detailed understanding of encryption processes, refer to HTG Explains: What is Encryption and How Does It Work?
Algorithms are fundamentally mathematical instruments that serve a diverse range of applications within computer science. They establish a defined pathway from an initial point to a final destination, providing a consistent set of instructions for navigation.
Do you have further insights to share regarding algorithms? Please contribute your explanations in the comments section below.