1. Home
  2. Explore
  3. Computer Science
  4. Artificial Intelligence Introduction

Study methods

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

Artificial Intelligence Introduction

Artificial Intelligence: Foundations, History, and Core Problem-Solving Paradigms

1. What Artificial Intelligence Seeks to Accomplish

Artificial intelligence studies how to build computational systems that perform tasks associated with intelligence. These tasks include:

  • Perception: seeing, recognizing objects, interpreting images, and understanding speech.

  • Action and motor control: grasping objects, moving through environments, and operating robots.

  • Language: communicating, translating, reading documents, and answering questions.

  • Knowledge representation: storing facts and procedures about the world.

  • Reasoning: drawing conclusions from known information.

  • Learning: acquiring new capabilities from experience and data.

AI has produced systems capable of superhuman performance in narrowly defined tasks, including:

  • Jeopardy-style question answering

  • The games of Go, chess, poker, and Dota 2

  • Speech and face recognition

  • Document understanding

  • Medical-image analysis

AI is likely to have a transformative effect on work and society. However, the future consequences of AI are difficult to predict, and successful demonstrations do not imply that general intelligence has been achieved.


2. A Brief History of Artificial Intelligence

2.1 The Dartmouth Workshop and the Birth of AI

In the summer of 1956, John McCarthy organized a workshop at Dartmouth College with researchers including Marvin Minsky and Claude Shannon. The workshop pursued an ambitious hypothesis:

Every aspect of learning and intelligence might be described precisely enough that a machine could simulate it.

This event is often regarded as the beginning of AI as an organized field.

Early AI programs could:

  • Play checkers

  • Prove mathematical theorems

  • Manipulate symbolic representations

  • Sometimes produce proofs more elegantly than human-written proofs

The early period was marked by significant optimism. Many researchers predicted that AI would be solved within only a few years.

2.2 Early Limitations and the First AI Winter

One famous example involved machine translation. An English sentence such as:

“The spirit is willing but the flesh is weak”

was translated into Russian and then back into English, producing:

“The vodka is good but the meat is rotten.”

This demonstrated that translation was not merely a matter of replacing words. Successful translation requires knowledge of language, context, ambiguity, and cultural meaning.

The resulting disappointment contributed to reduced government funding and the first AI winter, a period of low activity and limited financial support.

Why early AI struggled

  • Insufficient computation: Early machines had vastly less computational power than modern systems.

  • Exponential search: Many problems were formulated in ways that required exploring an exponentially growing number of possibilities.

  • Limited information: Even unlimited computation would not solve tasks such as translation without access to linguistic knowledge and experience.

  • Overly optimistic expectations: Researchers underestimated the complexity of real-world intelligence.

2.3 Contributions from Early AI Research

Although early AI did not achieve general intelligence, it produced important computer-science ideas:

  • Lisp: Influenced later high-level programming languages.

  • Garbage collection: Automated memory management.

  • Time-sharing: Allowed multiple users to interact with a single computer.

  • Modeling and inference: Encouraged the separation between what should be computed and how the computation should be performed.

The distinction between modeling and inference remains central to modern AI.


3. Expert Systems and the Second AI Winter

During the 1970s and 1980s, AI research shifted toward knowledge-based systems.

3.1 Expert Systems

The central idea was:

If expert knowledge about the world can be encoded, a computer can use that knowledge to perform expert-level tasks.

Knowledge was commonly represented as a collection of deterministic rules. For example:

  • If a patient has symptoms AAA and BBB, then consider diagnosis CCC.

  • If a customer orders product XXX, then retrieve component YYY.

Expert systems were usually narrower than the original goal of solving all intelligence. They focused on practical applications such as:

  • Disease diagnosis

  • Converting customer orders into component specifications

  • Industrial decision-making

These systems represented one of the first periods in which AI produced useful commercial products.

3.2 Limitations of Rule-Based Knowledge

Rule-based systems helped control the search space by incorporating domain knowledge, but they had major weaknesses:

  • Insufficient richness: Deterministic rules could not capture all the nuance and uncertainty of the real world.

  • Manual construction: Experts had to encode knowledge by hand.

  • Maintenance difficulty: Updating a large rule system was labor-intensive.

  • Brittleness: A system could fail when confronted with circumstances not covered by its rules.

  • Overpromising: Expectations again exceeded actual performance.

These problems contributed to the second AI winter.


4. Artificial Neural Networks and Deep Learning

A second intellectual tradition in AI developed from neuroscience rather than primarily from logic.

4.1 McCulloch and Pitts

In 1943, neuroscientist Warren McCulloch and logician Walter Pitts developed a mathematical theory of artificial neural networks.

Their work connected:

  • Biological neurons

  • Mathematical computation

  • Logic

This connection established an early foundation for modern neural networks and deep learning. Because computers were not powerful enough to train large models at the time, much of the early work focused on mathematical analysis rather than large-scale experimentation.

4.2 The Perceptron Limitation

In 1969, Marvin Minsky and Seymour Papert published Perceptrons. Their analysis showed important limitations of single-layer linear classifiers.

A key example was the XOR problem. A linear classifier cannot represent XOR because the two classes cannot be separated by a single straight boundary.

For inputs x1x_1x1​ and x2x_2x2​, XOR returns true when the inputs differ:

x1⊕x2={1if x1≠x20if x1=x2x_1 \oplus x_2 = \begin{cases} 1 & \text{if } x_1 \ne x_2 \\ 0 & \text{if } x_1 = x_2 \end{cases}x1​⊕x2​={10​if x1​=x2​if x1​=x2​​

The limitation applied to linear models, not necessarily to deeper networks. Nevertheless, the result discouraged much neural-network research and contributed to the field’s shift toward symbolic and logic-based approaches.

4.3 Backpropagation and Multilayer Networks

During the 1980s, researchers renewed interest in neural networks. The rediscovery and development of backpropagation provided a general method for training multilayer networks.

This was important because:

  • Single-layer networks have limited expressive power.

  • Multiple layers can represent more complex functions.

  • Backpropagation efficiently computes how each parameter contributes to prediction error.

4.4 Convolutional Neural Networks

In 1989, Yann LeCun applied a convolutional neural network to handwritten-digit recognition. The technology was later deployed by the United States Postal Service to read ZIP codes.

Convolutional neural networks are particularly useful for visual data because they can detect local patterns such as:

  • Edges

  • Corners

  • Shapes

  • Object parts

4.5 The Deep-Learning Revolution

Neural networks became especially successful in the 2010s under the name deep learning.

A major milestone was AlexNet in 2012, which achieved substantial improvements on the ImageNet computer-vision benchmark. This result rapidly transformed the computer-vision field.

Other major successes, including AlphaGo, demonstrated that neural networks could perform extremely well on complex tasks when combined with suitable training procedures and computational resources.


5. Two Intellectual Traditions in AI

AI has historically contained two major traditions.

5.1 Symbolic and Logical AI

This tradition emphasizes:

  • Explicit symbols

  • Rules

  • Logic

  • Knowledge representation

  • Formal reasoning

It is closely associated with John McCarthy and the early Dartmouth tradition.

5.2 Neuroscience-Inspired AI

This tradition emphasizes:

  • Artificial neurons

  • Distributed representations

  • Learning from data

  • Neural networks

  • Perception and pattern recognition

It is associated with the work of McCulloch, Pitts, LeCun, and modern deep learning.

5.3 The Traditions Are Connected

The two traditions should not be treated as completely unrelated.

  • McCulloch and Pitts connected neural networks with logic from the beginning.

  • Games such as Go have precisely defined logical rules.

  • Neural networks can nevertheless learn strategies that perform exceptionally well in such games.

This creates a central question in AI:

How can neural models learn highly effective behavior in environments whose rules can be described symbolically and mathematically?

Modern AI often combines techniques from both traditions.


6. AI as a Melting Pot of Techniques

AI draws on many fields, including:

  • Statistics: maximum likelihood and probabilistic modeling

  • Economics: game theory and strategic decision-making

  • Optimization: gradient descent and objective minimization

  • Computer science: algorithms, programming languages, and data structures

  • Neuroscience: models inspired by biological neural systems

  • Logic: formal reasoning and knowledge representation

AI can be viewed as a field that combines techniques developed in different contexts and applies them to challenging problems. The power of AI often comes from novel combinations of existing ideas rather than from one isolated technique.


7. Two Views of AI: Agents and Tools

AI can be understood through two related but philosophically distinct perspectives.

7.1 AI as Agents

The agent view asks:

How can intelligence be created or recreated in an artificial system?

A human-like agent would need capabilities such as:

  • Perception and object recognition

  • Physical interaction with the environment

  • Language communication

  • Declarative knowledge

  • Procedural knowledge

  • Reasoning

  • Learning from experience

Declarative and Procedural Knowledge

  • Declarative knowledge: Knowledge of facts, such as the capital of France.

  • Procedural knowledge: Knowledge of how to perform actions, such as how to ride a bicycle.

An intelligent agent should be able to use both types of knowledge. For example, it might know where Paris is and know how to travel there by bicycle.

Learning as a Central Capability

Humans are not born with fully developed language, reasoning, perception, or motor skills. Humans are born with the capacity to acquire these capabilities through experience.

Learning is therefore central to both:

  • Human intelligence

  • Modern AI systems

Current Gap Between Machines and Humans

Modern AI systems often achieve excellent performance under a narrow regime:

  • A precisely defined task

  • Very large datasets

  • Large amounts of computation

  • Extensive optimization

Humans operate differently:

  • They handle many diverse tasks.

  • They learn from relatively few examples.

  • They transfer knowledge between tasks.

  • They adapt to new situations.

  • They accumulate broad experience.

Building systems with this level of flexible, general-purpose learning remains a major challenge.

7.2 AI as Tools

The tool view asks:

How can technology be used to benefit people and society?

This view does not require an artificial system to resemble a human. Instead, it focuses on building systems that solve useful problems, including problems that humans did not evolve to solve.

Examples include:

  • Using satellite imagery and computer vision to estimate economic conditions in impoverished regions

  • Optimizing cooling systems in data centers to reduce energy consumption

  • Supporting medical analysis

  • Automating recognition and prediction tasks

A system can be valuable without possessing general intelligence or human-like behavior.


8. Risks and Social Consequences of AI

As AI systems are deployed in important settings, technical performance alone is not sufficient. Security, bias, fairness, and social impact must also be considered.

8.1 Adversarial Examples

An adversarial example is an input deliberately modified to cause an AI system to make an incorrect prediction.

Examples include:

  • Glasses or other visual accessories designed to fool face-recognition systems

  • Stickers placed on stop signs that cause a vision system to classify them as speed-limit signs

These failures are especially dangerous in applications such as:

  • Autonomous vehicles

  • Authentication

  • Security systems

  • Safety-critical perception

A model that performs well on ordinary test examples may still be vulnerable to carefully designed inputs.

8.2 Bias in Machine-Learning Systems

Machine-learning systems learn patterns from data generated by society. If those data contain social biases, the trained model may reproduce or amplify them.

For example, a translation system may associate:

  • A gender-neutral pronoun with nursing

  • Another gender-neutral pronoun with programming

Such outputs can encode stereotypes even when the system was not explicitly programmed with those stereotypes.

The basic process is:

  1. Society generates data.

  2. A machine-learning system trains on the data.

  3. The model learns statistical patterns.

  4. The model produces predictions that may reproduce existing biases.

This makes bias an active area of research rather than a problem that can be ignored.

8.3 Fairness and Incompatible Definitions

Risk-prediction systems used in criminal-justice settings illustrate the difficulty of defining fairness.

Suppose a system assigns risk scores to people from different demographic groups. One notion of fairness might require:

  • Equal accuracy across groups

Another might require:

  • Equal proportions of false positives across groups

A third might require:

  • Equal proportions of people who reoffend within each risk category

These requirements may each seem reasonable, but under certain conditions they are mathematically incompatible. Therefore, fairness cannot be treated as a single purely technical criterion. It requires social and ethical decisions about which values should take priority.

8.4 Deployment Is Part of the AI Problem

An AI system can affect people’s:

  • Employment

  • Access to services

  • Safety

  • Legal outcomes

  • Privacy

  • Economic opportunities

Responsible AI therefore requires attention to the full deployment context, not merely benchmark accuracy.

Importantly, reproducing human behavior is not always desirable. Humans can be biased and unreliable, so an AI system should not automatically imitate every human pattern found in its training data.


9. The Modeling–Inference–Learning Paradigm

A central framework for approaching complex AI problems consists of three components:

  1. Modeling

  2. Inference

  3. Learning

This framework provides a principled structure for transforming a complicated real-world problem into working software or hardware.

9.1 Modeling

Modeling means simplifying the real world into a mathematically precise representation.

A model is a mathematically precise simplification of a complex real-world system.

A model must discard information because it is impossible or impractical to represent every detail. The central modeling skill is deciding:

  • Which information is important?

  • Which information can be ignored?

  • Which assumptions make the problem computationally manageable?

Example: Finding a Route

To find the best route through a city, the city can be modeled as a graph:

  • Nodes: Locations or intersections

  • Edges: Connections between locations

  • Edge costs: Travel time, distance, tolls, or another measure of expense

This model ignores many real-world details but preserves the information needed for route planning.

9.2 Inference

Inference means asking questions and performing computations using a model.

Given the city graph, inference could answer:

  • What is the shortest path between two locations?

  • What route has the lowest cost?

  • Which locations are reachable?

  • How does a blocked road affect the best route?

Once the model is mathematically defined, algorithmic methods can be used to solve these questions efficiently.

9.3 Learning

Learning addresses the question:

Where do the model’s parameters come from?

A model may have a structure but unknown numerical values. For example:

  • The graph structure may be known.

  • The actual travel-time cost of each edge may be unknown.

Data can provide these parameters. If travelers report that a route takes particular amounts of time, a learning algorithm can estimate representative edge costs.

The general process is:

  1. Specify a parameterized model structure.

  2. Collect relevant data.

  3. Fit the parameters to the data.

  4. Use inference on the learned model.

Learning Is a General Philosophy

Learning is not synonymous with one particular algorithm such as nearest neighbors or neural networks. It is a general approach in which:

  • The model structure is specified.

  • Detailed parameters are learned from data.

  • A generic procedure fills in information that would be difficult to encode manually.

This differs from older expert systems, which attempted to manually encode large amounts of domain knowledge.


10. Machine Learning and Generalization

Machine learning is a central building block that can be applied to many types of AI models.

10.1 Moving Complexity from Code to Data

Traditional software engineering often places complexity in manually written code. Machine learning changes this balance:

  • Instead of writing enormous amounts of task-specific code,

  • the system uses a smaller amount of general code,

  • together with a large dataset from which patterns are learned.

This can be described as moving complexity from code to data.

10.2 Generalization

The goal of machine learning is not merely to perform well on the training data.

Generalization is the ability of a learned model to perform well on new examples and experiences.

The essential process is:

  1. Observe training data.

  2. Fit a model to that data.

  3. Apply the model to unseen examples.

  4. Evaluate whether the learned patterns transfer beyond the training set.

A model that memorizes the training data but fails on new examples has poor generalization.

Machine learning therefore requires a kind of empirical leap of faith: the patterns found in past data are assumed to remain useful for future data. Probability and statistics provide formal tools for analyzing when and why this assumption may be justified.


11. Types of AI Models

The course organizes models from lower-level, fast reactions to higher-level reasoning.

11.1 Reflex Models

A reflex model maps an input directly to an output using a fixed computation.

The basic pattern is:

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

Examples include:

  • Linear classifiers

  • Deep neural networks

  • Image-recognition systems

Reflex models are useful because they are fast. Once trained, they can often produce a response immediately.

Their main limitation is that they generally do not explicitly reason about future actions or possible world states.

11.2 State-Based Models

Some problems require planning and foresight. A state-based model represents:

  • The current situation as a state

  • Possible actions

  • The transitions caused by those actions

For example, in a chess position:

  • The board configuration is a state.

  • Legal moves are actions.

  • Each move produces a new state.

State-based models are useful in:

  • Games

  • Robotics

  • Motion planning

  • Navigation

  • Sequential decision-making

  • Some forms of language or image generation

Search Problems

In a search problem:

  • The agent controls the actions.

  • The objective is to find an optimal path or sequence.

Examples include route planning and puzzle solving.

Problems with Randomness

Some environments include uncertainty or randomness:

  • Traffic conditions may be unknown.

  • Dice rolls may influence a game.

  • Sensors may be noisy.

Such models must represent probabilities or random transitions.

Adversarial Games

In an adversarial problem, another agent actively tries to interfere with the system’s goals.

Examples include:

  • Chess

  • Go

  • Competitive games

  • Strategic interactions

Some environments combine adversarial behavior with randomness. Backgammon is an example: an opponent acts strategically, while dice introduce random outcomes.

Pac-Man as a State-Based Problem

A Pac-Man agent can be modeled using:

  • State: Pac-Man’s location, ghost locations, remaining dots, and possibly current game conditions

  • Actions: Move up, down, left, or right

  • Objective: Eat dots while avoiding ghosts

  • Strategy: Plan actions that balance progress, safety, and future consequences

11.3 Variable-Based Models

Some problems are more naturally represented as assignments to variables subject to constraints.

A variable-based model contains:

  • Variables

  • Possible values for each variable

  • Constraints or dependencies among variables

Constraint Satisfaction Problems

A constraint satisfaction problem, or CSP, requires an assignment of values that satisfies a set of hard constraints.

Examples include:

  • Sudoku

  • Scheduling

  • Assignment problems

  • Placement problems

In Sudoku:

  • Each blank is a variable.

  • Possible digits are the variable’s domain.

  • Constraints require that each row, column, and 3×33 \times 33×3 block contain the digits 111 through 999 without repetition.

Sudoku does not have a naturally important action order. The final assignment matters more than the sequence used to construct it.

Although Sudoku can be expressed as a state-based search problem, the variable-based formulation is more natural and allows specialized algorithms to exploit its constraints efficiently.

Bayesian Networks

A Bayesian network is a variable-based model containing soft probabilistic dependencies.

For example, a tracking system may contain:

  • Variables representing a vehicle’s position over time

  • Sensor readings associated with those positions

  • Probabilistic relationships describing how the vehicle moves and how sensors behave

Inference can then estimate the vehicle’s likely position given noisy sensor observations.

Choosing a Representation

Different representations are analogous to different programming languages:

  • A problem may be expressible in several forms.

  • One representation may be more natural.

  • A suitable representation can make algorithms simpler and more efficient.

The best model is not necessarily the most detailed one; it is the one that preserves relevant structure while supporting effective computation.


12. Logic and High-Level Intelligence

Logic-based models support systems that can:

  • Store heterogeneous information

  • Answer questions

  • Derive consequences

  • Reason over facts and rules

12.1 Facts and Rules

A logic system may be given facts such as:

  • Alice is a student.

  • Alice is from Phoenix.

  • Phoenix is a hot city.

It may also be given rules such as:

  • Students are people.

  • Cities are places.

  • If a person is from a hot place and it is cold, then that person is not happy.

The system can derive consequences from the combination of facts and rules.

For example:

  1. Alice is a student.

  2. Students are people.

  3. Therefore, Alice is a person.

If the system is told that Alice is not a person, it may detect a contradiction with the previously derived conclusion.

12.2 Open-Ended Reasoning

Logic systems differ from many narrow machine-learning systems because one statement can have many consequences. The system need not be shown millions of examples of every consequence.

A logic-based system can:

  • Learn or receive one fact.

  • Apply general rules.

  • Infer related facts.

  • Answer questions about the resulting knowledge base.

This supports rich reasoning over heterogeneous information.

12.3 Strengths and Weaknesses

Strengths

  • Explicit reasoning

  • Clear representation of facts and rules

  • Ability to derive consequences from limited information

  • Support for heterogeneous knowledge

Weaknesses

  • Brittleness when facts or rules are missing

  • Difficulty handling ambiguity and uncertainty

  • Dependence on the accuracy and completeness of the encoded knowledge

Logic is therefore powerful for structured reasoning but does not automatically solve the challenges of perception, noisy data, or common-sense understanding.


13. Discrete and Continuous Optimization

Optimization is a major tool for both inference and learning.

13.1 Discrete Optimization

Discrete optimization seeks the best object from a discrete set of possibilities.

Examples include:

  • Finding the lowest-cost path

  • Choosing a sequence of actions

  • Solving a puzzle

  • Selecting a valid assignment of variables

For a path PPP, a typical objective is:

min⁡PCost⁡(P)\min_P \operatorname{Cost}(P)minP​Cost(P)

The challenge is that the number of possible paths may be enormous. Trying every path individually is usually infeasible, so algorithms exploit structure.

One important tool is dynamic programming, which solves complex problems by reducing them to overlapping simpler subproblems.

13.2 Continuous Optimization

Continuous optimization seeks the best vector of real-valued parameters.

A general form is:

min⁡wf(w)\min_{\mathbf{w}} f(\mathbf{w})minw​f(w)

where:

  • w\mathbf{w}w is a vector of real-valued parameters

  • f(w)f(\mathbf{w})f(w) is an objective function

In machine learning, w\mathbf{w}w may contain model weights, and f(w)f(\mathbf{w})f(w) may represent training error.

A central algorithm for continuous optimization is gradient descent.


14. Dynamic Programming Through Edit Distance

14.1 The Edit-Distance Problem

Given two strings SSS and TTT, edit distance is the minimum number of edits needed to transform SSS into TTT.

The permitted edits are:

  1. Insertion: Add a character.

  2. Deletion: Remove a character.

  3. Substitution: Replace one character with another.

Examples:

  • The distance between cat and cat is 000.

  • The distance between cat and dog is 333.

  • The distance between cat and at is 111.

  • The distance between cat and cats is 111.

  • The distance between a cat and the cats is 444.

Edit distance is useful in:

  • Text matching

  • Spelling correction

  • Natural-language processing

  • Biological-sequence comparison

14.2 Reducing the Problem

A general problem-solving principle is:

Reduce a complex problem to simpler subproblems until the remaining cases are trivial.

To make the process systematic, the algorithm compares prefixes of the two strings rather than considering arbitrary edit positions.

Define:

D(m,n)D(m,n)D(m,n)

as the minimum edit distance between:

  • The first mmm characters of SSS

  • The first nnn characters of TTT

This representation uses indices rather than repeatedly copying substring objects.

14.3 Base Cases

If one string is empty, the only possible operation is to insert or delete every character in the other string.

Therefore:

D(0,n)=nD(0,n)=nD(0,n)=n

and

D(m,0)=mD(m,0)=mD(m,0)=m

These are the trivial cases that terminate the recurrence.

14.4 Matching Final Characters

If the final characters of the two prefixes match, no edit is needed for those characters:

D(m,n)=D(m−1,n−1)D(m,n)=D(m-1,n-1)D(m,n)=D(m−1,n−1)

when the mmmth character of SSS equals the nnnth character of TTT.

14.5 Nonmatching Final Characters

If the final characters differ, three operations are possible.

Substitution

Substitute the final character of one prefix for the final character of the other:

1+D(m−1,n−1)1 + D(m-1,n-1)1+D(m−1,n−1)

Deletion

Delete the final character from SSS:

1+D(m−1,n)1 + D(m-1,n)1+D(m−1,n)

Insertion

Insert the needed character into SSS. Equivalently, delete the final character from TTT:

1+D(m,n−1)1 + D(m,n-1)1+D(m,n−1)

The optimal recurrence is:

D(m,n)={nif m=0mif n=0D(m−1,n−1)if the final characters match1+min⁡(D(m−1,n−1),D(m−1,n),D(m,n−1))otherwiseD(m,n)= \begin{cases} n & \text{if } m=0 \\ m & \text{if } n=0 \\ D(m-1,n-1) & \text{if the final characters match} \\ 1+\min\left(D(m-1,n-1),D(m-1,n),D(m,n-1)\right) & \text{otherwise} \end{cases}D(m,n)=⎩⎨⎧​nmD(m−1,n−1)1+min(D(m−1,n−1),D(m−1,n),D(m,n−1))​if m=0if n=0if the final characters matchotherwise​

The minimum is taken because the algorithm must choose the least costly sequence of edits.

14.6 Why the Direction Does Not Affect Optimality

The algorithm can process the strings from left to right or right to left. The important requirement is consistency.

Any sequence of edits can be reordered according to the positions at which the edits occur. Thus, processing positions systematically from one end does not eliminate the optimal solution; it simply avoids redundant consideration of arbitrary operation orders.

14.7 Naive Recursion and Exponential Runtime

A direct recursive implementation branches into as many as three recursive calls whenever the final characters differ.

This creates a recursion tree with many repeated subproblems. Its runtime can grow exponentially because the same pair (m,n)(m,n)(m,n) may be recomputed through many different paths.

14.8 Memoization

Memoization stores the answer to each solved subproblem in a cache.

The procedure is:

  1. Before solving D(m,n)D(m,n)D(m,n), check whether (m,n)(m,n)(m,n) is already in the cache.

  2. If it is, return the stored value.

  3. Otherwise, compute the result recursively.

  4. Store the result for future use.

  5. Return the result.

Without memoization, the algorithm effectively pays for many repeated paths in the recursion tree. With memoization, it pays primarily for the number of distinct subproblems.

There are at most (m+1)(n+1)(m+1)(n+1)(m+1)(n+1) prefix pairs, so the memoized algorithm has approximately quadratic time complexity:

O(mn)O(mn)O(mn)

and requires approximately:

O(mn)O(mn)O(mn)

space for the cache.

Dynamic programming combines a recurrence for smaller subproblems with a mechanism—such as memoization—to ensure that each subproblem is solved only once.

This pattern appears repeatedly in search, decision processes, and game algorithms.


15. Continuous Optimization Through Linear Regression

15.1 The Regression Problem

Regression attempts to predict a numerical output from an input.

Examples include:

  • Predicting housing price from square footage

  • Predicting a health score from blood pressure and other measurements

Suppose the training data consists of points:

(x1,y1),(x2,y2),…,(xn,yn)(x_1,y_1), (x_2,y_2), \ldots, (x_n,y_n)(x1​,y1​),(x2​,y2​),…,(xn​,yn​)

For simplicity, consider a line constrained to pass through the origin:

y^=wx\hat{y}=wxy^​=wx

where www is the slope or model parameter.

15.2 Least Squares

For a data point (xi,yi)(x_i,y_i)(xi​,yi​), the prediction error is:

wxi−yiwx_i-y_iwxi​−yi​

Least squares squares this error and sums over all training points:

f(w)=∑i=1n(wxi−yi)2f(w)=\sum_{i=1}^{n}(wx_i-y_i)^2f(w)=∑i=1n​(wxi​−yi​)2

The objective is to find the value of www that minimizes f(w)f(w)f(w):

min⁡wf(w)\min_w f(w)minw​f(w)

A value of f(w)=0f(w)=0f(w)=0 means that every point is fitted exactly. Larger values indicate a poorer fit.

Squaring the errors:

  • Prevents positive and negative errors from canceling.

  • Penalizes large errors more strongly.

  • Produces a smooth objective function suitable for calculus-based optimization.

15.3 Abstracting the Objective Function

Rather than focusing only on the geometry of individual data points, the optimization problem can be viewed abstractly as minimizing a function.

Plotting f(w)f(w)f(w) against www converts regression into a general function-minimization problem:

  • The horizontal axis represents the parameter www.

  • The vertical axis represents the objective value f(w)f(w)f(w).

  • The goal is to reach the lowest point on the curve.

This abstraction allows the same optimization method to be applied to many different models and objective functions.


16. Gradient Descent

16.1 Core Idea

Gradient descent is an iterative method for minimizing a differentiable objective function.

The key idea is:

  • The derivative indicates the direction in which the function increases.

  • The opposite direction leads downhill.

  • Repeated downhill steps can approach a minimum.

For a one-dimensional objective f(w)f(w)f(w):

w←w−ηdfdww \leftarrow w-\eta \frac{d f}{d w}w←w−ηdwdf​

where η\etaη is the step size, also called the learning rate.

16.2 Derivative of the Least-Squares Objective

Starting with:

f(w)=∑i=1n(wxi−yi)2f(w)=\sum_{i=1}^{n}(wx_i-y_i)^2f(w)=∑i=1n​(wxi​−yi​)2

differentiate with respect to www:

dfdw=∑i=1n2(wxi−yi)xi\frac{d f}{d w} = \sum_{i=1}^{n}2(wx_i-y_i)x_idwdf​=∑i=1n​2(wxi​−yi​)xi​

The derivative follows from:

  • The derivative of a sum being the sum of the derivatives

  • The power rule for the squared error

  • The chain rule

  • The derivative of wxi−yiwx_i-y_iwxi​−yi​ with respect to www being xix_ixi​

The gradient-descent update is therefore:

w←w−η∑i=1n2(wxi−yi)xiw \leftarrow w-\eta\sum_{i=1}^{n}2(wx_i-y_i)x_iw←w−η∑i=1n​2(wxi​−yi​)xi​

16.3 Iterative Procedure

A basic gradient-descent algorithm is:

  1. Initialize www, often to 000.

  2. Compute the objective function.

  3. Compute its derivative or gradient.

  4. Move www in the opposite direction of the gradient.

  5. Repeat until convergence or until a stopping condition is met.

Pseudocode:

initialize w
repeat:
    compute f(w)
    compute gradient of f at w
    w = w - eta * gradient

The objective value should generally decrease as the algorithm approaches a minimum.

16.4 Step Size

The step size η\etaη controls how far the algorithm moves during each iteration.

  • If η\etaη is too small, convergence may be very slow.

  • If η\etaη is too large, the algorithm may overshoot the minimum or diverge.

  • A suitable step size allows the algorithm to approach the minimum efficiently.

An iteration can temporarily move past the minimum and then return, provided the overall process remains stable.

16.5 Gradients in Higher Dimensions

For a single parameter, the derivative is a scalar. For a vector of parameters w\mathbf{w}w, the corresponding object is the gradient:

∇f(w)\nabla f(\mathbf{w})∇f(w)

The gradient contains the partial derivative with respect to each parameter:

∇f(w)=[∂f∂w1,∂f∂w2,…,∂f∂wd]\nabla f(\mathbf{w}) = \left[ \frac{\partial f}{\partial w_1}, \frac{\partial f}{\partial w_2}, \ldots, \frac{\partial f}{\partial w_d} \right]∇f(w)=[∂w1​∂f​,∂w2​∂f​,…,∂wd​∂f​]

The update becomes:

w←w−η∇f(w)\mathbf{w} \leftarrow \mathbf{w}-\eta\nabla f(\mathbf{w})w←w−η∇f(w)

Gradient descent is foundational because many machine-learning algorithms train models by minimizing an objective function over a large parameter vector.


17. Central Takeaways

AI combines ideas from logic, statistics, neuroscience, optimization, economics, and computer science to build systems that perceive, reason, learn, and act.

  • Modeling simplifies a real-world problem into a precise mathematical form.

  • Inference answers questions using the model.

  • Learning estimates model parameters from data.

  • Reflex models respond directly and quickly but generally lack explicit foresight.

  • State-based models represent situations and actions, making them suitable for planning and games.

  • Variable-based models represent assignments subject to constraints or probabilistic dependencies.

  • Logic systems support explicit reasoning over facts and rules.

  • Dynamic programming solves problems with overlapping subproblems by storing intermediate results.

  • Gradient descent minimizes continuous objective functions by repeatedly moving opposite the gradient.

  • Generalization—performing well on new data rather than merely memorizing training data—is the central promise of machine learning.

  • Responsible AI must address adversarial inputs, bias, fairness, safety, and the real-world consequences of deployment.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent