Week 6
What's up everyone I'm back. I was struggling for awhile whether I should write this blog or not. As I mentioned last week, my first CSC148 assignment is due tomorrow. Although my partner and I already had some clue on how to write the Tour.py, we have not written it out yet so we won't know if the codes will work or not. However, I felt that really need a break from the intense programming so I'm writing this blog now. (FYI I'm programming with my partner at Bahen now and we are ready to pull a all nighter) Please forgive me if this blog is not as good as the previous blog that I've written.
oh ya. I've made all my lectures on time this week!!!!!!!! and I'm glad that I made them because a new and interesting topic was introduced this week, which was Trees. Yes, I'm not talking about Biology or Geography class. We were learning Trees at computer science class. You can think of Trees as a special method for storing data. At this week's lectures, Binary Tree was introduced.
Let me try to explain what is a Binary Tree:
In each tree there're roots. Each root can have a left child, a right child, or none. And each child can be a root itself......... etc. As more and more data was being stored, there'll be more and more roots and children in the tree.
I think the interesting part is that we can traverse the trees in different way. Up to know, three ways of traversing were being taught. They are: Post-order traversal, In-order traversal and Pre-order traversal.
Take it this way:
Post-order traversal = visit left then right, then root
In-order traversal = visit left, root, and right
Pre-order traversal = visit root, then left, then right
For example:

post-order traversal of this will be: 2, 5, 11, 6, 7, 4, 9, 5, 2
in-order traversal of this will be: 2, 7, 5, 6, 11, 2, 5, 4, 9
pre-order traversal of this will be: 2, 7, 2, 6, 5, 11, 5, 9, 4
All of this can be done by recursion, amazing right?
This is very fun too do, and it's a good practice on recursion too. I think for the coming weeks I'll be practicing more on Trees so that I can learn how to write different functions in it. So that's it for now, I need to get back to Assignment 1. Hope we can finish it tonight!
Check for my update next week, see ya!
No comments:
Post a Comment