ada greedy
TRANSCRIPT
-
7/24/2019 Ada Greedy
1/5
OPTIMAL MERGE PATTERN1 Algorithm Tree(n)
2 //list is a global list of n single node3 //binary trees
4 {
5 for i:=1 to n-1 do
{
! "t:=ne# treenode$ // %et a ne# tree node&
' ("t-lhild):=*east(list)$ //+erge t#o trees #ith
, ("t-rhild):=*east(list)$ //smallest lengths&
1 ("t-#eight):=(("t-lhild)-#eight)
11 .(("t-rhild)-#eight)
12 nsert(list0"t)$
13
14 retrn *east(list)$ //Tree left is in list is the merge tree&
15
HUFFMAN ENCODING
-
7/24/2019 Ada Greedy
2/5
1& nitialiation: t all nodes in an 67 list0 8ee" it sorted at
all times (e&g&0 A9;6)&
2& ing the lo#est
fre?enies/"robabilities0 reate a "arent node of them&
(b) Assign the sm of the hildren@s fre?enies/"robabilities tothe "arent node and insert it into 67&
() Assign ode 0 1 to the t#o branhes of the tree0 and delete
the hildren from 67&
-
7/24/2019 Ada Greedy
3/5
-
7/24/2019 Ada Greedy
4/5
JOB SEQUENCING WITH DEADLINE
1) ort all Bobs in dereasing order of "roCt&
2) nitialie the reslt se?ene as Crst Bob in sorted Bobs&
3) ;o follo#ing for remaining n-1 Bobs
f the rrent Bob an Ct in the rrent reslt se?ene
#ithot missing the deadline0 add rrent Bob to the
reslt&
6lse
ignore the rrent Bob&
-
7/24/2019 Ada Greedy
5/5