Question: In Ocaml, the function compress takes a tree and converts it to a list of custom type comp using postorder traversal. Write a function decompress
In Ocaml, the function "compress" takes a tree and converts it to a list of custom type comp using postorder traversal.
Write a function "decompress" that restores the list back to a tree. Example at bottom.
type 'a tree
Node of a 'a tree 'a tree
Leaf
type 'a comp
No of a
Le
EXAMPLE
let t Node Leaf, Node Node Leaf, Leaf Node Leaf, Leaf
let co compress t;;
'a flat list: Le; Le; Le; No ; Le; Le; No ; No ; No
let deco decompress co;;
'a tree: Node Leaf, Node Node Leaf, Leaf Node Leaf, Leaf
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
