Uploaded by basilalzhrany999

Assignment 3

advertisement
KING ABDULAZIZ UNIVERSITY
Faculty of Computing & Information Technology
Computer Science Department
CPCS 324: Algorithms and Data Structures II
Assignment 3: Fall 2023
Due date: Thursday, 16 November 2023
Question:
1
2
3
4
Total
Max. Marks
25
25
25
25
100
Obt. Marks
Q. No. 1: Given the following characters along with their Probabilities:
Construct final Huffman’s tree for these characters.
(10 points)
What are the codes for a, b, c, d, e, and f
(3 points)
Find the expected coding length for the message “badfeed”.
(3 points)
What is the compression ratio if we use fixed length encoding for the same alphabets.
(3 points)
e) Enocde the message “badfeed”.
(3 points)
f) Decode the message 1010111110001001101.
(3 points)
a)
b)
c)
d)
Solution:
Q. No. 2: Apply Prim’s algorithm on the following graph to find minimum spanning tree, assuming that
vertex ‘a’ is the source vertex.
(25 points)
Solution:
VT = {a, b, c, i, f, g, h, d, e}
ET = {(a, b), (b, c), (c, i), (c, f), (f, g), (g, h), (c, d), (d, e)}
minimum spanning tree = 37
Q. No. 3: Apply Kruskal’s algorithm on the following graph to find minimum spanning tree.
(25 points)
Solution:
ET = { (h, g), (g, f), (c, i), (c, f), (a, b), (c, d), (b, c), (d, e) }
Q. No. 4: Apply Dijkstra’s algorithm on the following graph to find shortest path of all other vertices
from the source vertex ‘a’.
(25 points)
Solution:
Q = { a( - , 0), b(-,∞), c(-, ∞) , d(-, ∞) , e(-, ∞) , f(-.∞) , g(-,∞) }
VT = {a,}
Q = { b(a,1) , c(a, 5) , d(-, ∞) , e(-, ∞) , f(-.∞) , g(-,∞) }
VT = {a,b}
Q = { c(a, 5) , d(b, 9) , e(b, 8) , f(-.∞) , g(-,∞) }
VT = {a,b,c}
Q = { d(b, 9) , e(b, 8) , f(c.7) , g(-,∞) }
VT = {a,b,c,f}
Q = { d(b, 9) , e(b, 8) , g(f,19) }
VT = {a,b,c,f,e}
Q = { d(b, 9), g(f,19) }
VT = {a,b,c,f,e}
Q = { g(f,19) }
VT = {a,b,c,f,e,g}
Download