TreeCoding using heap concept