4.3 Fundamentals of Algorithms Flashcards
What is a Graph Traversal?
A graph traversal is a process of systematically visiting each node in a graph
What is a Breadth-first traversal?
1) A Breadth-first traversal is a method for traversing a graph that explores the nodes closest to the starting node
2) A queue is used to track the nodes to be visited (Contents of a queue)
What is a Depth-first traversal?
1) A Depth-first traversal starts at a chosen node and explores as far as possible along each branch away from the starting node before backtracking
2) Uses current node and Visited nodes on a graph
What are the three ways to traverse a binary tree and how do they work?
1) Pre-Order: Traversing by visiting the root, traversing to the left subtree and the ten traversing to the right subtree
2) Post-Order: Traversing a left subtree then a right subtree and finally visiting the root
3) In-Order: Traversing the left subtree then the root and finally the right subtree
What is the use of a Pre-order traversal?
Outputting the contents of a binary search tree in
What is the use of a Post-order traversal?
1) Emptying a tree
2) Producing a postfix expression from an expression tree
What is the use of a In-order traversal?
Outputting the contents of a binary search tree in ascending order
What is recursion?
When a function calls itself eventually unwinding when the procedure ends there must be a true condition that terminates the recursive procedure
What is Reverse Polish Nation?
1) A way of writing mathematical expression in a format where the operators are written after the operands
2) E.g. 5 + 3 becomes 5 3 +
How do you evaluate infix expressions?
1) 5 + 3
2) You add the 3 to the 5 to create the result
3) 3+ (18/3 squared * 3) -4
- Square 3 = 9
- 18/9 =2
- 2 * 3 = 6
- 3 + 6 = 9
- 9 - 5 = 4
What is a Linear Search and what is its time complexity?
1) A search for items in a file, array or memory where the data items are searched one by one until the required one is found or the end of the list is reached
What is a Binary Search and what is its time complexity?
1) A Search where the items in the list are sorted it does this by halving the search area with each execution of the loop
2) Split into the middle section and two other sections
2) Start with n items n/2 after 1 comparison n/4 2nd comparison etc…
What is the Time Complexity of a Linear Search?
0(n) = Linear
What is the Time Complexity of a Binary Search
0(log n) = Logarithmic
What is a Binary Tree Search?
1) Same Time Complexity 0 = log(n) = Logarithmic
2) On each pass half of the tree or subtree is eliminated each time its root is examined