algorithm

Time table modeling in relational db

I know that it has been told almost anything related to time table modeling in RDBS, but i can not find any well written documentation about available techniques to store time tables in DB. My case: I have table witch holds available places, and table with actual classes. Each place has it's own unique schedule Each class can be sched...

algorithm to enumerate all possible paths

Consider the following graph: I'm trying to find a way to enumerate all possible paths from a source node to a target node. For example, from A to E, we have the following possible paths: A B C D E A B C E A C D E A C E Note that for A C D E, there are actually 2 paths, since one of the paths uses edge F3 and the other uses edge F5...

Find the number in an array which occurred most number of times

Hi, Given an integer array, i need to find which number occurred most number of times. I have written algorithm as below. Use a map to store number and number of times it occurred. map<int, int> Key: represents the number value: represents number of times key occurred. Scan input array and update the map with number ...

General DFS on River Crossers

I'm trying to write a DFS to solve multiple river crossing problems (Fox Goat Cabbage, Jealous Husbands, Mercenaries and Cannibals, etc.). I've written the puzzle classes, but I'm having trouble structuring my solver. I understand how DFS works, but I can't figure out where to start to adapt it to this design. Each puzzle has a move() m...

NP-Hard solution question

Hello, i have NP hard problem. Let imagine I have found some polynomial algorithm that find ONLY one of many existing solutions of that problem, but at least one solution (if present in the probem). Is that algorithm considered as solution of NP=P question (if that algorithm transformed to mathematical proof)? Thanks for answers ...

Insertion Sort on an array of strings in C#

If I have an array of strings, such as string[] names = {"John Doe", "Doe John", "Another Name", "Name Another"}; How do I sort this array, using insertion sort? Wikipedia has some examples: https://secure.wikimedia.org/wikibooks/en/wiki/Algorithm_implementation/Sorting/Insertion_sort#C.23 static void InsertSort(IComparable[] array)...

splitting the bill algorithmically & fair, afterwards :)

I'm trying to solve the following real-life problem you might have encountered yourselves: You had dinner with some friends and you all agreed to split the bill evenly. Except that when the bill finally arrives, you find out not everyone has enough cash on them (if any, cheap bastards). So, some of you pays more than others... Afterwa...

Brute-force, single-threaded prime factorization

Up for consideration is the following function which can be used to (relatively quickly) factor a 64-bit unsigned integer into its prime factors. Note that the factoring is not probabalistic (i.e., it is exact). The algorithm is already fast enough to find that a number is prime or has few very large factors in a matter of several second...

Algorithm to find an image in an array using minimum size constraint

Hello, I have an array containing image objects. I am looking for an image nearest my size constraint. For exemple I want an image equal to 400x600 or nearest. By nearest I mean nearest by size, a little bit bigger or smaller. I am not looking for an implementation just for an algorithm. Do you have an idea how to achieve this ? Tha...

Mapping Two Continuous Sorted Integer Sets onto One Integer Set

I have an algorithms problem you should help me out with: I am trying to map two continuous sorted integer sets (with potentially differing number of items) to a single continuous sorted integer set preserving linear spacing. e.g. A: {1,2,3} B: {1,2,3,4} could map onto C: {1,2,3,4,5,6,7} by A: {1->1, 2->4, 3->7} and B: {1->1, 2->3, 3->5...

Is there a pseudo-random number generator simple enough to do in your head?

Are there are any pseudo-random number generators that are easy enough to do with mental arithmetic, or mental arithmetic plus counting on your fingers. Obviously this limits to fairly simple math - it needs to be something someone of average mathematical ability can do, or maybe average ability for a programmer, not a math prodigy. The...

Resumee matching algorithm

I am building a job site -- yes, there isn't enough of those yet. One of the problems I came across in my research is how to match the relevant resumes to the interested recruiters. The most boring solution I thought of is to use textual analysis to parse the resumes for tags recruiters specify -- which has a drawback: the resume might b...

example algorithm for generating random value in dataset with normal distribution?

I'm trying to generate some random numbers with simple non-uniform probability to mimic lifelike data for testing purposes. I'm looking for a function that accepts mu and sigma as parameters and returns x where the probably of x being within certain ranges follows a standard bell curve, or thereabouts. It needn't be super precise or ev...

Exhibiting an algorithm that determines if L = L*, given any regular language L

I am studying membership algorithms and I am working on this particular problem which says the following: Exhibit an algorithm that, given any regular language L, determines whether or not L = L* So, my first thought was, we have L* which is Kleene star of L and to determine if L = L*, well couldn't we just say that since L is regular,...

Are there any open source Hierarchical Temporal Memory libraries?

I'm potentitally interested in the using Hierarchical temporal memory heuristic to solve a research problem I am working on. Some more details about it can be found here: http://en.wikipedia.org/wiki/Hierarchical_temporal_memory Are there any open source libraries for this? (I'm fairly open to languages although c++, java or haskell is ...

Graph theory questions from my Algorithms quiz today that I'd like help understanding

Today I had my algorithms quiz for the semester and I can't figure out these two questions and they've been bugging me all day. I've gone through my notes and the lecture notes and I'm still unsure. I would appreciate it if someone could take a look and provide some insight into these questions. These are not homework and I've already sa...

Combinatorial optimization

Suppose we have a connected and undirected graph: G=(V,E). Definition of connected-set: a group of points belonging to V of G forms a valid connected-set iff every point in this group is within T-1 edges away from any other point in the same group, T is the number of points in the group. Pls note that a connected set is just a connec...

What is the runtime difference between different parsing algorithms?

There are lots of different parsing algorithms out there (recursive descent, LL(k), LR(k), LALR, ...). I find a lot of information about the different grammars different types of parser can accept. But how do they differ in runtime behavior? Which algorithm is faster, uses less memory or stack space? Or to put this differently - which ...

String pattern/algorithm for PIN & PUK generated from MSIN

I wonder how mobile phone companies generate both PIN and PUK for their SIM cards? I have a large database of already generated codes, this database contains 3 columns: * MSIN : Mobile Subscriber Identification Number (10 digits) * PIN : Personal Identification Number (4 digits) * PUK : Personal Unblocking Code (8 digits) So far, may...

Dynamic Frequency Evaluation on Massive Random Numbers

I use a random function(Let's call it randomNum()) to generate random numbers(unsigned long) continuously(will generate about one million numbers in total).My question is How to determine whether the frequency of current number generated is greater than 20%(among the total numbers generated so far) efficiently? Please write down your op...