Notation

We expand our notation for termination time for algorithms and apply this to graphs:

Primitive operations can be performed in steps.

Breadth First Search (Algorithm)

:

  1. Select root vertex and add to a Queue (ADT)
  2. While queue is not empty:
    1. Inspect first element in queue
    2. Add unvisited neighbours of to queue
    3. Remove from queue
Link to original

Theorem: The termination time for Breadth-First-Search is .

  • Every vertex is enqueued or dequeued at most once.
  • Steps 2.1 to 2.3 are repeated once for each .
  • Inspecting (2.1) and removing (2.3) take a constant amount (at most ) number of steps.
  • Step 2.2 requires operations to queue each of the adjacent vertices to . Where denotes the set of vertices adjacent to .
  • Hence we sum all of these terms:
{
	"url":"[week4_bfsdfs.pdf](https://git.is.horse/insert/university/obsidian-notes/-/raw/9d95afcbbdb7a4c77ca9f62b32e35c6f31e269e7/University/Year%202/Semester%201/5CCS2FC2%20Foundations%20of%20Computing%202/Resources/Slides/week4_bfsdfs.pdf)",
	"page":[5,6,7,8,9,10,11,12,13,14,15,16],
	"scale":1.5
}

Depth First Search (Algorithm)

:

  1. Select root vertex and add to a Stack (ADT)
  2. While stack is not-empty:
    1. Inspect top element on the stack
    2. Add any unvisited neighbours of to the stack
    3. Remove from the stack
Link to original

Example Search

{
	"url":"[week4_bfsdfs.pdf](https://git.is.horse/insert/university/obsidian-notes/-/raw/9d95afcbbdb7a4c77ca9f62b32e35c6f31e269e7/University/Year%202/Semester%201/5CCS2FC2%20Foundations%20of%20Computing%202/Resources/Slides/week4_bfsdfs.pdf)",
	"page":[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42],
	"scale":1.5
}