Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Informed Search: Exercises and Homework

Midterm preparation for Informed Search, Local Search & Genetic Algorithms.


Part A: Concept Check (True / False)

State whether each claim is true or false and justify it in one sentence.

  1. A* with an admissible heuristic always returns an optimal solution when it terminates by selecting the goal for expansion.

  2. Greedy best-first search is optimal whenever hh is admissible.

  3. With h(n)=0h(n)=0 for all nn, A* behaves exactly like Uniform-Cost Search.

  4. Every consistent heuristic is admissible, and every admissible heuristic is consistent.

  5. A* may stop as soon as the goal is generated (added to the frontier) and still be optimal.

  6. If h1h_1 and h2h_2 are both admissible, then h1+h2h_1 + h_2 is admissible.

  7. If h1h_1 and h2h_2 are admissible and h2(n)≥h1(n)h_2(n)\ge h_1(n) for all nn, A* with h2h_2 never expands more nodes than with h1h_1 (ignoring ties).

  8. Hill climbing is complete: it always finds the global optimum if one exists.

  9. Simulated annealing with a very high temperature behaves like a random walk; with T→0T\to 0 it behaves like hill climbing.

  10. Tabu search can accept a move that makes the current solution worse.

  11. Single-point crossover is a valid operator for permutation chromosomes.

  12. Larger tournament size kk means higher selection pressure.

  13. Mutation is the GA’s main exploitation operator.

  14. Roulette-wheel selection can be applied directly to fitness values that may be negative.


Part B: Tracing Greedy, UCS and A*

Exercise B1

Consider the directed graph below. Start node is S, goal node is G. The edge labels are step costs and the heuristic value hh is written in each node.

  1. Compute the true cost-to-goal h∗(n)h^*(n) for every node. Is hh admissible? Is it consistent?

  2. Run Greedy Best-First Search. Give the order of expansion, the path found and its cost.

  3. Run Uniform-Cost Search. Give the order of expansion, the path found and its cost.

  4. Run A*. Give the order of expansion (with the ff value of each expanded node), the path found and its cost.

  5. Which algorithm expanded the fewest nodes? Which returned a non-optimal path? Explain why.

Exercise B2

Use the same graph as in B1 but with this different heuristic: h(S)=7, h(A)=6, h(B)=1, h(C)=7, h(D)=3, h(G)=0h(S)=7,\ h(A)=6,\ h(B)=1,\ h(C)=7,\ h(D)=3,\ h(G)=0.

  1. Is the new heuristic admissible? Is it consistent?

  2. Run A*. What path does it return and what is its cost? Explain what changed compared to B1.


Part C: Heuristics

Exercise C1: Admissible or consistent?

Directed graph with start S and goal G:

For each heuristic below, decide whether it is admissible, consistent, both, or neither. Justify with the relevant inequality.

NodeSABCG
hah_a54320
hbh_b65130
hch_c67430
hdh_d00000
heh_e65431

Exercise C2: Combining heuristics

h1h_1 and h2h_2 are admissible. For each of the following, state whether it is always admissible (give a proof) or not necessarily (give a counter-example).

  1. max⁡(h1,h2)\max(h_1,h_2)

  2. min⁡(h1,h2)\min(h_1,h_2)

  3. 12(h1+h2)\tfrac12(h_1+h_2)

  4. h1+h2h_1+h_2

  5. 2 h12\,h_1

Exercise C3: 8-Puzzle heuristics

Initial state (left) and goal (right); _ is the blank.

Initial:        Goal:
2 8 3           1 2 3
1 6 4           8 _ 4
7 _ 5           7 6 5
  1. Compute h1h_1 (number of misplaced tiles, blank excluded) and h2h_2 (sum of Manhattan distances) for the initial state.

  2. The blank can move up, left or right. For each of the three successors compute gg, h2h_2 and f=g+h2f=g+h_2. Which one does A* expand next?

  3. Which relaxation of the puzzle rules yields h1h_1? Which yields h2h_2?

  4. Does h2h_2 dominate h1h_1? What does it imply for the number of nodes expanded?

Exercise C4: Grid path planning

A robot moves in four directions (up/down/left/right), each move costs 1. # is a wall. Start S = (r0,c0), goal G = (r3,c4).

     c0 c1 c2 c3 c4
r0 :  S  .  .  #  .
r1 :  .  #  .  .  .
r2 :  .  #  #  .  #
r3 :  .  .  .  .  G
  1. Compute h(S)h(S) using the Manhattan distance to G.

  2. Is Manhattan distance admissible and consistent on this grid? Why?

  3. What is the true shortest path length? How many shortest paths exist?

  4. Using gg = true shortest distance from S, which free cells have f=g+h>7f=g+h>7? What does that tell you about A*?

Exercise C5: Effective branching factor

A* solves a problem at depth d=5d=5 and generates N=52N=52 nodes. The effective branching factor b∗b^* is the branching factor of a uniform tree of depth dd that contains N+1N+1 nodes:

N+1=1+b∗+(b∗)2+⋯+(b∗)dN+1 = 1 + b^* + (b^*)^2 + \dots + (b^*)^d

Estimate b∗b^* to two decimals. What does a b∗b^* close to 1 say about the heuristic?


Exercise D1: Hill climbing on 4-Queens

A state is a list of rows, one queen per column (rows and columns numbered 1 to 4). The loss LL is the number of attacking pairs. A move relocates one queen inside its column. Use steepest descent: move to the best neighbour and stop if no neighbour has a strictly lower loss.

Initial state: (2,3,2,4)(2,3,2,4).

  1. Compute LL of the initial state.

  2. Compute LL for all 12 neighbours. Which neighbour is chosen?

  3. Continue until the algorithm stops. What is the final state and its loss? Is it a solution?

  4. What simple modifications would let the search finish? Apply one and show the solution.

Exercise D2: Hill climbing on a small TSP

Distances (symmetric) between five cities:

ABCDE
A029107
B20648
C96085
D104803
E78530

A tour starts and ends at A. Neighbourhood: swap two of the four non-A cities in the tour. Starting from A→C→B→D→E→A:

  1. Compute the tour length.

  2. Evaluate the six neighbours and run steepest-descent hill climbing until it stops.

  3. Is the final tour a local or global optimum? How do you know?

Exercise D3: Simulated annealing

  1. Compute P(accept)=e−ΔL/TP(\text{accept})=e^{-\Delta L/T} for ΔL=4\Delta L=4 with T=8T=8, T=2T=2 and T=0.5T=0.5.

  2. With T=5T=5, decide for each move whether SA accepts it. Draw r∼U(0,1)r\sim U(0,1) given in the table.

MoveΔL\Delta LrrP(accept)P(\text{accept})Accepted?
1+30.40
2+100.20
3−20.95
4+50.35
  1. The schedule is exponential, T(t)=T0γtT(t)=T_0\gamma^t with T0=100T_0=100 and γ=0.9\gamma=0.9. What is TT after 10 iterations? After how many iterations does TT first drop below 1?

  2. Explain why SA must remember the best state ever seen.

States 0,…,70,\dots,7 lie on a line. A move goes to state i±1i\pm1. The loss is:

State01234567
LL64357412

Start in state 1.

  1. Run hill climbing. Where does it stop?

  2. Run tabu search where the tabu list holds the last k=2k=2 visited states (including the current one). At each step move to the best non-tabu neighbour, even if it is worse. Give the sequence of states and tabu list until the global minimum is found.

  3. What happens with k=1k=1?


Part E: Genetic Algorithms

Exercise E1: Roulette-wheel selection

Maximise f(x)=x2f(x)=x^2 over 5-bit integers. The population is:

ChromosomeA: 00110B: 10100C: 01011D: 11001
  1. Decode each chromosome and compute its fitness.

  2. Compute the selection probability, cumulative probability and expected count N⋅PiN\cdot P_i (N=4N=4).

  3. Spins of the wheel give r=0.45, 0.02, 0.90, 0.36r=0.45,\ 0.02,\ 0.90,\ 0.36. Which chromosomes enter the mating pool?

  4. Why is rank-based selection preferable if one chromosome had fitness 10000 and the others about 10?

Exercise E2: Crossover on bit strings

Parents: P1 = 11010011 and P2 = 00101100. Give both children for:

  1. Single-point crossover after bit 3.

  2. Two-point crossover with cuts after bit 2 and after bit 5.

  3. Uniform crossover with mask 10110010 (1 = take from P1P_1, 0 = take from P2P_2 for child 1; child 2 takes the opposite parent).

Exercise E3: Permutation operators

  1. Show with P1=[1,2,3,4,5]P_1=[1,2,3,4,5] and P2=[3,5,1,4,2]P_2=[3,5,1,4,2] that single-point crossover after position 2 gives an invalid child.

  2. Apply order crossover (OX1) with P1=[1,2,3,4,5,6,7,8]P_1=[1,2,3,4,5,6,7,8] and P2=[4,6,8,1,3,5,7,2]P_2=[4,6,8,1,3,5,7,2]. Copy the slice at positions 3 to 5 of P1P_1, then fill the remaining empty positions from left to right with the missing cities in the order they appear in P2P_2.

  3. Apply to [3,1,4,2,5][3,1,4,2,5]: (a) swap mutation of positions 2 and 5, (b) inversion mutation of positions 2 to 4, (c) insertion mutation moving the gene at position 5 to position 2.

  4. Why is inversion mutation a good choice for TSP?

Exercise E4: One generation by hand

Maximise the number of ones (OneMax) over 6 bits. Population:

A: 110100B: 111011C: 000100D: 101010
  1. Compute the fitness of each chromosome and the population average.

  2. Selection gave the mating pool {B, A, B, D}. Pair them as (B, A) and (B, D), and apply single-point crossover after bit 3 to each pair. Write all four children.

  3. Mutation (bit flip): flip bit 4 of the last child. Write the new population, with fitness and average.

  4. Did the average improve? Which operator contributed to the improvement of the best fitness?

Exercise E5: Design questions

For each problem, choose the encoding, the crossover and the mutation operator, and write the fitness function.

  1. 0/1 knapsack with 12 items and a weight limit.

  2. Tuning 5 real-valued parameters of a controller.

  3. Exam timetable where each of 20 exams gets a time slot (slots may repeat).

  4. Delivery route through 15 cities.