DSA1 | Week 5

DeBruijn Sequences, BFS & DFS

Summary from last week

The Cardstack data structure

Deques | Stacks | Queues

De-Bruijn Sequences

Adj. Matrix Adj. List Edge List
Adding a vertex Painful Tolerable Decent
Deleting a vertex Painful Tolerable Tolerable
Adding an edge Brilliant Brilliant Brilliant
Deleting an edge Brilliant Decent Tolerable
Finding degree(v) Tolerable Decent Tolerable
Check if (u,v) is an edge Brilliant Decent Tolerable

Recap: what we have seen so far

Graph Representations

1

2

3

4

5

6

7

8

9

Try them all

Explore one thoroughly

What do you do when you have many different options?

Navigating Graphs

Navigating Graphs

Try them all

Explore one thoroughly

What do you do when you have many different options?

Phase 0.

Identify a

starting point \(s\).

Phase 1.

Collect

all friends of \(s\).

Phase 0.

Identify a

starting point \(s\).

Phase 1.

Collect

all friends of \(s\).

Phase 0.

Identify a

starting point \(s\).

Phase k.

Collect
anyone who is a
friend of
anyone seen before.

\(\cdots\)

\(s\)

\(x\)

\(y\)

\(w\)

\(z\)

\(s\)

\(x\)

\(y\)

\(w\)

\(z\)

\(s\)

\(x\)

\(y\)

\(w\)

\(z\)

\(s\)

\(x\)

\(y\)

\(w\)

\(z\)

Phase 1.

Collect

all friends of \(s\).

Phase 0.

Identify a

starting point \(s\).

Phase k.

Collect
anyone NEW
who is a

friend of
anyone seen before.

\(\cdots\)

Phase 1.

Collect

all friends of \(s\).

Phase 0.

Identify a

starting point \(s\).

Phase k.

Collect
anyone NEW
who is a

friend of
anyone seen before.

\(\cdots\)

Implementation?

ask every unvisited node if

they are adjacent to

any visited node.

Phase #\(k\).

Try them all

Explore one thoroughly

What do you do when you have many different options?

Navigating Graphs

Thanks, XKCD.

Thanks, Wikipedia.

DSA1 | Week 5

By Neeldhara Misra