Friday, February 28, 2014

Recursion

Between week four and week seven, CSC148 focused on recursion. Beforehand, I had no experience with recursive functions and only heard simple descriptions of it in 108 and 165. Back in week four, I read the assigned reading to get a basic understanding of what was to come in the following weeks. It gave a helpful definition of the term, saying that it means "“defining something in terms of itself” usually at some smaller scale, perhaps multiple times, to achieve your objective." We can deduce that a recursive function calls itself within its body until it reaches its base case to achieve the correct result. It's basically when an active function uses itself over and over again to return an end.

For instance, in one of its simplest applications, recursion can be used on a nested list to return information about it, such as the amount of items within it, the sum of integers within it, its depth, among the infinite number of other possibilities. My first real challenge with recursion was during step 5 of A1, where you had to move all the cheese from the first stool to the last in a minimal amount of moves. Although it took a really long time to figure out, I was very satisfied with the fact that I was able to accomplish it.  The tree emphasized during week six was a key example of recursive structures. It presented the use of recursion and object-oriented programming* together.

I believe that the advantage of recursion is that it allows us to write fast and optimized code, whereas writing for an assignment/exercise without recursion may lead to a longer runtime. Plus, we can even use recursion for abstract data types, which proved to be useful in week seven's lab.
Recursion is definitely more challenging that object-oriented programming. While OOP was just about writing simple classes and their methods, recursion makes us thinking deeper about how we want to achieve results and if there are faster ways to do it. Although it's taking longer for it to sink in, its practicality is motivating me to keep trying.

*Object Oriented Programming

Thursday, February 13, 2014

Week 6

(This is a tree)
Hello fellow pythonista! Week 6 was full of challenges and fun, while our heads ached from A1.This week's slides focused once more on recursion. As the weeks go by, I start to worry more about writing recursive code on the midterm, but I'll leave those thoughts for reading week. Usually I would look at the slides and panic but this week's weren't as frightening! We talked mostly about terminology of recursive structures. For instance, Heap showed us this example called a tree which contain nodes, with one parent, that can be in a sequence by following paths. There are other terms including  height, being the maximum path length of the tree, and leaves which are nodes without children, but I wont name them all. Following this explanation of trees, we went through tree traversal! We learned about pre-order, in-order, and post-order traversal, which I'll have to study a bit. So far they look like ways of sorting values in a tree, regarding their height and location. The remaining parts of the Wednesday's lecture focused on methods that could be implemented on a Tree class, such as __repr__, sum, and height.
This week's lab was super easy! It required us to understand built-in methods such as all, any, filter, etc., but didn't require us to use them at all; we only had to break them down. Thus, we finished early and I gave myself a pat on the back. One extra thing it familiarized me with was test cases. Every time I saw that we had to make test cases, I cringed, but I feel like I can do them now.
One huge topic among 148 students this week was A1. I spent hours doing it, and I'm proud for finishing it as well as I could, but getting there was a long progress. I spent a lot of time looking at the handout for step 5, and though I couldn't get the best number of moves for all number, I think I got them close enough to get a good amount of credit. Anyways, that's all I have to say for this week.
See y'all after reading week!

Wednesday, February 5, 2014

Week 5

Hola pythonista! It's week 5! Now that this week's lectures are over, let's take a walk down memory lane to see what we've learned.
So this week we dove deeper into recursion as well as it's importance in A1. Honestly, Monday's lecture could have been really helpful, but I didn't read the A1 handout until Tuesday so I wasn't sure what he was talking about. Looking back at the lecture slide, it looks like I'll be able to use it to my advantage when I'm actually working on A1. During Wednesday's lecture, Prof Heap went over namespace and rec_max, another example of recursion. I think I'll have to read more about what we've learned this week because I don't feel comfortable enough with it yet.
This week's lab focused on tracing and recursion. Overall, the tasks were pretty easy. My partner and I took down the tracing challenge like we've been doing it our wholes lives. The last two parts needed us to create recursive code. At first we didn't know what to do, and slowly enough we had a chunk of terrible code. But, our TA gave us a hint and made us realize that we only had one mistake that wouldn't let us return anything! (Yay for TAs) For the second part, we used an example from class to guide us and we finished it in two minutes. I definitely feel a lot better with recursion now because I had no idea what I was doing beforehand.

Sunday, February 2, 2014

Week 4

Hello there you fabulous pythonista! This week Danny Heap gave lectures about recursion. As stated by one of the week's readings, "Recursion means “defining something in terms of itself” usually at some smaller scale, perhaps multiple times, to achieve your objective." Back in the first few weeks of my 148 adventure, recursion made no sense. It's still tricky to this day, but I now understand in which context I would create a recursive function. A cool/helpful example of recursion that we observed in class is the nested_depth function, where it returns an int according to the depth of nested lists in a list. Ex: list = [1, [2, 3, [4], 5], 6, 7]. If say nested_depth(list), it will return 2.
Week 4's lab was pretty swaggie. It helped my partner and I to design classes and to create complex methods. Although it was pretty easy and we were going considerably fast, our TA wouldn't explain how to use inheritance. So we sat there and surfed the web to find an explanation, but we never found a solution. Thus I need to learn how to do that really soon before it pops up in an exercise/assignment.
At first glance, exercise 2 was scary. It was full of exceptions and I had no idea what to do, so I laid out what the final product would look like and called it a day. The next afternoon I looked at it and I was pleasantly surprised to find out that I did half of it right. With the help of readings I was able to prevail over it's threat and dominate the exercise. I might be blowing this out of proportion though, since it was fairly simple.