4.3 (every spec covered) Flashcards
(60 cards)
What are the features of a breadth first graph traversal? (3)
explores graph level by level
uses a queue data structure
best for finding the shortest path in an unweighted graph
how does a breadth first search logically work (4)
Uses a queue to keep track of nodes to visit
Uses a visited set to avoid resvisiting nodes
start at first node, enqueue and mark as visited
dequeue A, Enqueues A’s unvisited neighbours
Repeat
What are the features of a depth first graph traversal?
Explores as deep along each possible branch before backtracking
uses a stack
applications include maze, puzzle solving and path finding
How does a depth first search logically work
need a stack and a visited set of nodes
step by step:
start at node 1, push 1 onto stack
pop 1, mark 1 visited, push neighbours onto stack
pop neighbour at the top of stack push unvisited neighbours of that stack
repeat until there are no unvisited neighbours
pre order tree traversal order
Node, Left, Right -
post order tree traversal
Left, Right, Node -
in order tree traversal and when its used (1)
Left, Node, Right -
Used in binary search trees
What is Meant by O(N)
O represents the order of complexity
N represents the number of inputs
What are the factors of complexity used in big o notation
Memory used, time clompexity
Time complexity of linear search
O(n)
Time complexity of Binary/Binary tree search
O(log n).
Time complexity of Bubble sort
O(n^2).
Time complexity of Merge sort
O(n log n).
What is djikstras algorithim?
Finds the shortest path between one node and all other nodes on a weighted graph.
It is considered a type of breadth first algorithim
What does it mean when algorithims are tractable?
These are problems that have a polynomial (or less) time solution (x^2)
What is it when an algorithim is intractable?
These are problems that have solutions in greater than polynomial time
What methods are used when tackling intractable problems
Heuristic methods
How do we trace a graph depth first
Start at a root and follow one branch as far as it will go. (using stack)
How do we trace a graph breadth-first
start at root scan every node connected and then continue scanning from left to right (using queue)
What are heuristic methods
give 2 examples
practical approaches used when finding an optimal solution is impractical or impossible due to time constraints
For example trial and error, pattern recognition
Describe the traversing of a graph breadth first using a queue
Set the root node as current node
Add current node to list of visited nodes
For every edge connected to that node enqueue the linked node
Then dequeue the current node and move front pointer up by one and repeat steps with the new current node
output all visited nodes
Describe the traversing of a graph depth frist using a stack
Visited nodes are pushed onto the stack, when there are no nodes left to visit the nodes are popped off the stack.
what does a depth first graph traversal give us
Suitable solutions for game or puzzle problems
what does an inorder traversal tell us