Let's take a trip down sorting lane, shall we?
This week, we learned about the different types of sorting methods we can use in Python (and other computer science languages) and why some of them should never be used *coughbubblesortcough.* It was actually quite interesting to go in-depth and see exactly how some of the sorting methods worked. And now, I'll basically regurgitate that info but also provide cool gifs (or not, they don't seem to work)! Yay.
Bubble Sort
Oh boy, here we go. Bubble sort goes through the entire list and always places the largest item at the end of the list, causing it to have a worst-case runtime of O(n^2) which is not good. While there are some ways it could be faster, such as having to check only once if the list is sorted, seeing the times tower over the other ones reminded me that if I have to, not to use bubble sort.
Insertion Sort
I personally like insertion sort, though I can see why some people don't really like it. It just accumulates a list as it goes along, plopping the end item where it needs to be. Simple! It's usually better to use insertion sort when the list is nearly sorted since there's little overhead.
Selection Sort
Selection sort should be used around the same number of times as bubble - close to zero. It is just sloooooooooooow. It goes through the entire list multiple times and builds it from the smallest up. Please don't use it.
Shell Sort
Based on insertion sort. Very good for smaller nearly sorted lists. A+.
Merge Sort
Ah yes, merge sort. This method splits the list to be sorted into a bajillion pieces, sorts those, then smushes them together bit by bit and sorts them again. Pretty cool, to be honest.
Built-In Sort
The last sort method I'll mention. Please use this one. It's so so fast and absolutely destroys the other methods in tests. It's actually a hybrid method based on insertion sort and method sort so it's pretty much magic.
All in all, it was quite fascinating to see how the timing of these methods went up as list sizes increase, through charts and other methods, and also to perform Big-O analysis on them. Hopefully I'll be able to delve into them more in the future.
Sunday, March 30, 2014
Sunday, March 23, 2014
Week 10: The Home Stretch
Oh boy, the last two weeks of class are finally here. We're really coming close to the end now. All in all, these week was pretty anti-climactic. Well, aside from my absolute insanity delving from trying to make assignment 2 work (spoilers: it didn't). I wrote some code as best as I could that would make some regexes work and some regexes ....not work, let's just leave it at that.
Lab was, in a nutshell, very interesting, kind of confusing, but in no way unexpected. It combined everything that we were working toward in the other labs (BSTNodes and Linked Lists) and smushed them into one neat package. Figuring out how to traverse these insane data structures was quite the feat, but in the end it all worked out. Although, I found myself staring at this diagram for what seemed like quite a long time:
In lecture, we discussed what might possible be the bane of my and many a computer science student's existence: Big-O analysis. Going through this in 165 is enough. Two courses? You've got to be kidding me. Thankfully, this side of it is more short analysis than writing out proofs dozens of lines long.
Until next time, where I talk to you alllllllll about sorting methods.
Lab was, in a nutshell, very interesting, kind of confusing, but in no way unexpected. It combined everything that we were working toward in the other labs (BSTNodes and Linked Lists) and smushed them into one neat package. Figuring out how to traverse these insane data structures was quite the feat, but in the end it all worked out. Although, I found myself staring at this diagram for what seemed like quite a long time:
In lecture, we discussed what might possible be the bane of my and many a computer science student's existence: Big-O analysis. Going through this in 165 is enough. Two courses? You've got to be kidding me. Thankfully, this side of it is more short analysis than writing out proofs dozens of lines long.
Until next time, where I talk to you alllllllll about sorting methods.
Sunday, March 16, 2014
Week 9: Assignment Two Part Two: Electric Boogaloo
Here we go, the home stretch of the course. It really feels weird to be almost done so quickly, but maybe that's just because I still haven't adapted to the shorter amount of time University is to High School, even after two years.
As usual, lab this week was quite interesting. I really do enjoy the labs, seeing as you are able to get immediate feedback on your work and the learning process is quite easy. This lab dealt with Binary Search Trees, which took me a while to understand since I'm very unobservant and didn't realize the mechanics of how they worked. Aside from that, the labs are probably my most consistent source of full marks for this course *nervous laughter*.
I haven't really begun to look at assignment two part two so far yet, but judging from what I've seen on piazza it's gonna be quite a doozy. Here's hoping that it gets done in time. All I'll need is a couple sleepless nights, monster energy drinks, and some adderall. Just kidding. Please don't do drugs.
Until next week.
As usual, lab this week was quite interesting. I really do enjoy the labs, seeing as you are able to get immediate feedback on your work and the learning process is quite easy. This lab dealt with Binary Search Trees, which took me a while to understand since I'm very unobservant and didn't realize the mechanics of how they worked. Aside from that, the labs are probably my most consistent source of full marks for this course *nervous laughter*.
I haven't really begun to look at assignment two part two so far yet, but judging from what I've seen on piazza it's gonna be quite a doozy. Here's hoping that it gets done in time. All I'll need is a couple sleepless nights, monster energy drinks, and some adderall. Just kidding. Please don't do drugs.
Until next week.
Sunday, March 9, 2014
Week 8: Assignment #2 and other cool things
Leave it to me to procrastinate the entirety of assignment 2's first part until... 12 hours before due date. How do I keep doing that?
Thankfully, this part of the assignment was actually quite simple once you got down to figuring out how the inheritance structure worked. It also borrowed quite a few elements from the already-implemented Tree class shown in lectures which made the process even simpler.
Now, we wait for the second part.
The good thing about this course is that even if I'm completely flubbing the midterms, I'm still learning and building upon my knowledge. Recursion is still an iffy topic for me, but I'm still hella impressed with myself for amassing so much knowledge of programming since I didn't even know what a for loop was a few months ago.
Nonetheless, I'm ready to take whatever this course (and PoST) throws at me next.
Thankfully, this part of the assignment was actually quite simple once you got down to figuring out how the inheritance structure worked. It also borrowed quite a few elements from the already-implemented Tree class shown in lectures which made the process even simpler.
Now, we wait for the second part.
The good thing about this course is that even if I'm completely flubbing the midterms, I'm still learning and building upon my knowledge. Recursion is still an iffy topic for me, but I'm still hella impressed with myself for amassing so much knowledge of programming since I didn't even know what a for loop was a few months ago.
Nonetheless, I'm ready to take whatever this course (and PoST) throws at me next.
Saturday, March 1, 2014
Week 7: Recursion
Hoo boy, recursion. What a super fun topic.
In all honesty, this is one of the most frustrating parts of programming, especially for a newbie like me. Figuring out how to recursively call your function and implement it has given me major headaches. Fortunately, I'm getting better at it and am able to understand it (at least a bit).
We just used it in our lab, where we also learned about the LinkedList class, something that works a bit like the Tree class, but only links to one other element. We had to implement prepend, decapitate, and insertion methods that used recursion to trace the lists and perform the function on them - letting us treat LinkedLists like the normal list type found in python.
I know that this is really just the start of my ~*~*~wondrous~*~*~ journey with recursion, and it definitely won't be the last I see of it.
Now, to get started on A2...
In all honesty, this is one of the most frustrating parts of programming, especially for a newbie like me. Figuring out how to recursively call your function and implement it has given me major headaches. Fortunately, I'm getting better at it and am able to understand it (at least a bit).
We just used it in our lab, where we also learned about the LinkedList class, something that works a bit like the Tree class, but only links to one other element. We had to implement prepend, decapitate, and insertion methods that used recursion to trace the lists and perform the function on them - letting us treat LinkedLists like the normal list type found in python.
I know that this is really just the start of my ~*~*~wondrous~*~*~ journey with recursion, and it definitely won't be the last I see of it.
Now, to get started on A2...
Subscribe to:
Posts (Atom)