util.py
def read_tree(bitreader):
	'''Read a description of a Huffman tree from the given bit reader,
	and construct and return the tree. When this function returns, the
	bit reader should be ready to read the next bit immediately
	following the tree description.

	Huffman trees are stored in the following format:
	* TreeLeaf is represented by the two bits 01, followed by 8 bits
	for the symbol at that leaf.
	* TreeLeaf that is None (the special "end of message" character)
	is represented by the two bits 00.
	* TreeBranch is represented by the single bit 1, followed by a
	description of the left subtree and then the right subtree.

	Args:
	bitreader: An instance of bitio.BitReader to read the tree from.

	Returns:
	A Huffman tree constructed according to the given description.
	'''
	#since bitreader is an instance of bitio.BitReader, we use readbit() to read first bit
	first_bit = bitreader.readbit()
	#if first bit is 1 means start from 1, it is branch
	if first_bit == 1:
		#read left sub tree until reach leaf		
		leftsub = read_tree(bitreader)
		#read right sub tree until reach leaf
		rightsub = read_tree(bitreader)
		#build the huffman tree branch
		Branch = huffman.TreeBranch(leftsub, rightsub)
		return Branch

	else:
		#there is a leaf
		second_bit = bitreader.readbit()
		#if second bit is 0 means EOF reached
		if second_bit == 0:
			#build the huffman tree leaf
			Eof = huffman.TreeLeaf(None)
			return Eof
		elif second_bit == 1:
			#if second bit is 1 means there is a character, read the bits of character
			value = bitreader.readbits(8)
			#build the huffman tree leaf and store the 8 bits
			valueleaf = huffman.TreeLeaf(value)
			return valueleaf
Read a description of a Huffman tree from the given bit reader,
	and construct and return the tree. When this function returns, the
	bit reader should be ready to read the next bit immediately
	following the tree description.

	Huffman trees are stored in the following format:
	* TreeLeaf is represented by the two bits 01, followed by 8 bits
	for the symbol at that leaf.
	* TreeLeaf that is None (the special "end of message" character)
	is represented by the two bits 00.
	* TreeBranch is represented by the single bit 1, followed by a
	description of the left subtree and then the right subtree.

	Args:
	bitreader: An instance of bitio.BitReader to read the tree from.

	Returns:
	A Huffman tree constructed according to the given description.
	
Read a description of a Huffman tree from the given bit reader,
and construct and return the tree. When this function returns, the
bit reader should be ready to read the next bit immediately
following the tree description.

Huffman trees are stored in the following format:
TreeLeaf is represented by the two bits 01, followed by 8 bits
for the symbol at that leaf.
TreeLeaf that is None (the special "end of message" character)
is represented by the two bits 00.
TreeBranch is represented by the single bit 1, followed by a
description of the left subtree and then the right subtree.

An instance of bitio.BitReader to read the tree from.

A Huffman tree constructed according to the given description.
Read a description of a Huffman tree from the given bit reader and construct and return the tree . When this function returns the bit reader should be ready to read the next bit immediately following the tree description . Huffman trees are stored in the following format : TreeLeaf is represented by the two bits 01 followed by 8 bits for the symbol at that leaf . TreeLeaf that is None ( the special " end of message " character ) is represented by the two bits 00 . TreeBranch is represented by the single bit 1 followed by a description of the left subtree and then the right subtree . An instance of bitio . BitReader to read the tree from . A Huffman tree constructed according to the given description .
def read_tree(bitreader):
	first_bit = bitreader.readbit()
	if first_bit == 1:
		leftsub = read_tree(bitreader)
		rightsub = read_tree(bitreader)
		Branch = huffman.TreeBranch(leftsub, rightsub)
		return Branch
	else:
		second_bit = bitreader.readbit()
		if second_bit == 0:
			Eof = huffman.TreeLeaf(None)
			return Eof
		elif second_bit == 1:
			value = bitreader.readbits(8)
			 and store the 8 bits
			valueleaf = huffman.TreeLeaf(value)
			return valueleaf
def read_tree ( bitreader ) : first_bit = bitreader . readbit ( ) if first_bit == 1 : leftsub = read_tree ( bitreader ) rightsub = read_tree ( bitreader ) Branch = huffman . TreeBranch ( leftsub , rightsub ) return Branch else : second_bit = bitreader . readbit ( ) if second_bit == 0 : Eof = huffman . TreeLeaf ( None ) return Eof elif second_bit == 1 : value = bitreader . readbits ( 8 ) valueleaf = huffman . TreeLeaf ( value ) return valueleaf
Read a description of a Huffman tree from the given bit reader,
and construct and return the tree.
Read a description of a Huffman tree from the given bit reader and construct and return the tree .
'''Read a description of a Huffman tree from the given bit reader,
	and construct and return the tree. When this function returns, the
	bit reader should be ready to read the next bit immediately
	following the tree description.

	Huffman trees are stored in the following format:
	* TreeLeaf is represented by the two bits 01, followed by 8 bits
	for the symbol at that leaf.
	* TreeLeaf that is None (the special "end of message" character)
	is represented by the two bits 00.
	* TreeBranch is represented by the single bit 1, followed by a
	description of the left subtree and then the right subtree.

	Args:
	bitreader: An instance of bitio.BitReader to read the tree from.

	Returns:
	A Huffman tree constructed according to the given description.
	''' #since bitreader is an instance of bitio.BitReader, we use readbit() to read first bit #if first bit is 1 means start from 1, it is branch #read left sub tree until reach leaf		 #read right sub tree until reach leaf #build the huffman tree branch #there is a leaf #if second bit is 0 means EOF reached #build the huffman tree leaf #if second bit is 1 means there is a character, read the bits of character #build the huffman tree leaf and store the 8 bits
bitreader