Wednesday, 30 October 2013
O sometimes, I get a good feeling
Today in class... We learned about big O notation! Yay! Conceptually it's a very easy concept. However I do find the grotesque oversimplification of information to be contrary to what I typically expect from this field of study. If the Professors wished to establish propriety within big O notation I think a greater amount of stress should have been put on the fact that all extraneous constants are considered part of 'C'. This fact was initially unclear to the classmates around me and I as 'C' was given very little emphasis.
Tuesday, 15 October 2013
Comprehend List Comprehension
I just had my lab on List Comprehension and the TA helped me understand what I didnt even know was able to be understood. Namely I learned the now obvious notion that for loops dont just have to run through numbers, they can, in fact, run through many object types (but in this case I am concerned with lists). I learned that when you write:
for i in listExample
'i' doesnt represent the index, but rather the objects in listExample. I also made the descovery that you can have multiple 'i's. For example using tuple unpacking (assuming listExample contains tuples).
for i,n in listExample
My coding style, as a result, has shifted slightly and I can condense a method into fewer lines. For example, the code I put in last week's post, which I wanted to shorten, I have now shortened to one line
def list_count(o):
return (1 + sum(list_count(i) for i in o) if isinstance(o, list) else 0)
huzza!
for i in listExample
'i' doesnt represent the index, but rather the objects in listExample. I also made the descovery that you can have multiple 'i's. For example using tuple unpacking (assuming listExample contains tuples).
for i,n in listExample
My coding style, as a result, has shifted slightly and I can condense a method into fewer lines. For example, the code I put in last week's post, which I wanted to shorten, I have now shortened to one line
def list_count(o):
return (1 + sum(list_count(i) for i in o) if isinstance(o, list) else 0)
huzza!
Monday, 14 October 2013
Middle of MidTerm
Oh happy day! Last week on Tuesday night I, Mackenzie Heller, against all odds, created a recursive method that worked! The solution? I deleted about half of my code. Turns out the 'solutions' I wrote for my bugs were in fact the problems themselves. I was unable to trust that if the program worked for the first case it could work for all cases thereafter. The program was handed in with one hour to spare. But now it's midterms, Ive been reviewing all the class notes and answering the preivous test we were given yet I still cant seem to get over the fact that I dont feel ready. I think thats because I havent really done any practice questions. A few questions on a practice test doesnt really seem like enough to me but maybe im just going overboard with how much i need to study for this (this being my first University test). In any case this is my answer for question 3...
def list_count(o):
k = 0
if isinstance(o, list):
for i in range(0, len(o)):
k += list_count(o[i])
return 1 + k
else:
return 0
Im sure you could make it shorter but this is how it most logically makes sense to me.
def list_count(o):
k = 0
if isinstance(o, list):
for i in range(0, len(o)):
k += list_count(o[i])
return 1 + k
else:
return 0
Im sure you could make it shorter but this is how it most logically makes sense to me.
Monday, 7 October 2013
Object-Oriented Programming's got class
Object-Oriented Programming is a form of programing that focuses around conceptual objects. Objects posses properties that define what kind of object it is and methods that allow the object and its properties to interact with other objects. For example a 'ball' might have a 'shape', 'colour', 'size', and 'bounciness' while being about to do things like roll() and bounce(). Objects may consist of other objects and inherent traits of still more objects. Because of its nature, Object-Oriented Programming tends to be modularized meaning larger goals that the program wishes to accomplish are split into smaller objects that interact with each other. Many Object-Oriented Programming languages such as java protect its modules from being tampered by the outside. Java does this by declaring if an object is 'Public' or 'Private'. Private variables can often be accessed safely through Public methods conventionally named 'get' or 'set'. The program language this course uses, however, does not protect its modules. Instead Python asks nicely that you do not touch anything that's name consists of a '__' before and after.
Object-Oriented Programming is useful because it allows you to use objects multiple times without having to recreate the code from them. By splitting problems into smaller problems, simpler and more effeicent methods can be found to solve said problems.
Object-Oriented Programming is useful because it allows you to use objects multiple times without having to recreate the code from them. By splitting problems into smaller problems, simpler and more effeicent methods can be found to solve said problems.
Recursion is (Recursion is (Recursion is (Recursion isn't quite the simplest case) great) great) great
Recursion is a Computer Science tool used to solve problems that are made up of smaller instances of the original problem. In most object oriented programing languages functions are able to call themselves allowing the programer to run the same method inside itself, each time with potentially different values in the parameters. At some point the method should hit a simplest case in which it can no longer be divided into small versions of itself. This point must always happen or the method will run itself for as long as the IDE can handle without ever returning values (or null) to the above methods. A method can employ single recursion, in which the method only calls itself once and expands linearly. However for more complex problems multiple recursion may be necessary as function in turn calls multiple versions of itself, expanding exponentially.
For certain problems Recursion can be a very efficient alternative to repetitively writing very similar lines of code.
However it can also be challenging to follow the recursive method during run time making it difficult to debug.
amidst A1
This week we are finishing up our assignment 1 for csc148. I did the first 3 parts within an hour and meant to leave part four for Saturday and five for Sunday. However part 4 proved to be more challenging then i thought. My recursive methods keep almost working and it is very frustrating. I think my problem is that I dont trust the computer to do a lot of the work for me as it goes deeper and deeper into the recursive method so i feel the need to help it out. But because I cant possibly grasp everything that goes on 4,5,6,7,8 levels deep I end up tripping up the computer with my clumsy human errors. As Ive simplified my code Ive gotten closer and closer to the answer but im still not perfectly there yet. Its frustrating not to be able to find the exact line of code and changing it for fear that it will break the recursive algorithm at three other points. In any case Ive created step five with very little problems and hope to, with what i currently have, get perhaps a 90. However, admits all the other work i have due this next few day, I hope to finish the code properly.
Subscribe to:
Posts (Atom)