Algorithms

Introduction to Algorithms

Difficulty: Beginner

Two recipes can both bake the same cake, yet one calls for thirty minutes and the other for three hours. The same is true of code: a problem like sorting a list or finding the largest number in an array has many valid solutions, and the...

Learn
/
Algorithms
/

Introduction to Algorithms

0%
BEGINNER
Complexity varies

Introduction to Algorithms

Two recipes can both bake the same cake, yet one calls for thirty minutes and the other for three hours. The same is true of code: a problem like sorting a list or finding the largest number in an array has many valid solutions, and the choice between them is exactly what an algorithm captures.

This lesson defines what an algorithm actually is, naming the five characteristics every algorithm shares (input, output, definiteness, finiteness, effectiveness). It separates the abstract steps of a method from the concrete code that implements it, and walks through how to judge whether a procedure is correct before worrying about whether it is fast. You will also build a first informal sense of efficiency, the way work grows as inputs get bigger, without any formal notation yet.

In How to Read Code (JS & Python), you practiced tracing variables, loops, and function calls in two languages. Introduction to Algorithms zooms out from individual lines to the recipe as a whole, treating those traces as evidence that a method does what it claims.

From here you will move into Iteration Patterns on Arrays/Strings, where these abstract ideas about correctness and efficiency get applied to concrete traversal templates.

Beginner
45 min
6 Objectives
5 Sections

Topics:

Algorithms
What is an Algorithm?
Correctness
Efficiency
Basics
Beginner
Free
Fundamentals

What You'll Learn

By the end of this lesson, you will be able to:

Define what an algorithm is and list its five key characteristics.

Distinguish between an algorithm (abstract steps) and its implementation (code in a language).

Evaluate whether a given set of steps constitutes a correct algorithm for a stated problem.

Explain why the same problem can have multiple algorithms with different efficiency profiles.

Trace through a simple find-max algorithm on a small input and predict intermediate states.

Describe efficiency informally using phrases like 'linear time' and 'constant extra memory' (without formal Big-O notation).

Why This Matters

01

Every piece of software you use — from search engines to social media feeds — runs on algorithms. Understanding what an algorithm is gives you the vocabulary to reason about any computational task.

02

Before you can optimize code, you need to distinguish between 'correct' and 'efficient.' This lesson builds that distinction so that later topics like Big-O and sorting have a solid foundation.

03

Algorithms are language-independent: once you understand the steps, you can implement them in JavaScript, Python, or any other language. Thinking algorithmically is a transferable skill that outlasts any single technology.

04

Interviewers expect you to articulate your approach before you code. Knowing how to describe an algorithm — its inputs, outputs, and step-by-step logic — is the first skill tested in every technical interview.

Key Terms

8 terms you'll encounter in this lesson

1

Algorithm

A finite sequence of well-defined, unambiguous steps that takes an input and produces a desired output.

2

Correctness

An algorithm is correct if it produces the expected output for every valid input and eventually terminates.

3

Finiteness

An algorithm must terminate after a finite number of steps for any valid input — it cannot loop forever.

4

Definiteness

Each step of an algorithm must be precisely and unambiguously defined, leaving no room for interpretation.

5

Efficiency

A measure of how an algorithm's resource usage (time, memory) grows as the input size increases.

6

Linear time

An algorithm that examines each element of the input a fixed number of times. Doubling the input roughly doubles the work.

7

Implementation

The concrete code in a specific programming language that carries out an algorithm's abstract steps.

8

Input / Output

The data an algorithm receives (input) and the result it produces (output). Every algorithm must clearly specify both.

Related Problems

Coding problems that put this lesson's concepts into practice

Heads Up

Common misconceptions to watch out for

"An algorithm is the same as a program"

An algorithm is an abstract sequence of steps. A program is one specific implementation of an algorithm in a particular language with specific data types, libraries, and syntax. The same algorithm can be coded in JavaScript, Python, C++, or any language.

"If my code gives the right answer on one test case, the algorithm is correct"

Correctness means the algorithm works for ALL valid inputs, not just one. You must consider edge cases (empty input, single element, duplicates, negative numbers) to verify correctness.

"Faster hardware makes algorithm choice irrelevant"

A slow algorithm on fast hardware will still lose to a fast algorithm on slow hardware once the input is large enough. For example, an algorithm that checks all pairs in a million-element list does roughly a trillion operations — no amount of hardware makes that fast.

"Every algorithm must be complicated"

Some of the most important algorithms are simple. Finding the maximum element in a list is a single loop. The key is that the steps are well-defined and produce the correct result efficiently — simplicity is a virtue, not a flaw.