Saturday, 4 April 2015

Last impressions - Journey Ends!!!

My journey through CSC148 was full of ups and downs. I learned a lot of new stuff in this course. Some topics were easy and some were hard. I did well in the assignments but not the midterms due to some careless mistakes. I found A3 useful for practicing recursive functions and I think I did pretty well on it. I look forward to give my best in the final so that I can come up with a good overall grade. The most interesting topic for me in this course was recursion and trees as it was the base for many other topics. Out of all the assignments, I found A2 particularly Minimax hard . I would like to invest more time on it so that I get it clear before the final exam. I would also use the classes created in A1 and A2 and add more games to it. To prepare for the finals I would write as many as possible recursive functions. I will do every possible thing so that I do well on the final exam. I would try to go to all the extra office hours and review session. I liked the way the course ended with talking about sorting efficiency similar to CSC165 and CSC108 as efficiencies are of great importance to programmers. There are several sorting techniques such as bubble sort, merge sort, selection sort, quick sort, heap sort and each has different efficiencies. The efficiencies come into play as the input size increases.  The following table shows the worst case, average case and best case of these sorts.

We specifically talked about Big - Oh efficiency in this course. Big - Oh efficiency gives us the worst, best and average-case in terms of input size of n.

The above pictures shows Big- Oh notation and its graph.

I find efficiency very vast and interesting so would like to learn more about it and tradeoffs of time and money in CSC263.

So I would like to wrap up my very last slog to be marked though I would continue writing about my programming journey. I would like to thank my professors, TA's and friends who all supported me a lot throughout the course. I would also like to mention a few slogs which I followed and read throughout my entire journey of CSC148 and which were very helpful to me.




Tuesday, 31 March 2015

WEEK 11 - March 23th - March 26th 

Revisting an earlier slog

This week's topic is revisiting an earlier slog and comparing our thoughts now and then. I would like to revisit my slog on summary of recursions.  Recursion is something I enjoy and comes more naturally to me than before. I feel more comfortable with recursions. A3 option B was a good choice to make as it gave  me a lot of practice on recursions. There were many functions for which recursions happened in the helpers and helpers were called in the main function. I agree with my thoughts that recursive code is simpler and more elegant than iterative code. Recursion is something I would like to learn more about. I have a long break for my CSC148 exam so I would practice a lot of recursive code during that time so that I feel more confident with the topic. Talking to other students I think everyone is now developing recursive thinking and everyone feels that more practice on the topic makes us sharp on the topic. I would also like to visit my very first slog Why Geeks Should Write. It is  now the 11th week I am writing slog and I realize seeing all my slogs aka posts that how I have summarized my journey of CSC148 in these slogs. I  wrote about what I learned, how I learned, what problems I faced and what I did to solve these problems. I think other benefit of writing is that you can share your thoughts and ideas with the public and receive feedback on your thoughts. I particularly liked what these slogs had to say about the topic Why Geeks Should Write 


While writing is beneficial reading is also rewarding. Reading other slogs helped me relate to different perspectives of the same topic. 


Sunday, 22 March 2015

WEEK 10 March 16th - March 20th

This week I started working on A3 with my partners. We decided to work on option B as we didn't do quite well on minimax. I will do option A myself later on to get practice for the final exam. We started with the function grow and are still struggling with it. We are very very to close in getting it. We almost got it but when we wrote the function node_count we realized we didn't actually what we wanted to accomplish. I am sure we will be able to get it. This week I need to work more hard so as to complete A3 on time. In lectures this week we looked back on A2 and performed unittest on minimax and learned how to choose test cases. I  am still confused how to decide about choosing test cases but I think lab09 would give me that practice. I didn't get time to complete lab09 though I have started. I will post my solutions when I am done. We also performed exercises in class to learn about assertion, what I learned of it was we need to assert something that would be true if our function did its right job. 

def list_between(node, start, end):
    ''' (BTNode, object, object) -> list

    Return a Python list of all values in the binary search tree
    rooted at node that are between start and end (inclusive).

    >>> b = BTNode(8)
    >>> b = insert(b, 4)
    >>> b = insert(b, 2)
    >>> b = insert(b, 6)
    >>> b = insert(b, 12)
    >>> b = insert(b, 14)
    >>> b = insert(b, 10)
    >>> list_between(None, 0, 15)
    []
    >>> list_between(b, 2, 3)
    [2]
    >>> L = list_between(b, 3, 11)
    >>> L.sort()
    >>> L
    [4, 6, 8, 10]
    '''
    lst = []
    if node is None:
        return []
    else:
        if node.data > start:
            lst += list_between(node.left, start, end)
        if node.data < end:
            lst += list_between(node.right, start, end)
        if start <= node.data <= end:
            lst += [node.data]
        return lst

In the function above we can assert node = BTNode which I got using the docstring. The syntax for assert statement is as follows
assert <<condition>>, <<error string>>
We have the AssertionError(<<error string>>) if the assertion is not true. I hope to learn more about unittest and implement it when doctest testing is not sufficient. I would like to say a little about doctest and unittest before I end. Doctest are really good for testing but we got more accurate and extensive testing with unittest. There are also conditions where doctest is not possible so unittest are of use in those conditions. Hope next week has more interesting stuff to reflect upon.

Sunday, 15 March 2015

WEEK 9 - March 9th - March 13th

This week we continued with linked lists. We wrote insert and delete functions. The idea of breaking down into cases is essential and must for recursive functions. We started with discussing all the possible cases and then packed up many cases together. Insert function was easier for me to understand than delete function as there was no problem of making a new root in insert which was there in delete function. We proposed an algorithm for making a new root if the value to be deleted was the root and did the required substitutions which seemed not quite natural to me. I got that after drawing pictures and talking to my friends. This week's lab was not easy for me because I did not have any tutorials to clear my doubts with TA's or lab partners. I was not sure what I was supposed to do in this week's lab so I would confirm it my professors next week. We also had term test 2 this week. I think I did well on it but can't predict before results are out. I am looking forward to learn more interesting and challenging stuff in the last week of classes


Sunday, 8 March 2015

 WEEK 8 - Impressions Of Week 7 March 2nd - March 6th

Week 7 was all about Trees specifically Binary Trees and Binary Search Trees(BST). I really enjoyed learning about Binary Search Trees because the fashion in which they are designed made searching simpler and better than linear searching. I was initially confused why is the height to be searched in a BST proportional to log2(N) where N is the number of the nodes but I was clear with it when I drew pictures for trees of different heights and searched for elements at different levels. 

This Tree diagram represents a Binary Tree where each node has two children. This resemblance with family relations helps me understand the concept of trees better.


This tree is a BST where all the left children are less than the root and right children are greater than the root. This is a special property of BST which distinguishes them from Binary Trees.

Writing Binary tree functions we had to take special care of None which was to be one of the base cases. There was no None in n-dimensional trees because the children were stored in a list so they either had something or were empty. So dealing with None data type was one of the things which I  became confident this week and it was mainly with practising lab exercises which were pretty challenging. Taking inspiration from other slogger's blog I thought of sharing my solutions to the lab's which can be found here. I am doing this to help people struggling on labs and also to get feedback from other sloggers about my solutions.

I also misunderstood Minimax where I thought I had to built Trees but later realized that we didn't have to use Trees at all instead had to use Recursion which recursively built Trees.



Sunday, 1 March 2015

WEEK 7 - SUMMARY OF RECURSION- Topic to be graded

I chose this topics from the list of topics to be graded because this is a new topic which I am learning out of the listed topics so I have more to share on this topic than others. Recursion is calling a function within itself. For example to calculate a sum within a nested list the best way would be recursive calls of the function to the inner lists
def sum_list(L):
    """
    (int or arbitrarily nested list of int) -> int
    
    Return the sum of all ints in L.
    
    >>> sum_list([1, [2, 3], [4, 5, [6, 7], 8]])
    36
    """
    
    if isinstance(L, list):
        return sum([sum_list(x) for x in L])
    
    else:
        return L
A recursive solution is concise and elegant, an iterative solution is long, complex, and inelegant. For writing recursive code, thinking informally helped me a lot that is thinking if I had a bigger problem version of problem, then calling helpers on smaller versions of same problem and then using the result of helpers to solve the larger problem.
Recursion involves three steps
  1. Choosing a base case which would be our if statement
  2. Thinking of smaller instances of the same problem, tracing calls to smaller instances of the same problem
  3. Gathering the result from all the helpers (smaller instances) to solve the larger instant of the problem and return that in the else statement
Recursion was way easier following these steps. The part where I was usually stuck was second part. Thinking of smaller instants requiring recursion was a tough call. But practicing made me comfortable with second step. Most of the tree methods require recursive calls. It is easier for the node to ask it's children the required information than calculating itself. For example in the height function gathering height of all the children and finding the maximum out of them was better then using iterations for me. Recursion is making my coding life simple and easy.
The above code shows a same problem with recursion, for loop and while loop. The code for the recursion is shorter, simpler and elegant while in the case of loops it is longer and less elegant.
So overall recursive code made me understand the importance of beauty and elegancy in an programming language.

I would also like to share my recursive code exercises solutions from the lab here

Sunday, 15 February 2015

SUMMARY OF OBJECT ORIENTED PROGRAMMING CONCEPTS (OOP)

I can relate to this topic because of my previous experience with C++ which is also an object oriented programming language. We treat everything here to be objects be it variable or function. Everything is implemented with the breakdown into modules or smaller units. Class design follows the concept of OOP where the methods of the class are modules or smaller units of the larger unit that is the class Inheritance is also an implementation of object oriented programming. The problem I faced with OOP concepts was the breakdown between methods or modules which involved smart strategies and critical thinking as in thinking as everything is happening live and then implementing it through specific modules performing the required tasks. I solved this problem by using the idea given by professors of thinking of class as a noun and the methods as verbs and therefore it was easier to design a class. For example in Assignment 1 I used OOP concepts where choosing a move, taking a move or declaring a winner were various methods, in other words verbs of the specific class which were implemented specifically in subclasses. One great thing or let me call it strategy I learned was first describing the specific subclasses and then generalizing whatever is repeated in these specifications which makes it easier to use inheritance. The given diagram explains Inheritance, the subclasses bikes, cars, buses and trucks all have same features such all are road vehicles but they are different types of vehicles. They have some common features which are implemented in base class, some specific features which are specific to subclasses and are implemented differently in subclasses.  


 Object Oriented programming language is better than procedural programming because here the central concern is objects here we define objects first and then flesh them out with specific implementations whereas in procedural programming treats program as an recipe whereas objects are containers of the recipe. Some of the advantages of Object Oriented Language are given below


So the idea of Object Oriented Programming itself is the main tool or the building block of various high level programming languages like python.