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

DelphiForFun Home 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

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?

Archive of Interesting Code The Archive of Interesting Code is an (ambitious) effort on my part to research, intuit, and code up every interesting algorithm and data structure ever invented. In doing so, I hope both to learn the mathematical techniques that power these technologies and to improve my skills as a programmer. In case you're curious what I'm someday hoping to having implemented on this page, you can check out my TODO list. If you're interested in using any of this code in your applications, feel free to do so! You don't need to cite me or this website as a source, though I would appreciate it if you did. Enjoy!

Algoritmi e Programmazione Avanzata 01 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: