Notation
We expand our notation for termination time for algorithms and apply this to graphs:
Primitive operations can be performed in steps.
Algorithm: Breadth First Search
Breadth First Search (Algorithm)
:
Link to original
- Select root vertex and add to a Queue (ADT)
- While queue is not empty:
- Inspect first element in queue
- Add unvisited neighbours of to queue
- Remove from queue
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:
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":[5,6,7,8,9,10,11,12,13,14,15,16],
"scale":1.5
}Algorithm: Depth First Search
Depth First Search (Algorithm)
:
Link to original
- Select root vertex and add to a Stack (ADT)
- While stack is not-empty:
- Inspect top element on the stack
- Add any unvisited neighbours of to the stack
- Remove from the stack
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
}