Algorithm-Paradigms

Question 1

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
A
P-iii, Q-ii, R-iv, S-i
B
P-i, Q-ii, R-iv, S-iii
C
P-ii, Q-iii, R-iv, S-i
D
P-ii, Q-i, R-iii, S-iv
Question 1 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.
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:

A
1-i, 2-iii, 3-i, 4-v.
B
1-iii, 2-iii, 3-i, 4-v.
C
1-iii, 2-ii, 3-i, 4-iv.
D
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
Question 3

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.

A
Theory Explanation.
Question 4
Which one of the following algorithm design techniques is used in finding all pairs of shortest distances in a graph?
A
Dynamic programming
B
Backtracking
C
Greedy
D
Divide and Conquer
Question 4 Explanation: 
→ 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 shortest paths between all pairs of vertices
→ The Floyd-Warshall algorithm is an example of dynamic programming.
Question 5

A text is made up of the characters A, B, C, D, E each occurring with the probability 0.08, 0.40, 0.25, 0.15 and 0.12 respectively. The optimal coding technique will have the average length of :

A
2.4
B
1.87
C
3.0
D
2.15
Question 5 Explanation: 

Step 1: Select two characters with smallest probabilities and merge them.

Step 2: Select two characters from Step 1 with smallest probabilities and merge them.

Step 3: Select two characters (from Step 2) with smallest probabilities and merge them.

Step 4: Merge the remaining two probabilities.

A = 1000 (4-bits)
E = 1001 (4-bits)
D = 101 (3-bits)
C = 11 (2-bits)
B = 0 (1-bit)
There are 5 questions to complete.

Access quiz wise question and answers by becoming as a solutions adda PRO SUBSCRIBER with Ad-Free content

Register Now

If you have registered and made your payment please contact solutionsadda.in@gmail.com to get access