Sunday 30 March 2014

Week 11 Sorting and Effectiency

    During this week's lecture , Danny has introduced us two extra sorting algorithm ——merge sort and quick sort. The idea of quick sort is to select an item out of the data as a pivot(most of algorithm picks the first item). Then partition the data/list into two halves: items that are less than the pivot and the items that are greater than the pivot . than we can rearrange the list to get the right position of the pivot item we selected , select a new pivot and repeat the partition after that . This is the basic idea of a quick sort. it is a  fairly fast sorting technique. The best case run time for quick sort is O(n). and the worst case is O(nlogn). this is also one interesting idea pops up during the Wednesdays lecture. Since we know what the worst case of quick sort looks like. we can edit/ change our algorithm to avoid such situation by instead of choosing the first item on the list as pivot, now we  randomly pick out pivot item .
    The second sort technique that has been introduced is merge sort . it  splits the list in two halves and sorts two halves individually then merge two sorted halves. merge sort seems like it taking a lot steps to sort a small sized list. However , in a lag sized list . it performs just fine the worst case is same as quick sort O(nlogn)

Sunday 2 March 2014

Week 7 recursion

    Through the past couple weeks we have been study on Recursion, which is basically to repeat a recursive procedure  multiple times. The idea that have been introduced to the class was to repetitively call a recursive function until  a "base case" is reached .
    for example , compute a factorial function would be look like :
def factorial(n):
    if n == 1:
        return 1
    else: 
return n * factorial(n-1)
http://www.python-course.eu/recursive_functions.php [source]

 the program itself is simple. only 5 lines of code .  However, it is really clear that we repetitively call upon the function itself with (n-1) as argument and n*factorial(n-1) as accumulated/final output .

 if n == 1:
        return 1
   this if statement is the base case i called about . with out this piece of code the value of n will keep reduce and function will stuck in to a infinite loop.
 
    from this example, it is quit obvious how recursion work, it essentially breaks down the big and complex problem by finding the similarity (the recursive parts) . and solve the problem in a much efficient way compare with what we have learned in csc108 , write a huge loop with tons of if statement.
 
   overall ,i belive recursion is a powerful tool that will come handy on my later study of computer science

Monday 3 February 2014

Week 4

Week 4 
    This week is basically introducing  Assignment one and recursion .

    On Monday. we learned about nested list, and a idea of how to solve a recursive problem by tracing the function step by step. it is a bit confusing to start with, but after couple examples and discussing with the Ting-Ting (girl who were sitting next to me ) , i was able to trace the problem and the function returns the value as i excepted .
   
   On Wednesday, we went deep further in recursion problems , something called "tree burst". being able to read something new with what i have just learned is simply exciting . So , based on idea of this example , i coded  a function that would drawing a dividing ruler . (not in python though , was did in turing , which i consider as a really good starter programming language)
   
    in this week. i also met up with my group mates for Assignment one , we decided to write the helper function of our own  and pull everything together discuss and improve, which i think is great because. i think  in CSC course , knowing how to work with others is important but it is certainly not a reason to taking a "free ride" it will ruined my own chance to learning more about this course.

Sunday 26 January 2014

Object-Oriented Programming

     Many Programming Languages are Object-Oriented, such as java,C++, and Python which are the program we currently learning and about to learn in the coming up academic years .
   
    The first three weeks of studying on Python give me a higher level of understand on Python. A brand new perspective : design and written codes using Class, which is extremely useful and cool tool to use. it essentially letting us to merges data with the same or similar(we can use the idea of inheritance/sub-classes which is also what we learned in week 3)  property /attributes  under one particular Object.
 
    Before i have a start taking CSC148, in CSC108 i actually thought use classes to code was useless, increase the complexity of the code and it is a total waste of time. However, after three weeks of studying in the lecture and lab , i realized how efficient it is, it is not only helping you  to eliminate duplicate code ,efficiently collect and organize data   , and improve ones written style which is key and important for other programmer to understand your code or work with others on same peace of project.

    The more i play around with it the more i realize how power this OOP is , the idea of Object-orienting is suddenly makes a lot problem used to be impossible to code for me are now relatively easy. i have learned  a lot this three weeks, even tho i know i am just scratching the surface , but i am loving it.