algorithm

Small World Theory implementation - like in XING

Some probably wont know what XING is: it is a online network community like linkedIn etc. You can add new contacts, manage these contacts, search for new etc. The whole application is done in Ruby and somewhat inspired by the small world theory, at least it is said so. There is one specific feature that I really cant imagine how it is...

List circular group membership from active directory

We have 40K+ groups in our active directory and we are increasingly facing problem of circular nested groups which are creating problems for some applications. Does anyone know how to list down the full route through which a circular group membership exists ? e.g. G1 --> G2 --> G3 --> G4 --> G1 How do I list it down. ...

Find longest repeating strings?

I have some HTML/CSS/JavaScript with painfully long class, id, variable and function names and other, combined strings that get used over and over. I could probably rename or restructure a few of them and cut the text in half. So I'm looking for a simple algorithm that reports on the longest repeated strings in text. Ideally, it would r...

How can I tail a zipped file without reading its entire contents?

I want to emulate the functionality of gzcat | tail -n. This would be helpful for times when there are huge files (of a few GB's or so). Can I tail the last few lines of such a file w/o reading it from the beginning? I doubt that this won't be possible since I'd guess for gzip, the encoding would depend on all the previous text. But s...

Spiral Algorithm in C#

Hi, How can I fill an array like so: 1 2 3 4 5 6 7 8 20 21 22 23 24 9 19 30 31 32 25 10 18 29 28 27 26 11 17 16 15 14 13 12 Spiral C# Thanks ...

Is there a repository of test input, with answers, for algorithms (especially graph algorithms)?

As a summer project, I have decided to practice basic algorithms and learn Haskell at the same time, by implementing large chunks of CLRS in Haskell. Things are going pretty swimmingly, so far, but since I started graph algorithms, I've noticed a lack: test input and output! For example, I've implemented Floyd-Warshall's algorithm, and ...

Algorithm for generating a 'top list' using word frequency.

I have a big collection of human generated content. I want to find the words or phrases that occur most often. What is an efficient way to do this? ...

Packaging Algorithm

Good Day! I'm trying to see if there is any way to accomplish this. I've got a set of items, with associated attributes (Weight, Length, Width). I've also got a set of Packaging Types, with associated attributes (Max Weight, Length, Width) I'm looking for an algorithm to determine the LEAST amount of boxes to package the items into. ...

Algorithms to identify Markov generated content?

Markov chains are a (almost standard) way to generate random gibberish which looks intelligent to untrained eye. How would you go about identifying markov generated text from human written text. It would be awesome if the resources you point to are Python friendly. ...

Data structure optimized for lowest-complexity recursion from deepest to shallowest nodes?

I'm looking a data structure or algo (to be implemented in C) that will provide low time-complexity recursion from the deepest nodes to the shallowest nodes in a complex, nested structure. The application is protocol encoding, where each element must know its size (the combined size of its data, and any member elements). I've been bang...

merge sort implementation to sort by string length - python

I've implemented what I believe to be a merge sort algorithm in python. I've never programmed in Python before, so I used several resources with commands that seemed foreign to me, to gain a better understanding. However, I've also never implemented merge sort in the first place, so I'm not sure if I've even implemented it correctly....

How to solve the "Mastermind" guessing game?

How would you create an algorithm to solve the following puzzle, "Mastermind"? Your opponent has chosen four different colours from a set of six (yellow, blue, green, red, orange, purple). You must guess which they have chosen, and in what order. After each guess, your opponent tells you how many (but not which) of the colours you guess...

Best way to convert a flat list to a set of two-tuples in Erlang?

Is there a fast way to convert a flat list into a list of two-tuples such that a flat list like [1,2,3,4,5,6] becomes [{1,2},{3,4},{5,6}]? This works, but it feels just plain WRONG: tuples_from_flat_list(Target) -> TargetWithIndex = lists:zip(lists:seq(1, length(Target)), Target), {K, V} = lists:partition(fun({I, _}) -> I rem 2...

Whats the algorithm to calculate aspect ratio? I need an output like: 4:3, 16:9

I plan to use it with javascript to crop an image to fit the entire window. I appreciate all help you can provide. Edit: I'll be using a 3rd part component that only accepts the aspect ratio in the format like: 4:3, 16:9 ...

Sliding window algorithm in C#

I'm trying to implement simple sliding window alogirithm on two-dimensional array in C# 3.0, I found this as very useful but it involves only single-dimensioal array. The post also includes the code for the algo, I'm totaly failed to use it for my senario... can any one suggest me how do I proceed? Scenario: The above image is 10X...

Algorithm for a graph problem

I need to check the connectedness of directional nodes in a list. It is basically questions with 2 to 7 answers each. The answer picked dictates the next question. Since these pairs will be manually captured, I need to check each possible path for looping back (not allowed) and dead ends (all routes must stop at the END node) Any pointer...

Cache Invalidation - Is there a General Solution?

"There are only two hard problems in Computer Science: cache invalidation and naming things." Phil Karlton Is there a general solution or method to invalidating a cache; to know when an entry is stale, so you are guaranteed to always get fresh data? For example, consider a function getData() that gets data from a file. It caches i...

Mathematical notation in algorithms

I am currently reading the Algorithm Design Manual, but my mathematical notation has become a little rusty. What does mean? ...

Good algorithm for finding the diameter of a (sparse) graph?

I have a large, connected, sparse graph in adjacency-list form. I would like to find two vertices that are as far apart as possible, that is, the diameter of the graph and two vertices achieving it. I am interested in this problem in both the undirected and directed cases, for different applications. In the directed case, I of course ...

What is the best way to architect a "find nearest" location-aware application on the iPhone?

I would like to build a location-aware application that automatically detects a user's location and presents them a sorted list of the nearest landmarks from a landmark database. The application will be built on the iPhone. The fundamental questions are: How to calculate the distances to nearby landmarks and sort by "closest" Where to...