Name an application of breadth-first search
Finding the shortest path for an unweighted graph
Name an application of depth-first search
Navigating a maze
2 differences between depth-first traversal and breadth-first traversal
DF: Chooses to explore the most recent node to be discovered
BF: Chooses to explore the least recent node to be discovered
DF: Implemented using a stack (when implemented iteratively)
BF: Implemented using a queue (when implemented iteratively)
Depth-first traversal algorithm (beyond spec)
Each node has a binary flag discovered which is updated whenever we pop a node off the stack and consider its neighbours
discovereddiscoveredBreadth-first traversal algorithm (beyond spec)
Each node has a binary flag discovered which is updated whenever we dequeue an item and consider its neighbours
discovereddiscoveredWhat is tree traversal?
Visiting the nodes of a tree in a specific order
Use of pre-order traversal
Copying a tree
2 uses of in-order traversal
2 uses of post-order traversal
Pre-order traversal operation
In-order traversal operation
Post-order traversal operation
3 advantages of RPN
Steps for converting postfix to infix (2*)
Steps for converting infix to postfix (3•)
Steps for linear search on a list
(use an indefinite while loop!)
Steps for binary search on a value X (in English)
What is the while condition when coding binary search?
lower<= upper && !found
What does it mean if you reach a leaf node before you find X in a binary tree search?
X is not in the tree
Why is space complexity important to consider when analysing binary tree search?
Because the algorithm is recursive, it places a demand on the call stack
Bubble sort (ascending order) pseudocode on array A
N ← length(A)swapped ← Truewhile swapped and N > 1:
__swapped ← False
__for position = 0, 1, ... , N-2:
____if A[position] > A[position+1]:
______swap( A[position] , A[position+1])
______swapped ← True
__N ← N-1
Merge sort complexity
O(n log n)
What is an algorithm?
A sequence of unambiguous steps that can be followed to complete a task and that always terminates
2 reasons why smaller time complexity is better