Friday, 25 October 2013

Exercise 5 Problems!


I am still currently working on exercise 5 that is due at midnight tonight. I have completed my code for e5a.py, and I got full marks for it. However, e5b.py is giving me quite a bit of trouble. I understand what should be returned from the leaves_and_internals function, and I understand which items in BTNode are leaves (items that have no children) and which are internals (items that have at least one child). Here is an example of what is produced when I test my code in the shell:

>>> a = BTNode(3, BTNode(4, None, BTNode(1)), BTNode(6, None, BTNode(9)))
>>> a.leaves_and_internals
<bound method BTNode.leaves_and_internals of <__main__.BTNode object at 0x102f346d0>>

I have no idea why a.leaves_and_internals returns what it returns, when in my code, I made it return (leaves, internals).

Anyways, I will continue to work on e5b.py for the rest of the evening, and hopefully I can figure out what I am doing wrong!

Wednesday, 16 October 2013

Test 1 and Exercise 4!


Today was Test 1 for CSC148. I was extremely nervous about it, and I was especially scared that TreeLists would be on it. I understand the concept of trees, but I just get confused with pre-order and in-order. I’m also confused with the TreeList function that we have to write for Exercise 4. I know how to determine the root and subtrees, however, for e4a.py, I’m not sure how to determine whether a leaf is in Element 1 or 2. For example, if I’m given the pre-oder [10, 6, 8, 12, 11, 15] and the in-order [8, 6, 12, 10, 11, 15], I’m not sure if make_tree( [10, 6, 8, 12, 11, 15], [8, 6, 12, 10, 11, 15]) should produce:

[10, [6, [8, None, None], [12, None, None]], [11, None, [15, None, None]]]
or
[10, [6, [8, None, None], [12, None, None]], [11, [15, None, None], None]].

I’ve asked this question on piazza and I am waiting for a reply.

Continuing my review of Test 1, I didn’t find it too difficult. Question 1 confused me a lot at first, simply because it returned the minimum of the tuple for a given range. At first I thought that this meant that I had to calculate the expression, then find the minimum number in the tuple, and return that number for each i in range(1, n). Later, I realized that I was wrong, and the question was in fact asking to calculate the expression for each i in range(1, n), and then find the smallest tuple and return that tuple. I think and hope that I got the correct answers for Question 1!

Saturday, 12 October 2013

Object-Oriented Programming and Recursion


The topics this week are Object-Oriented Programming and Recursion.

Object-Oriented Programming is when one programs code, using objects. Object-Oriented Programming is very useful for computer scientists since it allows for the programmer to use past methods or functions, and implement them into new code. I other words, by using objects, computer programmers can avoid repetition in their code since they can use their previous work to create new functions. I find using objects in code to be very helpful.

Now recursion is something new to me. I can define recursion to be when a function calls itself, which can be quite confusing. It took me awhile to wrap my brain around this idea and I am still not confident about my knowledge on the subject. Recursion can be useful when solving a very long problem since it breaks down the problem into smaller pieces that are easier to solve, then puts them together to solve the overall problem. 

Assignment 1


This past Tuesday, the first assignment for CSC148 was due. I had a pretty hectic week last week, so I did not start the assignment until Saturday evening. This was a huge mistake. I did not realize how much time the assignment would take, and I got stuck on Step 3. Step 1 of the assignment took me much longer than I expected it to, but I found Step 2 to be very simple. When I got to Step 3, that’s when most of my problems began. I was confused as to what each function actually did, which made writing them quite difficult. It was hard to implement each function since all I could figure out about what each one did was from how they were used in ManualController.py. I had particular trouble with the move function and how to implement it. I was able to write some code for each function, but when I tested out my code by running ManualController.py, nothing but a blank blue window popped up.

I hope I submitted enough work for the assignment, even though I didn’t get past Step 3. Now I know that I need to give myself more than a few days for an assignment and I need to go to office hours when I get stuck on a particular section of the homework. I hope the second assignment goes much better!