CS401A's Finals: Design & Analysis of Algrthms. Module 05 Flashcards
For final exams. (27 cards)
Definition of || What is the
- It is a general algorithm design technique that solves a problem by dividing it into several smaller subproblems of the same type, solving each of them recursively, and then combining their solutions to get a solution to the original problem.
Divide and Conquer Algorithm || Design Technique?
Definition of || What is the
- The figure below illustrates an example of a
\_\_\_\_\_\_ \_\_\_ \_\_\_\_\_\_\_ \_\_\_\_\_\_\_\_\_
in a typical case:
(A problem of size n) v > (Subproblm 1 of size n/2) v > [solution subproblm 1] v > (Subprblm 2 size n/2) v v > [soln subprblm 2] > v v [solution to original problem]
Divide and Conquer Algorithm || Design Technique?
Divide and Conquer algorithm
Definition of Divide and Conquer Algorithm
Importance of Divide and Conquer Algorithm Design Technique
- Solving difficult problems
- Algorithm efficiency
- Parallelism
- Memory Access
Application of
is a type of sorting algorithm that repeatedly divides the data in half, sorts each half separately, and combines the sorted halves into one sorted array.
Divide and Conquer Algorithm Design Technique
Merge Sort
Application of
Example:
Initial Hand:
0 1 2 3 4 5 6 [2|Q|J|7|A|10|5]
1st Split:
Divide and Conquer Algorithm Design Technique
Merge Sort
1st Split:
0 1 2 3 4 5 6 [2|Q|J|7] [A|10|5]
Application of
Example:
Initial Hand:
0 1 2 3 4 5 6 [2|Q|J|7|A|10|5]
2nd Split:
Divide and Conquer Algorithm Design Technique
Merge Sort
2nd Split:
0 1 2 3 4 5 6 [2|Q] [J|7] [A|10|5]
Application of
Example:
Initial Hand:
0 1 2 3 4 5 6 [2|Q|J|7|A|10|5]
3rd Split:
Divide and Conquer Algorithm Design Technique
Merge Sort
3rt Split:
0 1 2 3 4 5 6 [2|Q] [J|7] [A|10] [5] 0 1 2 3 4 5 6 [2] [Q] [J] [7] [A] [10] [5]
Application of
Example:
Initial Hand:
3rd Split:
0 1 2 3 4 5 6 [2] [Q] [J] [7] [A] [10] [5]
1st to 3rd Merge:
Divide and Conquer Algorithm Design Technique
Merge Sort
1st to 3rd Merge:
[2] [Q] [J] [7] [10|A] [5] [2|7|J|Q] [5|10|A] [2|5|7|10|J|Q|A]
Application of
is a type of sorting algorithm in which the main idea is to partition the array into two (2) regions: small items are moved to the left side of the array and large items are moved to the right side. After partitioning, the sort is repeated on the left and right sides.
Divide and Conquer Algorithm Design Technique
Quick Sort
Application of
is a type of search algorithm that is used to locate an element in an ordered array. It is advisable to use it whenever the list starts to become larger.
Divide and Conquer Algorithm Design Technique
Binary search
Application of
The steps of the Binary search starts by
testing the target.
If the target is equal to the middle item,
quit.
Otherwise:
Divide and Conquer Algorithm Design Technique
The steps of the \_\_\_\_\_\_ \_\_\_\_\_\_
starts by
If the target is equal to the middle item,
Otherwise:
1. Divide the array into two sub-arrays about half as large. If the target is smaller than the middle item, choose the left sub-array. If the target is larger than the middle item, choose the right sub-array.
2. Divide (Solve) the sub-array by determining whether the target is in that sub-array. Unless the sub-array is sufficiently small, use recursion to do this.
3. Obtain the solution to the array from the solution to the sub-array.
Application of
The steps of the Binary search starts by testing the target. If the target is equal to the middle item, quit. Otherwise:
1. Divide the array into two sub-arrays about half as large. If the target is smaller than the middle item,
If the target is larger than the middle item,
Divide and Conquer Algorithm Design Technique
-
Divide the array into two sub-arrays about half as large. If the target is
\_\_\_\_\_\_\_ \_\_\_\_ \_\_\_ \_\_\_\_\_\_ \_\_\_\_
,
choose the left sub-array.
If the target is \_\_\_\_\_\_ \_\_\_\_ \_\_\_ \_\_\_\_\_\_ \_\_\_\_
,
choose the right sub-array.
Application of
The steps of the Binary search starts by testing the target. If the target is equal to the middle item, quit. Otherwise:
2. Divide (Solve) the sub-array by determining whether the target is in that sub-array. Unless the sub-array is sufficiently small,
Divide and Conquer Algorithm Design Technique
use recursion to do this.
Application of
The steps of the Binary search starts by testing the target. If the target is equal to the middle item, quit. Otherwise:
3. Obtain the solution to the array from the
Divide and Conquer Algorithm Design Technique
solution to the sub-array.
Application of
is a type of tree data structure in which no node can have more than two (2) subtrees. In other words, a node can have zero, one, or two subtrees. These subtrees are designated as the left subtree and right subtree.
Divide and Conquer Algorithm Design Technique
Binary Tree
Application of
requires that each node of the tree be processes once and only once in a predetermined sequence.
Divide and Conquer Algorithm Design Technique
Binary tree traversal
Application of
The \_\_\_
(_
) general approaches to the traversal sequence are as follows:
Divide and Conquer Algorithm Design Technique
two (2)
* Depth-first traversal
* Breadth-first traversal
Application of
The
general approaches to the traversal sequence are as follows:
is where the processing proceeds along a path from the root through one child to the most distant descendent of the first child before processing a second child.
Divide and Conquer Algorithm Design Technique
- Depth-first traversal
Application of
The
general approaches to the traversal sequence are as follows:
In other words, in the \_\_\_\_\_\_\_\_\_\_\_
search \_\_\_\_\_\_\_\_\_
, all of the descendants of a child are processed before going on to the next child.
Divide and Conquer Algorithm Design Technique
depth-first search traversal
Application of
\_\_\_\_\_
(_
) types of depth-first search binary tree traversal
Divide and Conquer Algorithm Design Technique
Three (3)
preorder traversal
inorder traversal
postorder traversal
Application of
types of depth-first search binary tree traversal
the root is visited first and successively moving to the left subtree until a leaf is reached, visiting each node on the way there.
Divide and Conquer Algorithm Design Technique
In the preorder traversal,
Application of
types of depth-first search binary tree traversal
Once there are no more children on the left of a node, the children on the right subtree are visited.
Divide and Conquer Algorithm Design Technique
In the preorder traversal,
Application of
types of depth-first search binary tree traversal
the left node is visited first, and subsequently visits the parent of that node.
Divide and Conquer Algorithm Design Technique
In the inorder traversal,
Application of
types of depth-first search binary tree traversal
It then goes to the child on the right and finds the leftmost node in the tree to visit.
Divide and Conquer Algorithm Design Technique
In the inorder traversal,