Class prep · TJ Artificial Intelligence

Turn a descriptioninto a procedure.

An independent course in artificial intelligence. Practice search, heuristics, constraints, games and a first learning model, then the Artificial Intelligence 2 topics: probability and Bayes' rule, Bayesian networks, Markov decision processes and reinforcement learning, and language and sequence models. Check every result by hand. Every problem has a full worked solution. Built by Neil Kothari, a TJ alumnus.

$395 covers the full school year. The first lesson is free.

Try one. This is a test-level question from the course.

Problem 1

  • Test level
  • Multiple choice
  • No calculator
  • 4 pts

A number starts at 2. The actions are add 3 and double, tried in that order. Results above 30 are not allowed. The goal test is "the number is a multiple of 7".

Use the lesson's rules: neighbors are tried in the listed order, a node is marked when it is discovered, and the search stops when G is expanded (taken off the frontier), not when G is first discovered.

How many expansions does BFS make, and which path does it return?

Choose one answer

original problems, each with a worked answer
936
original problems, each with a worked answer
at test level or beyond
648
at test level or beyond
short lessons, one for every topic
72
short lessons, one for every topic
units, all open now
12
units, all open now

Free lesson

Lesson 1.1: States, actions, and a goal test

How to turn a map into states, actions, and a goal test, then search it one node at a time and read the path back.

Start with states, actions and a goal test. The queue that lists reachable states is the search the next lesson names.

Start with a question

You are at school and want to get to the gym. You can walk from school to the bakery. From the bakery you can go to the corner store or to the park. The corner store also leads to the park, the park leads to the museum, and the museum leads to the gym.

How do you find a route? You probably looked at the list and traced it with your finger. A computer cannot "look." It needs the question written in a form it can follow one step at a time:

  • Where am I allowed to be? (the states)
  • From each place, where can I go next? (the actions)
  • How do I know I have arrived? (the goal test)

Once those three things are written down, any search rule can be run on them, by you or by a program, and two people running the same rule will get the same answer.

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

  • name the states, actions, start, and goal test of a search problem,
  • read a neighbor list and know the order in which actions are tried,
  • trace breadth-first search with a queue and depth-first search with a stack,
  • tell the difference between a node being discovered and being expanded,
  • read the path back from parent pointers and count its edges.

The three parts of a search problem

A search problem has three parts.

  1. States. Every situation you could be in. On a map, a state is a place. In this unit, a state is a node name such as S, P, or G.
  2. Actions. For each state, the legal moves out of it. In this unit, each neighbor listed for a node is one action. If the list says Q: [R, G], then from Q you can move to R or to G, and nothing else.
  3. Goal test. A yes or no question you ask about a state: "Is this the goal?" In this unit the goal test is true only at G.

You also need a start state, the place the search begins. Here it is always S.

A street map turned into a search problem with states, actions, start, and goal

A drawing alone is not a problem yet. Two people can trace different routes through the same picture of a maze if one thinks a diagonal step is allowed. Writing out the states, actions, and goal test removes that argument.

Neighbor order is part of the problem

The order of a neighbor list matters. S: [P, Q] means the search tries P first and Q second. If the list were S: [Q, P], the search could visit nodes in a different order and even return a different path. When a problem gives you a list, you follow the written order exactly. You do not sort it, and you do not skip ahead to the neighbor that "looks closer" to G.

A small graph and its neighbor list, showing which neighbor is tried first

Path length in this unit

There are no costs on the edges yet. Every move counts as one step, so the length of a path is the number of edges in it. The path S-Q-G has 3 nodes and 2 edges. Always count edges, not nodes.

Quick check 1. In the street map above, what is the start state, what is the goal test, and which actions are available at the bakery, in order? Answers are at the end of the lesson.

Worked example 1: listing every route on the street map

Write the street map as a neighbor list, using S for School, B for Bakery, C for Corner store, P for Park, M for Museum, and G for Gym:

S: [B]
B: [C, P]
C: [P]
P: [M]
M: [G]
G: []

List every simple path (a path that never repeats a node) from S to G, with its length.

  1. From S the only action is B. Every path starts S-B.
  2. From B there are two actions. Follow C first: S-B-C. From C the only action is P: S-B-C-P. Then P to M to G: S-B-C-P-M-G. That path has 6 nodes, so 5 edges.
  3. Go back to B and take its second action, P: S-B-P. Then P to M to G: S-B-P-M-G. That path has 5 nodes, so 4 edges.
  4. There are no other branches, so these are the only two simple paths.

The shortest one is S-B-P-M-G with 4 edges.

Check: read each consecutive pair and confirm it is a listed action. For S-B-P-M-G: S lists B, B lists P, P lists M, M lists G. Every step is legal, and the edge count is one less than the 5 nodes.

Problem 2

  • Core
  • True or false
  • No calculator
  • 2 pts

A directed graph has these arrows.

NodeNeighbors, in order
SL, H
LH, G
HC
CG
G(none)

Use the lesson's rules: neighbors are tried in the listed order, a node is marked when it is discovered, and the search stops when G is expanded (taken off the frontier), not when G is first discovered.

True or false: breadth-first search from S discovers node C but never expands it.

Is the statement true or false?

Problem 3

  • Core
  • Multiple choice
  • No calculator
  • 4 pts

Three light switches are each off (0) or on (1). A state is written as three digits, switch 1 first, so the start is 000. The actions are flip 1, flip 2, flip 3, tried in that order. The goal test is "the state is 011".

Use the lesson's rules: neighbors are tried in the listed order, a node is marked when it is discovered, and the search stops when G is expanded (taken off the frontier), not when G is first discovered.

Which path does breadth-first search return, and how long is it?

Choose one answer

Open the rest of this lesson, free

The full lesson and all 13 of its problems, with every worked answer.

I am aI am a

Your free lesson opens right here, on this device for 30 days. We'll email you occasional TJ class prep updates. Unsubscribe anytime.

How it works

Class prep that works alongside class

A complete artificial intelligence course for students taking Artificial Intelligence at TJ. Work alongside class or study the material in sequence. Each lesson states a rule, runs it on a small instance, and shows the check before you try the practice.

  • Original problems in several formats: true or false, multiple choice, multi-part and free response.
  • Each one is marked core, test level or beyond.
  • Search, heuristics, local search, constraints, games, logic, a first learning model and one-step backups, then probability, Bayesian networks, Markov decision processes and language models.
  • A worked answer for every problem, ending with the mistake that most often costs points.
  • Queues and stacks, A-star, hill climbing, coloring, minimax, entailment, neighbors, a Q update, Bayes' rule, value iteration, n-grams and the Viterbi algorithm.

What is inside

  1. 1Search problems6 lessons · 78 problems
  2. 2Heuristics6 lessons · 78 problems
  3. 3Local search6 lessons · 78 problems
  4. 4Constraints6 lessons · 78 problems
  5. 5Games6 lessons · 78 problems
  6. 6Logic6 lessons · 78 problems
  7. 7A first learning model6 lessons · 78 problems
  8. 8Agents6 lessons · 78 problems
  9. 9Probability and Bayes' Rule6 lessons · 78 problems
  10. 10Bayesian Networks6 lessons · 78 problems
  11. 11Markov Decision Processes and Reinforcement Learning6 lessons · 78 problems
  12. 12Language and Sequence Models6 lessons · 78 problems
The front entrance of Thomas Jefferson High School for Science and Technology
Neil Kothari, co-founder of EduAvenues

Who built it

Neil Kothari

TJHSST alumnus · Co-founder, EduAvenues · 10+ years in TJ preparation

Neil is a TJ alumnus and has spent more than a decade working with TJ students and their families. He built this course so a student can turn a search or a model into a small instance and check the result by hand. Every problem is written for the course and every answer is checked before it goes in.

Tuition

$395for the full school year

One tuition covers every unit of the course. All 12 units are open now. The States, actions, and a goal test lesson stays free for everyone.

  • All 12 units: 72 lessons and 936 original problems
  • A worked answer for every problem
  • Access through the end of the school year
Enroll
TJ Artificial Intelligence | EduAvenues