Text
Week 12: Final preparation, hashing, farewell (maybe…)
So…..the time has come! It’s almost time to test all my knowledge I gained in this course in the final exam! This last week we have learned about hash tables and Big O. FINALLY we are incorporating the material we have been learning in CSC165 and everything suddenly makes sense to me (Big O, running time complexity). It’s been a little hard to focus on the hashing material this week with all the distractions from finals and last assignments. From my understanding, a hash function is a function that takes input of a variable length sequence of references to objects and converts it to a fixed length sequence. It is a one way function. This means if f is the hashing function, calculating f(x) is pretty fast and simple, but trying to obtain x again will take years. The value returned by a hash function is often called a hash value. Most of the time a hash function will produce unique output for a given input. However depending on the algorithm, there is a possibility to find a collision due to the mathematical theory behind these functions.
Once you have hashed an object to a number, you can easily use part of that number as an index to a list to store the object or something related to it. If the list is of length n, you might store information about the object A at index hash(A) % 0.
Dictionaries are implemented using hash tables! These tables are sort of difficult to understand (for me) but maybe staring at the example codes for a bit will help me, then I can implement some of the class examples again such as the birthday paradox one.
I am also planning my review for the final exam! I am going all out with studying this time… I have made enough mistakes with past midterms and quizzes that I should be able to overcome now! I’m definitely going to go to the last few office hours for help and do a study group! Of course, I will do a lot of practice with past labs and assignments as well.
Now… this will probably be my last post. But, I’ve had fun updating you on my progress and (mainly) struggles in this course! I hope I haven’t bored anyone to death. Whoever has read my posts, thank you for taking the time to do so! :)
1 note
·
View note
Text
Reflecting on Week 7 and my improvements
Hello!
This week I will be revisiting my SLOG from Week 7, where I talked about my struggles of writing Test 1, struggle with ADTs such as linked lists and stacks/queues and doing poorly on lab quizzes. Since then, I feel as of lately, I have improved much more than I thought I would and I am more comfortable with the material.
I mentioned that I was having trouble with studying for the tests, and that I have a bad habit of overthinking questions at times and stumbling on things that I am able to do. For example, on Test 1, the count_stack method implementation was easy however I failed to put back all the objects removed into the original stack. Now, I learned that all I had to do was use the .add() function to add the removed item back into the stack again. I looked back at this mistake and I implemented more stack/queue related methods from the additional lab exercises. Now, I have a better understanding of how FIFO and LIFO data structures work and have more practice on actual implementation of them rather than just reading codes from class lectures and assuming I know it or can “memorize” the code. This is WRONG. Never do this in a CS course. Not every method I will ever encounter will be seen before. This is one of the problems I had in this course in general; I slacked on actually practicing implementing methods and just read over things many times. It eventually caught up to me on tests…and it is something I suggest someone who takes this course in the future shouldn’t do.
Also, I have been doing better on my last few quizzes as well. This is probably due to the fact that the material on recursion has somehow been easier for me to grasp- I guess I’m one of those that just gets it. Also, I have been a lot more productive in the last few labs as well and took time to really UNDERSTAND what I’m doing rather than just trial and error. Also, I have been consulting with my friends and other people a lot more, which is VERY crucial in CS. Studying with friends is the best idea, since you can learn a lot more than doing it all alone and hoping that whatever you are doing is right. Working on A2 with my partners definitely helped with that as well.
Now that I feel like I’m getting a little better in this course, I am planning to go all out for this final exam- I will be practicing a LOT and consulting with friends and TAs on things I’m confused about. I finally figured that this is the key to success in this course.
Until next time!
2 notes
·
View notes
Text
Trees, Test 2, A2!
Hi again!
So this past week has been pretty interesting. We are currently learning how to implement recursive functions and work with trees (not actual trees… a Python data structure quite similar to linked lists). To be honest, I dreaded this entire unit because I had heard from others that this part of the course tends to get very difficult. However, I am quite enjoying it! I think I have gotten down the basic idea of recursion, and how a function can repeatedly call itself without iteration and for/while loops. I’m a math person so trying to come up with a recursive code kind of requires me to think in the same way.
Trees are really fun! I think it helped a lot that we did linked lists before trees/recursion because it is a very similar idea, more specifically binary trees and linked lists. Binary trees use the similar node structure as a linked list with node.value, node.next_ but with .right and .left attributes. Binary trees are trees that have no more than 2 “children”.
I like binary trees the most because it is easier to work with rather than a tree that can have multiple nodes (even then though it’s not really that difficult, but binary ones are just easier to draw).
Also, the second midterm is coming up! I have been really trying to improve my study methods and reading How to Think Like a Computer Scientist, doing the lab exercises all over again, and just trying to re-implement codes that we have done in the past and do ones I left incomplete. I am in a much more eager mood to study the material because I am genuinely enjoying everything we have been learning after the first midterm in February.
Also, A2 is due in 2 weeks! It was quite the struggle doing A1, as it wasn’t as easy as I thought it would be. I had never done an assignment of that length before in CSC108 that involved multiple classes. We had to keep track of all changes we made in all classes because everything was connected, which made debugging difficult and frustrating to. In the end, our code wasn’t completely successful but we realized all our mistakes that we will avoid for this next assignment. One of them is to start working on it much earlier! Time management becomes an issue when you have a million other assignments and tests to worry about and have to write methods for 8 classes. However for this next assignment, I will try to improve on that. I like recursion, and all those game implementations seem like they will be fun. I will update you guys on my progress once we start A2 and also provide feedback for Test 2!
Until next week!
3 notes
·
View notes
Text
Week 7 – ADTs, Recursion, My struggles, thoughts…
Hi again! It’s that time; slog time.
So, by now we are basically halfway through the course and it overwhelms me when I think about how much I have learned in 2 months. Stacks, queues, linked lists… so many abstract data types in so little time. I definitely struggled a lot more than I expected this semester in this course, and not everything was easy to grasp. I noticed that sometimes things just were unclear to me and made no sense until I did the labs. For example, I didn’t understand the whole “next” node thing about linked lists until I actually implemented methods in lab. Even then, I managed to not get the quiz question correct because there was just something that was off; either syntax related error or just the algorithm in general. Unfortunately this happened on a few other quizzes to. It’s frustrating mostly because they were careless mistakes that could have been avoided IF I understood the content better. Another mistake I made in the quizzes is when we were asked to write the function call of a Queue ADT based on the body of the method. A queue is a FIFO ADT, meaning first object in the list is the first object out as opposed to a Stack where the last object in is the first object out. On the quiz, I mixed up the two and instead I did it based on the stack method of remove() so the thinking behind it was right, but just in a completely opposite order. The bright side is that I learned from these mistakes, and I don’t usually let a bad grade discourage me. Instead, it motivates me to do better and put in more effort for next time. Speaking of bad grades, we got back our midterms last week, and all I can say is that I’m glad it’s over. There are many opportunities to improve ahead. I expected to do better, but I think that time management writing the test was a huge issue for me. The test was longer than I expected and I left a bit incomplete and made careless mistakes while rushing to finish it. People work at different paces, and I usually like to take my time, but unfortunately this time that didn’t really work. Despite it being long, in terms of the material it was quite doable and easy, but given more time I would have definitely done a lot better. The stack method implementation was easy however I failed to put back all the objects removed into the original stack. Now, I learned that all I had to do was use the .add() function to add the removed item back into the stack again as such: def count_stack(s): """ Return the number of elements in Stack s. Restore s to the same state it started in. @param Stack s: @rtype: int >>> s1 = Stack() >>> s1.add("how") >>> s1.add("now") >>> count_stack(s1) 2 """ s_tmp = Stack() counter = 0 while not s.is_empty(): s_tmp.add(s.remove()) counter += 1 while not s_tmp.is_empty(): s.add(s_tmp.remove()) return counter
To improve for the next term test and assignment, I will try to go to office hours more often when I run into problems and need clarification on things. I feel like I am slacking on that and I regret it. Also, I will do the extra lab exercises for more practice, and just devote at least an hour a day on just practicing programming. The best way to learn I have figured is to just do the exercises and tackle problems myself rather than just reading about the topic. Right now, we have just begun recursion and so far I am finding it REALLY cool. It’s basically when functions can call themselves to solve smaller subproblems and do this repetitively and in a recursive manner, hence, recursion. So far I think I am really understanding it well and I’m going to try to practice as much as I can. That was it for now! Until next time!
1 note
·
View note
Text
Week 3 - LinkedLists
New week, new post!
In the last 3 lectures, we learned all about linked lists and how they work in Python. I however, only managed to grasp the concept of linked lists during Lab #4 after implementing some LinkedList class methods.
A linked list is a data structure that is made up of nodes (or “sublists”). Each node contains a single piece of data (str, int, float, etc…) and also has an attribute called next_ which is a reference to the next node in the list. Each node contains a reference to the next node in the list, which then contains a reference to the next node in the list and so on, sort of like train cars attached together (at least that’s how I like to think of it).
To define a LinkedList class, you must first define a Node class which would look something like this:
class LinkedListNode: """ Node to be used in linked list
=== Attributes === @param LinkedListNode next_: successor to this LinkedListNode @param object value: data this LinkedListNode represents """
def __init__(self, value, next_=None): """ Create LinkedListNode self with data value and successor next_.
@param LinkedListNode self: this LinkedListNode @param object value: data of this linked list node @param LinkedListNode|None next_: successor to this LinkedListNode. @rtype: None """ self.value, self.next_ = value, next_
There is also a __str__()to represent the node as a string and an __eq__() that returns whether a node is equivalent to another node.
Now that a node is created, it can be linked with other nodes to create a list that contains several of them. A linked list can be empty (represented by None) or it can have a designated first object (front) and a designated last object (back) which can also be the first if there is only one node. A linked list has three attributes; front, back and size. “front” refers to the first object in the list, “back” is the last object and size is the number of nodes/objects in the list. Each object has a successor object, except for the last object which its successor is None and contains no data in it. The first object is the successor of no other object, hence why it is called the front. A good way to understand this concept is by drawing diagrams, such as this:
Here is the initialization of the LinkedList (currently, the one below is empty):
class LinkedList: """ Collection of LinkedListNodes
=== Attributes == @param: LinkedListNode front: first node of this LinkedList @param LinkedListNode back: last node of this LinkedList @param int size: number of nodes in this LinkedList a non-negative integer """
def __init__(self): """ Create an empty linked list.
@param LinkedList self: this LinkedList @rtype: None """ self.front, self.back = None, None self.size = 0
To access objects in the list and modify things we “walk” along the list by first making a reference to a certain node and move along the list while a condition is true. It generally looks something like this:
cur_node = ________ <- self.front (front node) or any node/position you choose to begin from while <some condition here…>: #do something cur_node = cur_node.next_
We can do many things with linked lists, and some things we have learned is how to insert or remove objects at different positions in the list and also join 2 lists together. I can talk about this for ages but since I want to keep this short, this has been fun (I hope)!
Currently, I am working on Assignment 1 so, I’ll update you on that soon and I’m currently really anxious for my midterm mark.
Until next time!☺
4 notes
·
View notes
Text
Week 1
Hi! Welcome to my SLOG! This is my blog where I will post my (hopefully somewhat interesting) thoughts on the course CSC148 - which so far has been pretty exciting, overwhelming, but also confusing. Please bear with me while reading my posts, I probably won’t make you laugh, but I hope you will learn more about me and my experiences with computer programming.
First off, my professor, Danny Heap, began with review from the last portion of CSC108- classes. There are many things I was familiar with from before such as the __init__(), __str__(), __eq__(), __add__() methods. Something that really caught my attention the first lecture was Python TURTLES! (Yes, turtles. Turtles that can draw themselves.) Turtle is a Python module that can draw intricate shapes using programs that repeat simple moves. I never knew this was actually possible in Python, so I was pretty mind blown. Something interesting I also learned about is inheritance. Inheritance is when you create a subclass (or “child” class) and a superclass (or “parent” class). Subclass inherits features from the superclass, adding new features to it. This results to the re-usability of code, which avoids duplicate code. To inherit something from another class, it would look something like this (don’t forget to import the superclass!):
class Subclass(Superclass): body of Subclass
I have to admit, it is a little difficult getting used to object oriented programming. There are many more things I now have to keep in mind when I’m coding and sometimes it gets a little overwhelming, but nonetheless, I don’t mind a little challenge (except for having to wake up early for my 9 am lab every Thursday morning).
2 notes
·
View notes