Skip to content

Depth-first search

networks

Level 2 of 3

Also called DFS.

fresh numbers

The test's questions that a run answers, asked again on new numbers whenever you like. The answer, its working and the reason for every other choice come from depth-first search's own run on the numbers shown.

choose one

question 1

The walk starts at A on the map C-H, B-E, G-H, E-F, F-G, A-E and C-D. How many looks does it make?

A1BCDEFGHA
the answer, and why

the answer is A

The map is in one piece with 7 roads, and each is looked along from both ends, 14 in all.

if you chose another

  • That counts each road once, but each road gets a look from both ends.
  • That counts the places, A, B, C, D, E, F, G, H, not the looks.
  • That adds the 8 places coming off, but coming off is no look.

new numbersthe test page's numbers

question 2

On the town of eight from A, how many places has the walk reached when it first steps back?

A1BCDEFGHA
the answer, and why

the answer is D

It reaches A, E, F, G, B, 5 places. Every road from B leads to a place already reached, so B comes off, and the walk steps back to G.

if you chose another

  • 4 is the stack after the step back, A, E, F, G. B was reached too.
  • That is the whole town, but C, D, H are not reached yet.
  • D, the next place, is reached after the step back.

new numbersthe test page's numbers

question 3

The walk starts at the place after the semicolon on each map. On which map does it make the most looks?

the answer, and why

the answer is D

B-F, C-H, C-D, D-H, B-C; B makes 10 looks, two for each road in its start's piece, the most of the four.

if you chose another

  • That map makes 8 looks, fewer than 10.
  • That map makes 8 looks, fewer than 10.
  • That map makes 8 looks, fewer than 10.

new numbersthe test page's numbers