Wednesday, March 30, 2016

Revisiting a Post - on Abstract Data Types, Linked Lists, and Memory

In my post on Thursday, February 11th, I said that I would learn more about hash tables, how linked-lists save memory, and data structures and sorts in general. After reading a lot more about data structures and efficiency (in Big O notation), I feel like I've learned enough to answer some questions.

From reading the WikiBook Data Structures, as well as perusing through many, many Harvard C50 videos, I know now that linked-lists generally simplify matters because data doesn't have to be stored contiguously. In addition, arrays have to have a preset size, so in order to grow arrays, they need to be completely copied to a larger array. which takes O(n) time, amortized to O(1) (since we do it 1/n of the time). However, linked lists can be dynamically resized. The main disadvantage to linked-lists is that searching elements takes O(n) time in the worst case, while it takes O(1) time in an array.

In addition, I learned about many other data structures, such as hash tables, red-black trees, and tries. Each has their own advantages and disadvantages, and often I've learned that there's a trade-off between time-complexity and space-complexity for data structures. In addition, in regards to sorting algorithms. I learned and became comfortable with all the standard algorithms taught in class such as bubble sort, insertion sort, selection sort, merge sort, and quick sort, but also learned about heap sort (another data structure I learned about was a heap), counting sort, and radix sort.

So in all, what's happened since the beginning of last February? I feel like every blog post I've made so far has shown a new subject that I learned about, or a new area that I'm interested in - and at the end of it all, I feel like I've done a pretty good job, on my own time, to learn some pretty interesting and useful material in this subject. I've taken the topics that we've learned in class and searched them up, so that I get more comfortable with them, but also because I have a desire to scratch more than the surface. In essence, I feel like this is the basis of learning - a desire to scratch beyond the surface. To find out what you're not being told. And I feel like I've embraced that, and learned immensely.

Friday, March 25, 2016

Assignment 2

This past week, we finished assignment 2. Although we hadn't learned anything about algorithm efficiency yet for the assignment, I had already found myself trying to speed things up throughout the assignment, in any ways that I knew - often trying to implement the most clever strategy or failfast for a game. Overall, the assignment went quite smoothly, and though there was indeed some debugging to be done, I feel that the process of debugging taught me more about my program.

The sudoku game was quite simple to implement - most of the methods were already implemented, and there were very clear instructions on how to implement the last one.

The word ladder game was simple to implement - but we took quite a long time thinking of an effective failfast for the game - as we saw the the text file had almost 100k words, we were thinking of ways to optimize the game's searching so we wouldn't have to go through 100k words every time.

The grid peg solitaire game was actually quite difficult to implement - its implementation was mostly the same as the MN-puzzle's implementation, but we were caught off guard by the fact that our grids would be affected by each swap when creating extensions - so we would create far more extensions than desired. We fixed it with a deepcopy.

The MN puzzle's usage of tuples was quite annoying, as we wanted to change variables within the puzzle for the extensions, but had to go through a convoluted method of creating lists and then changing back into tuples - I feel like there should be a more clever way to solve the problem, but this was the implementation that we went with. Importantly, for the MN puzzle, I used some theory that I picked up on CSC240 and MAT495, proving that there's always an invariant for the puzzle, and thus we implemented an effective fail-fast which could tell immediately whether a puzzle was solvable or not.

Initially, we wanted to use recursion to implement the searches, but we couldn't figure out how to keep track of the visited configurations with recursion - so instead we used the deque and implemented both searches iteratively with a while loop.

Most of the puzzles run quite quickly - the longest would be the sudoku puzzle 2 - which can take up to 2 minutes if we're unlucky, but can take as little as 10 seconds. The other puzzles all take well under 1 minute, many in fractions of seconds.

Thursday, March 17, 2016

Binary Trees, and then Assignment 2

This past week, we've been working on binary trees, had our second midterm, and will have assignment 2 due in about a week.

I feel like binary trees are a good specialization of the general Tree structure - they model real world yes/no decision making, as well as predicate/propositions (things that can evaluate to 2 things) quite well. In addition, they can represent binary operations such as the basic arithmetical operations, as we have shown in class. In all, I feel quite comfortable with the recursive processes applied onto binary trees, though I do feel that more practice would always help.

I am currently working on assignment 2 - so far, I think it's going to be an interesting assignment (I love solving puzzles regardless).

Thursday, March 10, 2016

Binary (n-ary) Trees

This past week, we worked on binary (and really, generally any arity) trees. In general, I felt that the tree structure is quite an important and intuitive way to think of data - and so I want to spend the next week thinking about and learning about different ways in which trees are used. I know that they're used in searches, in sorts, but I'd also like to find other methods in which to use trees.

In particular, I feel that the power of recursion displays itself quite well when applied to trees - since the set of trees is recursively defined, we can use recursion to characterize and employ functions on trees very easily.

Wednesday, March 2, 2016

Recursion

These past 2 weeks, we've been working on Recursion - what I view to be one of the fundamental concepts in computer science, and also a concept that can result in rather powerful functions being created in simple ways. In terms of class content, I felt that I was quite comfortable with the simpler examples and exercises in recursion presented in class - perhaps because it's a topic that I've dealt with in the past, and which requires some level of mathematical/analytical skill, which I feel is one of my stronger traits as a computer scientist. 

I was quite interested in the concept of solving recurrences, as that links closely to topics that have been covered in other classes that I have taken or am taking (MAT495 and CSC240), and so I found it quite enjoyable to break down a recurrence to understand what it truly does - and in many cases, the function is actually quite complex for a very short segment of code - the power of recurrence, I suppose. 

But in effect, I believe that I was more interested in employing recurrences, and thus I spent quite a deal of time thinking about areas in which recurrences could be used. I was quite intrigued to learn that the recursively defined Fibonacci number function was actually substantially slower than that using a loop (it proceeds in O(2^n), exponential time) and so there were areas where a recurrence might actually be detrimental to a program. However, I also learned over the week that it becomes a much simpler task to employ sorting methods using recurrences, as well as to define tree structures. In fact, I found the tree with directed edges defined under the recurrence method to be quite a clever construction. 

In effect, I'm quite excited to continue learning about recurrences, as well as to employ them in my future ventures wherever necessary and viable.