background preloader

Algo y ritmos

Facebook Twitter

Ruby implementations

Common Data Structures and Algorithms. Estimated Time: 1-2 hrs The basic idea of a data structure is to store data in a way that meets the needs of your particular application.

Common Data Structures and Algorithms

You might be inclined to store a particular kind data in one giant array, but it would be rather time consuming to locate a specific value if you had a significant number and depth of items. So you need to look to other options. Depending on the application, there are a batch of other basic data structures available to help you out. The differences between them typically have to do with trade-offs between how long it takes to first populate the structure, how long it takes to add or find elements, and how large the structure is in memory. We'll save the specifics of data structures for more computer-science-oriented courses, but this introduction should again expand your toolbox slightly so you can identify and solve certain problems where plain old Arrays, Hashes and Sets don't quite cut it.

Points to Ponder. Data Structures and Algorithms. Estimated Time: 6-10 hours Don't forget to use Git to save your projects!

Data Structures and Algorithms

Project 1: Searching Binary Trees You learned about binary search trees -- where you take a group of data items and turn them into a tree full of nodes where each left node is "lower" than each right node. The tree starts with the "root node" and any node with no children is called a "leaf node". You also learned about tree search algorithms like breadth-first-search and depth-first-search. Your Task You'll build a simple binary tree data structure from some arbitrary input and also the "crawler" function that will locate data inside of it. Build a class Node.

Student Solutions Send us your solution so we can show others! Data Structures and Algorithms with OO Design Patterns in Ruby. Ruby Algorithms: Sorting, Trie & Heaps - igvita.com. By Ilya Grigorik on March 26, 2009 A good choice of an algorithm or a data structure can make or break an application.

Ruby Algorithms: Sorting, Trie & Heaps - igvita.com

By and large, Ruby provides enough native primitives such as Array, Hash, and Set, to get you by in most cases, but we've all ran into situations where the performance or the memory footprint of these structures left us wanting for more. Sensing a nice opportunity, Kanwei Li and Austin Ziegler partnered up for the '08 Google Summer of Code (GSoC) to translate some of the most well known algorithms and data structures into Ruby, resulting in implementations of nine different containers and ten different search and sorting algorithms!

And while I would encourage you to explore the entire project, a few aspects deserve special attention: first, there is the question of performance of sorting algorithms in Ruby, and second, Trie, Heap and Priority Queues are data structures worth keeping in mind. Data Structures and Algorithms with Object-Oriented Design Patterns in Ruby. Overview on data structures. Big-O Algorithm Complexity Cheat Sheet. ConciseNotes.pdf. Sorting algorithms in Ruby, Part 1. For fun, I decided to implement some classic sorting algorithms in an object oriented language.

Sorting algorithms in Ruby, Part 1

In this case Ruby. Later I plan to implement some sorting algorithms in a functional language to contrast the differences. For now, here are the algorithms I chose the implement. Bubble sort Selection sort Insertion sort Merge sort I implemented those by reading the textual descriptions of the algorithms on Wikipedia and trying to refrain from looking at actual source code or pseudo code. To test the algorithms I wrote some simple test cases. In these tests I create an unsorted array which I then sort using Ruby’s built-in sort method. Bubble sort The first one is bubble sort. While it can beat some algorithms for nearly sorted arrays, ie: [1, 2, 4, 3, 5, 6], in the real world it’s uses are mostly academic. There are ways to optimize bubble sort. Selection sort Selection sort is another inefficient but simple sort.

The algorithm iterates over the array finding the smallest element. Code golf - Sorting a list of strings without using any built-in sort method - Programming Puzzles & Code Golf Stack Exchange. Current community your communities Sign up or log in to customize your list. more stack exchange communities.

code golf - Sorting a list of strings without using any built-in sort method - Programming Puzzles & Code Golf Stack Exchange

Stable Sorting in Ruby. The process of learning Ruby has brought several surprises.

Stable Sorting in Ruby

Some of which are more pleasant than others. The latest I have encountered is that Array#sort is not stable. For those readers who may not understand what I mean by this, this post starts with a description of what stable sorting is. From there it continues to show why sorting in Ruby is not stable. Lastly I will show a solution to this problem and explain why it works. What is a stable sort? Given a list of compound elements, viz. elements which contain elements, we often need different sorts on different elements. Let’s consider an example. Suppose we wanted to sort this list using the last name as a primary key and the first name as a secondary key. To accomplish this, we would first sort by the secondary key: Then we would sort by the primary key.

Sorting Algorithm Animations. Algorithms in Java, Parts 1-4, 3rd edition by Robert Sedgewick. Addison Wesley, 2003. Quicksort is Optimal by Robert Sedgewick and Jon Bentley, Knuthfest, Stanford University, January, 2002. Dual Pivot Quicksort: Code by Discussion. Bubble-sort with Hungarian (“Csángó”) folk dance YouTube video, created at Sapientia University, Tirgu Mures (Marosvásárhely), Romania. Select-sort with Gypsy folk dance YouTube video, created at Sapientia University, Tirgu Mures (Marosvásárhely), Romania.

Sorting Out Sorting, Ronald M. Big-O Algorithm Complexity Cheat Sheet.