In week 7, the professor covered the concept of linked lists. A linked list is a recursive data structure that is made up of connecting nodes. Each node contains a reference to the next node in the list. As usual, when I was first introduced to this concept in class, I found it quite confusing and hard to understand. But after reading over it again and visualizing it in my mind and on paper, I was able to make sense of how it worked. Asking the professor also helped.
To teach this concept, the professor created a class called BTNode, which had 3 attributes: data, left, and right. Data is the root node, and left and right represent the children of data. He then showed us some methods that used these attributes along with some additional ones to create representations of this class. Again, this was confusing for me at first, as the code seemed complicated and odd to be able to create some form of a visual representation of the nodes in the class. An example of this is the __str__ method. It involved indenting in order to distinguish the children and space them out. I wonder how people can figure out how to code this, as it seems so complicated for me to code. I can visualize it and draw it on paper easily, but when I have to translate it into code, it seems like a burden.
The professor also showed us how arithmetic expression trees are represented. The values in nodes don't necessarily have to be numbers. They can even be operators, such as the ones in the tree below(a representation):
7.0
+ 4.0
*
3.0
The professor also showed us how to evaluate a binary expression tree, using the eval() function. I found this particularly interesting and useful as it simplifies the job of evaluation by combining the values in the nodes into one single string expression and evaluating that expression.
Furthermore, we were shown how to evaluate a binary search tree inorder, preorder and postorder. Additionally, our professor showed us added ordering conditions to a binary tree, and were taught how to check if a value was in a tree by calling a recursive function on the tree. Overall, I found this lecture interesting, but I do find the course becoming progressively more challenging. However, I try to curb this challenge by reading over concepts again and again and practicing them, and aim to continue to seek help when necessary.