background preloader

Data Structure Visualization

Data Structure Visualization

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. Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne

XOR swap algorithm Using the XOR swap algorithm to exchange nibbles between variables without the use of temporary storage The algorithm[edit] Conventional swapping requires the use of a temporary storage variable. Using the XOR swap algorithm, however, no temporary storage is needed. The algorithm is as follows:[1] The algorithm typically corresponds to three machine code instructions. In the above System/370 assembly code sample, R1 and R2 are distinct registers, and each XR operation leaves its result in the register named in the first argument. However, the algorithm fails if x and y use the same storage location, since the value stored in that location will be zeroed out by the first XOR instruction, and then remain zero; it will not be "swapped with itself". sets x to zero (because x = y so X XOR Y is zero) and sets y to zero (since it uses the same storage location), causing x and y to lose their original values. Proof of correctness[edit] The binary operation XOR over bit strings of length as where and

Rope (data structure) A simple rope built on the string of "Hello_my_name_is_Simon". In computer programming a rope , or cord , is a data structure for efficiently storing and manipulating a very long string . For example, a text editing program may use a rope to represent the text being edited, so that operations such as insertion, deletion, and random access can be done efficiently. [ 1 ] Description [ edit ] A rope is a binary tree . The binary tree can be seen as several levels of nodes. Operations [ edit ] Index [ edit ] Definition: Index(i) : return the character at position i Time complexity: O(log N) where N is the length of the rope To retrieve the i -th character, we begin a recursive search from the root node: // Note: Assumes 1-based indexing. function index( RopeNode node, integer i) if node.weight < i then return index(node.right, i - node.weight) else if exists(node.left) then return index(node.left, i) else return node.string[i] endif endif end Split [ edit ] Time complexity: O(log N)

CompSci 101 - Big-O notation I recently had a couple of Google interviews in Tokyo, and while preparing for them I ended up with a huge list of things I wanted to brush up on before the interview. It turns out I didn’t get the job (next time!), but I thought I might be able to learn something anyway by working through the list and blogging about the main areas that companies like Google expect you to know. I’ve grabbed the domain computerscience101.org (which currently redirects back here), and when I’ve collected enough posts I plan to throw everything up there as a kind of chapter-by-chapter interview-primer in the hope that it might help someone else out. Without further ado, first on the list is Big-O notation: So what is Big-O notation anyway? Big-O measures how well an operation will “scale” when you increase the amount of “things” it operates on. Big-O can be used to describe how fast an algorithm will run, or it can describe other behaviour such as how much memory an algorithm will use. Common complexity cases

Fisher–Yates Shuffle Say you had a fresh pack of cards: If you want to play a game of Texas Hold ‘em with friends, you should shuffle the deck first to randomize the order and insure a fair game. But how? A simple but effective way of doing this is to pull a random card from the deck repeatedly and set it aside, incrementally building a new stack. But let’s say instead of a physical deck of cards, you wanted to write code to perform this same task with an in-memory array of n elements. One slow option—gotta start somewhere: pick a random element from the array (in [0, n - 1]) and then check if you’ve shuffled that element already. Here’s what the implementation looks like in JavaScript, not that you should use it: function shuffle(array) { var copy = [], n = array.length, i; while (n) { i = Math.floor(Math.random() * array.length); if (i in array) { copy.push(array[i]); delete array[i]; n--; } } return copy; } This is bad, and we can do better. Comments?

Algoritmi e Programmazione Avanzata 01 President Obama’s Dragnet Those reassurances have never been persuasive — whether on secret warrants to scoop up a news agency’s phone records or secret orders to kill an American suspected of terrorism — especially coming from a president who once promised transparency and accountability. The administration has now lost all credibility. Mr. Based on an article in The Guardian published Wednesday night , we now know the Federal Bureau of Investigation and the National Security Agency used the Patriot Act to obtain a secret warrant to compel Verizon’s business services division to turn over data on every single call that went through its system. A senior administration official quoted in The Times offered the lame observation that the information does not include the name of any caller, as though there would be the slightest difficulty in matching numbers to names. That is a vital goal, but how is it served by collecting everyone’s call data? But what assurance do we have of that, especially since Ms.

Maze Generation: Growing Tree algorithm # An implementation of the "Growing Tree" algorithm. This one is # notable for it's ability to become nearly identical to Prim's # algorithm, or the Recursive Backtracking algorithm, depending on # how the cells are removed from the list that aggregates as the # algorithm runs. # This script allows you to play with those settings by specifying # the mode after the width and height parameters, as "random" (pull # the cell from list at random), "newest" (pull the newest cell), # "middle" (pull the cell from the middle of the list), "oldest" # (pull the oldest cell), or a combination of any of these, e.g # ruby growing-tree.rb 10 10 newest:50,random:50 # That would select the newest cell half of the time, and a random # cell the other half of the time. # commands as well, to be chosen in order, by separating them with # semicolons; each subcommand may then be a comma-delimited list of # options to select randomly: # ruby growing-tree.rb 10 10 "newest;newest;oldest,middle" # see what you get! # 1. # 2. end

Related: