Tutor Time

            Tutor Time By Ashur Baroutta 


    This week I spent a good bit doing a CSC program in order to better teach it to CSC205 students looking for help from the tutor center. The program is called ExpTree, its a tree data structure that holds symbols in each node. When the symbols of all the nodes are combined they form an arithmetic expression.

The students are given a file and instructed to write the code for 3 methods that either return the number of all nodes, the number of "+" symbols in the tree, and the value of the expression that forms the tree. The methods must use recursion to achieve these goals. 

The method for the number of nodes requires us to first check if the node is empty as if it is we return 0, and if it isnt we return 1 plus the recursive method call for each left and right of that given node passed. 

Finding the amount of plus operators within the tree is kind of similar in that we are going to return a value and recursive method calls to check the left and right nodes. So again we start by checking if our node is currently null (returning 0 if it is), else if our node contains a plus operator we return 1+our recursive calls. If the current node is not null and does not contain a plus operator, we return 0 + our left and right recursive calls. 

The evaluate method is the one that takes the most leg work but it helps to understand the recursion calls will hit in order if we setup our conditions correctly. The code for the evaluate method is as follows. 


In spirit is the same type of work we've been doing in the other methods but it is a clear step up in thought process, especially if one doesn't know how the recursive calls work. Even when you do, if you aren't privy to how autoboxing/unboxing works in JAVA the last return statement that actually outputs the value of the expression would never had came to mind. 

Super fun program.

Comments

Popular posts from this blog

IP #6 : Reversing an Integer

IP#5 : LinkedList Removing Duplicates II