Wednesday, 9 March 2016

Week 8: Absorbing the CS in me

As we progress in the course, we are now starting to learn new ways to organize data and objects in python in more efficient and organized manner. This week, we were introduced the data structure of Binary Tree. A binary tree has an arity of 2. It has a value in it's own node, where it has a left ad a right child and the tree continues. We implemented this tree with __eq_, __str__, and __repr__ while making a functionality of determining if  a node exists or not with a specific value in it. We even went and created arithmetic expression trees where there are arithmetic symbols '+', '-', '*', or '/' and that is applied on the values of the node and hence used to solve the tree. This way of organizing objects was quite interesting to me where I was witnessing that there are so many ways of collecting data in an efficient manner.

Not only implementing the binary tree, we also went in depth of how to get the data in the binary trees in different manner 'traversal'. In traversal, there were three ways of fetching objects from the tree. First being the 'inorder' which would get the left node first, then the parent node, and then finally the right node. This would be done recursively until reached the end of the tree. Second method was called 'preorder' where the order was a bit different. Here, first the parent node would be fetched, then the left node and finally the right one. Finally, the third method was known as 'postorder' where the objects were fetched in left most node, then right most node and finally the parent of those nodes order. Doing all this really made me feel like a CS student (one who is smart) and where computer science is no more just about coding and more about the science behind the code and writing the code in an efficient manner.

Finally, we also went over binary search trees which the same as binary trees but BST (binary search trees) with n nodes may have height 'int(lg n) + 1' as the best case (a more balanced tree) If a BST node has a left child, the left child's value is always smaller than the node's right child and vice versa. Moreover, we also learned to implement BST with an insert method which would place the object in the tree in that very order. Overall, this week made me feel like a true CS student who is now officially dealing with subject which are more concerned about efficiency than the code (high school)

No comments:

Post a Comment