(P1) Fundamentals of Algorithms Flashcards
What is graph traversal?
The process of visiting each vertex in a graph.
What are the two graph traversals?
Depth-first and breadth-first.
Describe depth-first traversal.
A branch is fully explored before backtracking.
Uses a stack and is used navigating mazes.
Describe breadth-first traversal.
A node is fully explored before venturing on the next node.
Uses a queue.
Used for determining the shortest path on an unweighted graph.
What is an algorithm?
A set of instructions which completes a task in a finite time and always terminates.
What is a tree?
A connected acyclic graph.
Describe tree traversal.
Process of visiting each node in a tree.
Unique to trees and must start at the root.
Where should the dot be drawn for a pre-order traversal?
Left.
Where should the dot be drawn for a in-order traversal?
Bottom.
Where should the dot be drawn for a post-order traversal?
Right.
What can pre-order traversal be used for?
Copying trees.
What can an in-order traversal be used for?
Used in binary trees to outputs the contents of a binary tree in ascending order.
What can post-order traversals be used for?
Infix to RPN conversions.
Producing a postfix expression from an expression tree.
Emptying a tree.
How are Infix to RPN and binary trees related?
Infix to RPN involve the making and traversing of a binary tree.
What is an opcode?
An operator.
What is an operand?
Data which is applied to the operator.