Tuesday, 24 March 2015

A Walk To Remember...

SECOND LAST POST YA'LL ! *woot woot*

So we're almost there, I can feel the tension building up, and the caffeinated spirits seem to be on an all time high.
 The best part about slogs is that we can not only see ourselves growing in understanding through the semester but also our friends and classmates. I can definitely look back on this semester and CSC148 and say I've made some really good friends out of it and learnt something interesting. 

Keeping the title in mind, I'd like to revisit my post "More Recursion !" (it can be found here, http://mysuperslog148.blogspot.ca/2015/03/more-recursion.html ). You'd think I'd want to go back to the very beginning of semester or maybe even the beginning of the topic recursion, however I'd like to visit this particular post because while in my original recursion related post I only explained the theory behind it, here I gave an example. Now the thing about recursion is, the deeper you go, the more complex it can get, and sometimes its a simple factorial recursion code that you need to bring you back to the basics. Its easy to get deep into recursion and forget what its supposed to do or where it returns what. Though I try to keep in mind the "keep it simple" advise Diane gave us, it's still easy to forget when I'm knee deep in something like MiniMax. (ugh ugh ugh)

Since I mentioned making friends this semester, let's see what some of them have to say .. 

Cindy Quach ( my assignment partner for the whole semester ) has an interesting approach towards coding. Putting it simply, she needs good sleep and good food and bam! she's good to go. She is really fun to work with because she gets really motivated and determined to finish things off quickly.
One of her posts ( http://csc148x.blogspot.ca/2015/03/recursion.html ) shows her approach quite nicely. She believes in understanding the concepts extremely clearly and reading and analyzing each line. Here, she uses a simple example to explain recursion very accurately. 

Syeda Sidra Tul-Muntah  is another friend I've made through our common lab. She and I share a similar approach to understanding coding. Her slogs are always up to date and quite detailed. You can check them out at http://slogsbysidra.blogspot.ca/ .

So basically everyone seems to have learnt from each others' point of views, and we all seem to agree on how much we have loved this course. 

Until next time.. !

PS- That title though .. I hope people know the reference. 

PPS - Really random but all I can think of right now is the song from High School Musical 2.. summer..summer ..summer.. 

Saturday, 14 March 2015

Creeping on to the final weeks....

First things first, the test.
.
.
.
.
Honestly I'm pretty sure I bombed it. Did not expect that. I somehow forgot the basic of traversing but managed to get it right, but in the process managed to blank out on everything else. I'm really disappointed because I expected this test to go as awesomely as the first. What makes it worse is that I was highly confident about the topics on this test. Trees, BST and Linked list all seem to me like something I understand pretty well.
Maybe I underestimated it ?
Anyhow, I'm now determined to get a 100 on both assignment 3 and the final.
(Someone give me a HELL YEAH ! )

Moving on to things we learnt..

We pretty much discussed only assignment 2 and how the profs wanted us to work it. They've given us the unittests that we need to make it run. I don't remember if I mentioned this in my other posts but A2 was surprisingly annoying and I didn't do my best. (Thus my determination for A3 and final)

With this course coming to an end in a couple of weeks, all I can say is how much I appreciate the marking scheme and the planning of this course.
I'm pretty sure it's considerably different from last few years and its only for the better.

Not much to say right now except I hope the test is marked easy .. :P

Until next time ..

PS - tick tock tick tock ..end of semester came up too fast !

Tuesday, 10 March 2015

Linking Stuff...

Linked Lists !!!
I probably sound too enthusiastic but familiar terms make me happy :)

So linked lists is again something I've briefly done in high school and since its the same concept, I had a much easier time understanding.

Linked lists are basically linear sequence of nodes with a reference to the front or the head.

Linked List 

The key to understanding and doing well in linked lists is drawing it out. There's no better method. The front node here is the box with 2 and 2184 and the back node is the box with 7 and Null.
It is Null here since there is no next node to keep a reference to. The most important thing in linked lists is to know which nodes we have to keep track of. Insertion, deletion etc of nodes can get quite messy if we lose track of the nodes. This is where drawing comes in, it allows us to physically see which node needs to be connected to which other node. 

The labs for linked lists are pretty straightforward and I'm hoping to do well in linked lists related questions on the test tomorrow.

Speaking of.. test 2 ! 
With the strike in full force I'm kind of confused about how they'll mark us or if they even will. I'm hoping the strike is resolved soon with both the parties happy. I have to say not being able to actually go to labs is a bit of an inconvenience especially since our new TA seemed really helpful.

I'm all set for the test and honestly this slog was mostly just to take a break from the actual coding. 
I've discovered that I find it more helpful when I write the code down now since I've realized that it affects my performance. Depending too heavily on running the code on Wing makes me less intuitive about the logical as well as syntax errors I could be making. 

Until next time .. ! 

PS- Goodluck everyone ! :) 

Friday, 6 March 2015

All About The Trees..!

Trees.
To normal people outside of the world of CS, this word might seem completely harmless. Might even give them happy thoughts, trees..greenery .. who doesn't like that, right ? right ?

Wrong.
Because to programmers, it is like a mini nightmare in one word.
But no, don't be afraid because it's not all bad... at least not yet.
Let me tell you why...

So, like I explained in my previous post, recursion is a simple concept to understand and trace but not that easy to code. There's is a general idea to follow but unless you understand exactly how to you want your code to work, recursion won't seem like the best idea.

"A tree is a set of nodes with directed edges between some pair of nodes." These edges connect a parent node to a child node.
A specific type of tree is Binary Tree. In this type of tree each parent only has two children, the left and right. This makes navigating through the tree a little easier.
This week we learnt to traverse through a tree in order to find its height and to find if a value exists in the tree or not.
Another specific tree is the Binary Search Tree. Like it's name suggests, you search for something in a tree. The catch you ask ?
BST (we love abbreviations), has to be made in a specific order. While these specifications might make the task easier, it is slightly confusing to understand.


Binary Search Tree

This is an example to understand how the placing of numbers in a BST works.
Each node on the left has to be smaller than all the nodes on its right. As you can see, 
9 < 12<14 < 17<19 < 23.....<76.
In this way, searching for a number becomes increasingly simplified. 

As far as I understand, trees work in a certain way, which is the key to coding with recursion for trees. 

Until next time.. !

PS - Did anyone get the song reference ? *no treble*



Sunday, 1 March 2015

More Recursion !

Hey everyone, (everyone who's reading this at least)

I hope your reading week was fun, relaxing and as unproductive as mine. I think the only thing I worked on is assignment 2 with my partner Cindy (http://csc148x.blogspot.ca/ ).

Since recursion is part of the assignment this time, it only makes sense that I write about it.
 In my previous post from February 6, I mentioned what recursion is and how it is supposed to work.

In assignment 2, we use a MiniMax which is a strategy generally used to two-player games where the best possible move is chosen by both players. For this particular we need to use recursion.
Since we're not allowed to give out assignment details, I'll try to explain it as simply as possible.
Recursion calls on itself again and again till it reaches the base case or the stopping case, and in the case of Minimax, both players need to have complete knowledge of the game.
For Minimax to work, we use recursion to find out what each move will lead to and will that move end in a win or loss. So we call on our method again and again until it reaches the end of the game for each move available in that game state.

To illustrate how recursion works, I'm going to show a simple example. A simple thing to remember is that recursion works in place of iterative functions.

*****************************
def factorial (n):
    """ (int) -> int

    Return factorial of n.

    >>> factorial (4)
    24
    >>> factorial (12)
    479001600
    """
    if n == 1 :
        return 1
    else :
        return n * factorial (n-1)

*****************************

In the example, "if n == 1 " plays the role of the stopping case or base case. Once it reaches here, the recursion process stops and the values start getting returned.
When n == 4, the else condition is executed and thus factorial calls itself but this time n = 3.
This continues until n = 1 and so the value 24 is returned to the user.

While recursion as a concept is easy to understand, and even easy to trace, it isn't however easy to write.
The assignment is giving us a little bit of trouble at exactly this and we hope to figure it out soon.

Hope this made sense!

Until next time ...

PS - I hope I'm not the only one not getting this part of the assignment ! Good luck to everyone ! :)



Friday, 20 February 2015

Object-Oriented Programming !

So to start off I'd like to say, I initially thought I was writing too much and then did some checking and found out people have been writing far more than I have and far more intensely. Oops ?
Anyway, quality over quantity and all that so I'm going to continue my own thing.
Another thing I'd like to mention is how awesome were the midterm grades ???? I hope everyone did well on it and isn't mad at me for being all cheery about it !
Moving on ..

OOP !
I kind of feel a little silly writing this because let's face it if anyone wanted the definition they'd google it not look at my blog but anyway  Object-Oriented Programming makes use of several concepts all inter connected that we've been using so far in csc148 and even csc108. It revolves around the concept of Abstract Data Type and some of the important terms that one comes across in OOP are object, class, attributes, methods, and inheritance. 
Objects are data structures that contain data and can be assigned to a variable name.
Classes are basically the structure or blueprint or the base of the your program. It is used to perform actions using its methods and attributes,in a cleaner and consistent manner. For creating objects within a class we use the syntax :

                 post = blog(4 , '20th Feb 2015')

Here, 'post' is the variable used for the object,
          'blog' is the name of the class,
          '4' and  '20th Feb 2015' are both attributes 

Inheritance, like its name suggests allows one class, the subclass, to inherit the methods and attributes of another class, the parent class. This is done to avoid redundant and duplication of code. Simply put if there is one class that has methods and attributes in common with a few other classes, it would be more simpler to write that code only once and let it be inherited by the other classes.
For example :

class Worker:
    def update_salary(self, salary):
        self.total_salary = self.total_salary + salary

class HourlyWorker(Worker):
    def calc_wage(self, num_hours):
        self.wage = num_hours * 11.5

class SalaryWorker(Worker):
    def calc_salary(self, commission):
        self.salary = self.salary + (10/100)*self.salary

Here, 'Worker' is the parent class,
          'HourlyWorker' and 'SalaryWorker' are both the subclasses 
          'update_salary' , 'calc_wage' and 'calc_salary' are methods 

Both kind of workers would need their total salaries updated and so that method stays in the Parent class, however the way of calculating said salary is different and so it would be done in separate classes.
The example also shows the syntax that we use to execute inheritance.

So I hope this was simple enough to understand. I didn't try to paste actual code because I'd rather type it out here fast so I hope that didn't bother anyone.

Until next time then..

PS- Doing this during reading week took lots of coffee and a lot of motivation by my friends.
PPS - Is anyone reading this ? ...

xx

Friday, 6 February 2015

Recursion and Stacks&Queues !

So if anyone is actually reading these posts, you probably know by now that I'm not a 'formal' writer.
Especially since we're technically 'blogging', it's impossible for me to write in a style that suits an essay.
Now that that's out of the way..

Tracing Recursion !
Let me start by saying I have some experience in programming since I had C++ in high school.
So when we started recursion I had a mini panic attack. As far as I remember recursion is one of the tougher concepts and I wasn't so keen starting it.
Recursion is basically defining a function in such a way that it works for the simplest problem, and then calling itself so it then works for larger problems of the same kind. (Yes, it is as annoying as it sounds.)
Luckily for us recursion isn't on the midterm completely and only tracing is. I was disappointed in my lab exercise(test?)  since I think I got the idea but I was too hasty and messed up. Anyhow after discussing my answers with other students after the midterm I know I did it right there so yay!
Tracing seems simple enough and one important advise that Diane gave us, that I find extremely helpful is "Don't over think". It really works !

Stacks&Queues..
As I mentioned, I've done C++ and have previous knowledge of how they work. Even though I was sick and had to miss the classes for this particular topic, I found the lab work simple enough to follow. The basic idea behind them is the same and honestly seems even easier in python.

The only thing I worry about is recursion during a test or exam. It always takes several tries (and sometimes not even then!) to get it right and I honestly don't know how we're expected to write code for it without actually running it.
I'm hoping it's a practice thing and I will eventually master the art of recursion.

Assignment 1 and Midterm 1 were sufficiently good for and I have high hopes for my GPA to survive thanks to this course!

Until next time..!

PS - Cannot wait for reading week...