Sie sind auf Seite 1von 5

OPTIMAL MERGE PATTERN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

Algorithm Tree(n)
//list is a global list of n single node
//binary trees
{
for i:=1 to n-1 do
{
pt:=new treenode; // Get a new tree node.
(pt->lchild):=Least(list); //Merge two trees with
(pt->rchild):=Least(list); //smallest lengths.
(pt->weight):=((pt->lchild)->weight)
+((pt->rchild)->weight)
Insert(list,pt);
}
return Least(list); //Tree left is in list is the merge tree.
}

HUFFMAN ENCODING

1. Initialization: Put all nodes in an OPEN list, keep it sorted at


all times (e.g., ABCDE).
2. Repeat until the OPEN list has only one node left:
(a) From OPEN pick two nodes having the lowest
frequencies/probabilities, create a parent node of them.
(b) Assign the sum of the children's frequencies/probabilities to
the parent node and insert it into OPEN.
(c) Assign code 0, 1 to the two branches of the tree, and delete
the children from OPEN.

JOB SEQUENCING WITH DEADLINE


1) Sort all jobs in decreasing order of profit.
2) Initialize the result sequence as first job in sorted jobs.
3) Do following for remaining n-1 jobs
If the current job can fit in the current result sequence
without missing the deadline, add current job to the
result.
Else
ignore the current job.

Das könnte Ihnen auch gefallen