Sunday, 16 March 2014

         This week I completed my homework exercise #3 - part a and b. I found part b to be easier. For this I used 3 functions to help with the main function sum_to_deepest which had to return the sum to the keys from the root to the deepest levels leaves in a TreeList. As for part a, the function make_tree had to construct a tree when given the a preorder list and an inorder list. To start, I created the functions preorder and inorder which took a TreeList as their parameters and then returned the corresponding preorder and inorder list. This helped when making the example calls and helped to better visualize the tree. The function make_tree consisted of many conditions to satisfy all the simpler possibilities, and then recursion was used to satisfy the more complex trees. Part a took the longest because I had to understand exactly what was happening with diagrams. In the lab, I continued to alter linked lists by doing the same things in various different ways. In the lectures, we learned about sorting a list using various sorting methods and considering their base case, worst case, and predicting how well they run with lists of different sizes. 

No comments:

Post a Comment