binary trees the recbuildtree(method takes two argumentsa reference to the current node and queue containing the tokens that have yet to be processed the use of the queue is the easiest way to keep track of the tokens throughout the recursive process we indicated earlier that the expression will be supplied as stringbut strings in python are immutablewhich makes it difficult to remove the tokens as they are processed the queuewhich was introduced in is the best choice since the tokens will be processed in fifo order the non-recursive buildtree(method creates queue and fills it with the tokens from the expressionas shown in lines - of listing the code in this method can actually be placed within the constructor we only used this helper method in order to hide the tree construction details in the initial presentation of the expressiontree class in listing until the actual operation was presented the recursive function assumes the root node has been created before the first invocation thusafter building the token queue in buildtree()an empty root node is created and the two structures are passed to the recursive function the recbuildtree(method implements the five operations for building the expression tree as described earlier if you review those stepsyou will notice the only times we descend down the tree is after encountering left parenthesis or an operator after moving down to either the left or right child nodethe next token encountered must be either left parenthesis or an operand thusthe function extracts the next token to be processed and then evaluates it to see if it is either or an operand if the token is an operandwe can set the data field of the current node with the integer value of the token and then return this takes us back to the parent of the current node the bulk of the work is done when left parenthesis is encountered the same sequence of stepsas shown in lines - is always performed since we are only working with binary operators firsta new left child is created and we descend down to the new node by making recursive call upon returning to this invocation of the functionwhich represents the parent of the new nodethe next token must contain an operator it is removed from the queue and assigned to the current node' data field new right child is then created and again we descend down to the new node to process the right side of the operator finallywhen the second recursive call returnsthe next token will be right parenthesiswhich can removed from the queue and discarded heaps heap is complete binary tree in which the nodes are organized based on their data entry values there are two variants of the heap structure max-heap has the propertyknown as the heap order property that for each non-leaf node the value in is greater than the value of its two children the largest value in max-heap will always be stored in the root while the smallest values will be stored in the leaf nodes the min-heap has the opposite property for each non-leaf node the value in is smaller than the value of its two children figure illustrates an example of max-heap and min-heap