Inorder searching is a way of searching through binary trees, where it visits the left subtree inorder, then visits the node itself, then visits the right subtree inorder. This code is recursive. Preorder, on the other hand, is different, since the node itself is visited first, then the left subtree in preorder, then the right subtree in preorder. Finally, post-order searching is when the left subtree is visited first in postorder, then the right subtree in postorder, then the node itself. In all cases, the left subtree is always visited before the right subtree.
Furthermore, in last week's lab, we created recursive code for a binary tree. This was difficult at first, especially writing the recursive part of the code. In order to create recursive code, you must first understand the most basic and simplest example, which does not require recursive code. This part usually the easiest since it does not require any recursion and is just a simple 'if' statement. Afterwards, you must think of the most simplest example that does require a little recursion. After, write the recursive code for this simple recursive example. This part is much more difficult, and takes some practice and understanding. However, afterwards it becomes much more easy to write and implement recursive code. For one part of the lab last week, we had to write code to search through a binary tree without stopping at unnecessary nodes. As mentioned above, this meant we had to use the properties and ordering conditions of a binary tree already explained. This code was also recursive and was easier to understand and visualize than to write and implement. However, once the most basic example was thought of and code written for, the rest flowed naturally.
No comments:
Post a Comment