Algorithm-Paradigms
Question 1 |
Give short answers to the following questions:
(i) Convert the following Pascal statement to a single assignment statement:
if x > 5 they y:=true else y:=false;(ii) Convert the Pascal statement repeat S until B; into an equivalent Pascal statement that uses the while construct.
(iii) Obtain the optimal binary search tree with equal probabilities for the identifier set (a1, a2, a3) = (if, stop, while)
(iv) If a finite axiom system A for a theory is complete and consistent, then is every subsystem of A complete and consistent? Explain briefly.
Theory Explanation. |
Question 2 |
Given below are some algorithms, and some algorithm design paradigms
A. Dijkstra’s Shortest Path 1. Divide and Conquer B. Floyd-Warshall algorithm to 2. Dynamic Programming compute all pairs shortest path C. Binary search on a sorted array 3. Greedy design D. Backtracking search on a graph 4. Depth-first search 5. Breadth-first search
Match the above algorithms on the left to the corresponding design paradigm they follow Codes:
1-i, 2-iii, 3-i, 4-v. | |
1-iii, 2-iii, 3-i, 4-v. | |
1-iii, 2-ii, 3-i, 4-iv. | |
1-iii, 2-ii, 3-i, 4-v. |
Question 2 Explanation:
(1) Dijkstra’s Shortest Path using to find single source shortest path. It is purely based on Greedy technique because it always selects shortest path among all.
(2) → All Pair shortest path algorithm is using Dynamic Programming technique. It takes worst case time complexity is O(|V|3) and worst case space complexity is O(|V|2).
→ The Floyd–Warshall algorithm is an algorithm for finding shortest paths in a weighted graph with positive or negative edge weights (but with no negative cycles).
→ A single execution of the algorithm will find the lengths (summed weights) of the shortest paths between all pairs of vertices. Although it does not return details of the paths themselves, it is possible to reconstruct the paths with simple modifications to the algorithm.
(3) Binary search on a sorted array:
Search a sorted array by repeatedly dividing the search interval in half. Begin with an interval covering the whole array. If the value of the search key is less than the item in the middle of the interval, narrow the interval to the lower half. Otherwise narrow it to the upper half. Repeatedly check until the value is found or the interval is empty.
(4) Backtracking search on a graph uses Depth-first search
(2) → All Pair shortest path algorithm is using Dynamic Programming technique. It takes worst case time complexity is O(|V|3) and worst case space complexity is O(|V|2).
→ The Floyd–Warshall algorithm is an algorithm for finding shortest paths in a weighted graph with positive or negative edge weights (but with no negative cycles).
→ A single execution of the algorithm will find the lengths (summed weights) of the shortest paths between all pairs of vertices. Although it does not return details of the paths themselves, it is possible to reconstruct the paths with simple modifications to the algorithm.
(3) Binary search on a sorted array:
Search a sorted array by repeatedly dividing the search interval in half. Begin with an interval covering the whole array. If the value of the search key is less than the item in the middle of the interval, narrow the interval to the lower half. Otherwise narrow it to the upper half. Repeatedly check until the value is found or the interval is empty.
(4) Backtracking search on a graph uses Depth-first search
Question 3 |
Match the following:
(P) Prim's algorithm for minimum spanning tree (i) Backtracking (Q) Floyd-Warshall algorithm for all pairs shortest paths (ii) Greedy method (R) Mergesort (iii) Dynamic programming (S) Hamiltonian circuit (iv) Divide and conquer
P-iii, Q-ii, R-iv, S-i | |
P-i, Q-ii, R-iv, S-iii | |
P-ii, Q-iii, R-iv, S-i | |
P-ii, Q-i, R-iii, S-iv |
Question 3 Explanation:
Prim’s algorithm always select minimum distance between two of its sets which is nothing but greedy method.
Floyd-warshall always changes it distance at each iteration which is nothing but dynamic programming.
Merge sort in merge sort first we always divide and merge to perform sorting hence divide and conquer.
Hamiltonian circuit used to reach the entire vertex once, if some vertex is repeating in its path it will backtrack.
Floyd-warshall always changes it distance at each iteration which is nothing but dynamic programming.
Merge sort in merge sort first we always divide and merge to perform sorting hence divide and conquer.
Hamiltonian circuit used to reach the entire vertex once, if some vertex is repeating in its path it will backtrack.
Question 4 |
Which of the following is not a paradigm for designing algorithms?
Greedy Method | |
Divide and Conquer | |
Functional Programming | |
Dynamic Programming |
Question 4 Explanation:
Greedy method,Divide and conquer , Dynamic programming are the designing paradigm but functional programming is not any designing paradigms.
Question 5 |
Match the following typical example problems with suitable algorithm-design paradigms
A: Minimal Spanning Tree
B: Binary Search Algorithm
C: Depth-First Search
D: Optimization
I: Divide and Conquer
II: Greedy Method
III: NLP
IV: Backtracking
A-II, B-I, C-IV, D-III
| |
A-III, B-II, C-IV, D-I
| |
A-III, B-I, C-IV, D-II
| |
A-IV, B-I, C-II, D-III |
Question 5 Explanation:
A. Minimal spanning tree is a greedy algorithm.
B. Binary Search algorithm is a divide and conquer strategy.
C. Depth first search algorithm is a backtracking method.
D. Optimization is a NLP method.
B. Binary Search algorithm is a divide and conquer strategy.
C. Depth first search algorithm is a backtracking method.
D. Optimization is a NLP method.