background preloader

Dictionary of Algorithms and Data Structures

Dictionary of Algorithms and Data Structures

Highly Efficient 4 Way Merging Acknowledgements: This article is based on the work of Peter Sanders and Roman Dementiev. You can find the full source code presented here in their STXXL library (STL library for large data structures), Peter Sanders' paper and the accompanying source code. Warning: If you are of sensitive nature either regarding computer science theory highly practical program optimization then I recommend you to stop reading this article at once. You might faint or something. /* Merge two already sorted arrays where both are terminated * by 0x0fff ffff which may not appear *inside* arrays. */ void merge2(int a[], int b[], int result[]) { int i = 0, j = 0, k = 0; while (true) { if (a[i] <= b[j]) { result[k] = a[i]; i += 1; k += 1; } else { result[k] = b[j]; j += 1; k += 1; } if (result[k] == 0x0fffffff) return; } } If you are like me you do not think about Mergesort any more after understanding it and writing the exam it is relevant for. OK, so we are all fluffy and set now, aren't we? template Updates

Anti-Aliased Line Drawing First, let's start with an example to show why we want to use anti-aliased lines. The lines on the left are drawn with something like Bresenham's line algorithm. The lines on the right are drawn with an extended form of Bresenham's which anti-aliases. They are shown both at normal size and 4x zoom. Which do you think looks better? For MP4, you need to implement the one on the right. Just take me to the algorithm! There are several models one can use to draw anti-aliased lines, with differing quality results. But when I want to display that on a screen, and my units above are individual pixels, I simply cannot draw that. Rasterization So what should I do? For x = x0 to x1 y = (y1-y0) * (x - x0) / (x1 - x0) + y0 DrawPixel (x, y) End For And would result in something like Figure B. Now, this algorithm has several downfalls: There is a multiplication and a divide for every pixel. What can I do about it? There are two main categories of problems we want to address now: Speed and Appearance.

Functional Programming in C# 3. As a developer who was raised on procedural and object oriented programming languages like C, C++ and Java it took me a while to figure out what people were raving about when it comes to the benefits of functional programming techniques. I always thought closures and higher order functions were words used by snobby kids from MIT and grad students to show how overeducated they were as opposed to programming tools I'd ever find useful. This thinking was additionally fueled by articles like Joel Spolsky's Can Your Programming Language Do This? which not only came off as snobby but also cemented the impression that higher order functions like map() and reduce() are for people solving "big" problems like the folks at Google who are trying to categorize the entire World Wide Web not people like me who write desktop feed readers in their free time. All of this changed when I started learning Python. There are more examples from the RSS Bandit code base but I'm sure you get the idea.

Collected Algorithms of the ACM blog » Blog Archive » Game of Life text and image generator g I saw this image the other day on Hacker News and Reddit: It’s a Game of Life pattern that prints out “Golly”. Neat, but I wanted my own. After about 5 minutes of playing around with the Golly logo pattern in Golly (a program for experimenting with the Game of Life), I gave up and wrote a program to do it. The program takes the top and bottom portions of a template pattern (based on the Golly pattern) and positions them, then fills in the gliders between them for the correct number of columns. This was great, but I had essentially created a dot matrix printer that could draw anything, so it would be a waste to not draw images with it. The code is available on GitHub. Download Golly to open up the generated “.rle” files.

Related: