Search. Datastructure. Quicksort. Pagerank. Damn Cool Algorithms: Spatial indexing with Quadtrees and Hilber. Posted by Nick Johnson | Filed under coding, tech, damn-cool-algorithms Last Thursday night at Oredev, after the sessions, was "Birds of a Feather" - a sort of mini-unconference. Anyone could write up a topic on the whiteboard; interested individuals added their names, and each group got allocated a room to chat about the topic.
I joined the "Spatial Indexing" group, and we spent a fascinating hour and a half talking about spatial indexing methods, reminding me of several interesting algorithms and techniques. Spatial indexing is increasingly important as more and more data and applications are geospatially-enabled. Efficiently querying geospatial data, however, is a considerable challenge: because the data is two-dimensional (or sometimes, more), you can't use standard indexing techniques to query on position. Spatial indexes solve this through a variety of techniques. Quadtrees Quadtrees are a very straightforward spatial indexing technique. Geohashes Still, we can do better. Presto! Matching Wildcards: An Algorithm. Essentials of Metaheuristics.
Replacement of Quicksort in java.util.Arrays with new Dual-Pivot. Pathological Programming with Primes (REPOST) I’m currently away on a family vacation, and as soon as vacation is over, I’m off on a business trip for a week. And along the way, I’ve got some deadlines for my book. So to fill in, I’m recycling some old posts. I decided that it’s been entirely too long since there was any pathological programming ’round these parts, so I’m going to repost some of my favorites.
Today’s pathological language is my personal all-time favorite pathological monstrosity. It’s an incredibly combination of perfect simplicity and complete incomprehensibility. It’s based on a piece of work calledFractran by John Conway of game theory fame. It’s a really fascinating bugger; absolutely insanely difficult to program in, but based on one of the most bizarrely elegant concepts of computation that I’ve ever seen.
It’s based on the idea of numbers as products of prime factors. 24 = 2×2×2×3, or 23×31 291 = 3×971800 = 5×5×3×3×2×2×2=52×32×23 Set f equal the first fraction in the list. Let’s look at an example. Evil, huh? Java has Switched From Mergesort to Timsort : compsci. Hash Functions: the modulo prime myth? Longest common subsequence. I pinched the idea for this animation from Ned Batchelder’s clever visualisation of Román Cortés’ brilliant CSS Homer Simpson. It depends on Javascript, CSS and a font containing upwards, leftwards and north west arrows. If it doesn’t work in your user agent, my apologies. If you’d like to find out why I’m comparing humans with chimpanzees, read on!
Retracing our steps Taking a brief step back, this article is the third of a series. Starting with a list of runners ordered by finishing time, select a sublist of runners who are getting younger. In the second episode we coded up a brute force solution which searched all possible sublists to find an optimal solution. In this episode we’ll discuss an elegant algorithm which solves our particular problem as a special case. An outline of the approach is: Simple example As a simple example I’ve highlighted “HMAN”, the longest subsequence common to both “HUMAN” and “CHIMPANZEE” We can also rule out a simple divide and conquer scheme.
Memoize Thanks. Weekday Calculation Algorithm. Collected Algorithms of the ACM. Finding a Loop in a Singly Linked List. Motivation A singly linked list is a common data structure familiar to all computer scientists. A singly linked list is made of nodes where each node has a pointer to the next node (or null to end the list). A singly linked list is often used as a stack (or last in first out queue (LIFO)) because adding a new first element, removing the existing first element, and examining the first element are very fast O(1) operations. When working with singly linked list, you are typically given a link to the first node. Common operations on a singly linked list are iterating through all the nodes, adding to the list, or deleting from the list. Algorithms for these operations generally require a well formed linked list. That is a linked list without loops or cycles in it. If a linked list has a cycle: A malformed linked list with a loop causes iteration over the list to fail because the iteration will never reach the end of the list.
Incorrect "Solutions" Traverse the List Until the End Mark Each Node. Algorithms Animator in Launchpad. Stanford CS Ed Library. Hash Functions. Sorting Algorithms Demo. We all know that Quicksort is one of the fastest algorithms for sorting. It's not often, however, that we get a chance to see exactly how fast Quicksort really is. The following applets chart the progress of several common sorting algorithms while sorting an array of data using in-place algorithms. This means that the algorithms do not allocate additional storage to hold temporary results: they sort the data in place. (This is inspired by the algorithm animation work at Brown University and the video Sorting out Sorting By Ronald Baecker from the University of Toronto (circa 1970!).)
Some of these sorts are very stupid or very slow and should not be used in code. The use of Bubblesort is deprecated. In-Place Mergesort is yet another abomination. New: Radix sort by Alvin Raj, August 13, 2002. Click on each applet to see the algorithm run.Click on the name of the algorithm to see the source. Bubble Sort (by James Gosling and Jason Harrison) Bi-Directional Bubble Sort (by James Gosling) Three Lists problem. Skip this if you don't like my toy-algorithm posts. What I call the "three lists problem" is presented in AdUni's Algorithms course, lecture number five by Prof.
Shai Simonson: Given three lists of numbers A, B and C, find if there exists a triplet x in A, y in B and z in C such that x+y+z=0. Prof. Simonson describes in general three ways of doing this, the brute force method in O(n^3), a slighly smarter method in O(n^2 log n), and finally a neat method in O(n^2). The numbers need to be distributed normally between some number X and -X. In order to compare the running times, you also need to make sure there is only one zero-sum triplet to be found. First the brute force method, which is useful for comparison, and to check the correctness of the other results. Next is the roughly O(N^2 N Log N) method. Finally the neat O(N^2) solution.
Problems I don't intend on fixing: The use of LOOP in the above is primitive. Generating the lists (the test data) is slow, annoying and not shown here. No Free Lunch Theorems. Conversations: Jon Bentley.