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.

Friday 6 February 2015

WEEK 5 - February 2nd - February 6th
TRACING RECURSIONS IMPRESSIONS
My experience with tracing recursion was quite interesting. Tracing recursive function was something very new which I was doing and therefore I enjoyed it. I think I misinterpreted it therefore lost marks on the quiz and even in the exam but I think we learn from our mistakes if I didn't made these mistakes I would not care about it and ignore it but making these mistakes helped me review recursion again and I learned it better than before. The easy method I learned was writing whatever the function is doing in english then translating it in python with recursive code which makes learning recursion easy. The same can be done while tracing recursions. The feeling of writing recursive code which works in the first go is out of the world for me because it is something which not everyone can do.



Saturday 31 January 2015

WEEK 1 - January 5th - January 9th
This was the first week of CSC148. We were all excited to start the course and got a warm welcome by professor Diane Horton. I found her very passionate about teaching CSC148. We were introduced with the course outline and syllabus. Then we discussed about Object Oriented Design. We did a short CSC108 basics recap as in string concatenation, lists, checking equality and checking types of data. Then we started designing classes, but before this we used decision analysis to decide for class name using nouns, methods using verbs, attributes using less common nouns. Then followed design recipe to write methods. . We learned about two kinds of comparisons that is with 'is' and '=='
and learned the difference between two. In first week I got recap and quick recap of some topics from 108 with a prospective of a different professor so it made me more confident with the topics I was unsure about. In 108 I started coding in python using design recipe and then suddenly left it when I felt comfortable with it but 148 made me use design recipe again, it showed how design recipe make it easier to design functions and programs.


WEEK 2 - January 12th - January 16th
Second week of CSC148 came with a bunch of new special methods that is__init__() to initialize attributes, __str__() to return a string representation of self, __repr__() to return a string representing self that produces an equivalent python object when evaluated in python, __eq__ to check equality of two objects when compared using '=='.  We learned about ADT's like stack and learned about it's push, pop and is empty operations We also learned about client code and interface which made us realize we can't go back and change our docstrings and the tasks our methods performs as billions of clients are using our user interface. This also raise a problem that clients code see and modify our variables, which we tend not to happen. So then we came up with a solution of using property mechanism of python to resolve the issue which we planned of discussing next week.We also had our first lab were we wrote a RaceRegistry() to register runners according to speed category. we had methods to get the category, to get runners according to category and method to register runners. The main concept or the idea which I got confused was the word self, why was it required but all doubts were gone when I started playing with my code, that is trying working without self or with different names so I learned the meaning of self in relevance to classes. __repr__() was something I got but i didn't I understand why was it required until I researched and learned that it is used by web developers.

WEEK 3 - January 19th - January 23th
Third week of CSC148 we were provided with the solution raised in week3 with help of property mechanism. We defined methods set_x() and get_x() to prevent the attributes from being modified and changed. We starting defining parent class employee and then created subclasses  HourlyEmployee and SalariedEmployee which inherited methods and attributes from parent class. Then we realized there were some methods that could not be implemented in parent class as they were specific to different subclasses so defined those methods in parent class and raised exceptions using raise Exception(' Defined in a subclass').  This made us realize the power of inheritance and we traced inheritance using some code to learn the idea better. We also also learned some cool python features namely list comprehensions, class zip and function all. In the lab we made a class GradeEntry, LetterGradeEntry, NumericGradeEntry which involved the use of inheritance. One small phrase which I made to learn inheritance was that the child always knows more than the parent and the each child has same features of the parent but in addition its own specific features.



WEEK 4 - January 26th - January 30th
What we learned in week 4 was a completely new topic recursion. That is calling a function within itself. It came as a surprise that such thing can happen and it was hard to believe before we actually traced after tracing we got a sense that it is possible. This is also involved use of list comprehensions which we learned earlier. I also learned a thing myself after the lecture and lab that the functions written using loops are long but the same function can be reduced using recursion. This is the code for my lab03 the same function is written using seven lines with loop and only three lines using loops. So this gives me a reason why recursion is a better alternative.






Tuesday 20 January 2015

WHY GEEKS SHOULD WRITE?

Everyone wonders what benefit writing can give you but trust me you can't keep wondering to get the answer. You need to actually experience it and your experience will answer everything. I was also wondering what should I write on the topic 'Why geeks should write' before I started and then I realized writing makes your thought process faster and clearer, it makes you think in multiple directions and in multiple ways. So writing an essay about some topic makes you critically think and reflect on the topic. Similarly writing for computer scientists help them critically think of their code and reflect upon it later. There are maybe many bugs in our code which we realize later so keeping a record of our code helps in debugging it later. Also there can be more than one algorithm for a specific problem and choosing the right one becomes tedious until we write it down. Writing makes learning easier and faster. Writing helps us to overcome our laziness and instead compels us to come into actual field try it down. So overall keeping a record in this course would benefit me and maybe helps me in debugging at a later point of time.

I would love to change the world, but they won't give me the source code!