algorithm

Algorithm to find the maximum subsequence of an array of positive numbers . Catch : No adjacent elements allowed

For example , given A = [1,51,3,1,100,199,3], maxSum = 51 + 1 + 199 = 251. clearly max(oddIndexSum,evenIndexSum) does not work. The main problem I have is that I can't come up with a selection criterion for an element. A rejection criterion is trivial given a selection criterion. The standard maximum sub-sequence algorithm doesn't se...

Easy way to find Subtree in a Tree

I'm writing some code that uses a Tree (a regular tree that can have an unlimited number of nodes, but no crossover, i.e. two parent nodes will not point the the same child node). Anyway, two things: 1) Are there any well-known algorithms for finding a sub-tree within a tree. 2) Are there any Java libraries (or any libraries for that ...

Rounding to nearest 100

First number needs to be rounded to nearest second number. There are many ways of doing this, but whats the best and shortest algorithm? Anyone up for a challenge :-) 1244->1200 1254->1300 123->100 178->200 1576->1600 1449->1400 123456->123500 654321->654300 23->00 83->100 ...

How to choose group of numbers in the vector

I have an application with some probabilities of measured features. I want to select n-best features from vector. I have a vector of real numbers. Vector is normalized, sum of all numbers is 1 (it is probability of some features). I want to select group of n less than N (assume approx. 8) largest numbers. Numbers has to be close togethe...

Basic Pixel/Cell Counting Algorithm

Good night :) I am currently playing with the DevIL library that allows me to load in image and check RGB values per pixel. Just as a personal learning project, I'm trying to write a very basic OCR system for a couple of images I made myself in Photoshop. I am successfully able to remove all the distortions in the image and I'm left wi...

How much is it fair to assume about implementation when doing big-O calculations?

When programmers versed in a wide variety of languages are discussing the merits of an algorithm expressed in pseudocode, and the talk turns to efficiency, how much should be assumed about the performance of ultimate the language? For example, when I see something like: add x to the list of xs I see an O(1) operation (cons), while so...

Artificial Intelligence Search Question

Hello, everybody. I am working on a university timetable scheduler project. Mainly, I am using taboo search, but I want to ask: In general search, you can explore all neighbors of the current state and then take the best state - according to a fitness or evaluation function, - but in such a project, generating all neighbors will make p...

Find all duplicates and missing values in a sorted array

Suppose you have a sorted range (x to y) of values in an array. x = 3; y = 11; array == 3, 4, 5, 6, 7, 8, 9, 10, 11 But it is possible that some values are duplicated and some are missing, so you might have: array == 4, 5, 5, 5, 7, 8, 9, 10, 10 What's the best way in your language to find all duplicates and missing values so you g...

Clone detectors

Anyone know some good clone detectors? I'm searching for examples and algorithms on how they work to study them. A clone detector is a program that detect repeated code in the src file. An example of a clone detector I already found, was this for eclipse: http://www.cs.mcgill.ca/~swevo/clonetracker/ But I'm really interested is in d...

Obtaining numeric/normalized representation of strings to aid in 'natural sort ordering' of titles in DB

I'd like to store an additional column in a table as a 'sort value', which is a numeric representation of the title column, such that the order of such values represents the string's natural alphabetical sort order. Ie, so that I can retrieve rows ordered by the sort value, and they'll be in natural sort order - and when I insert a new ...

Finding the farthest point in one set from another set

My goal is a more efficient implementation of the algorithm posed in this question. Consider two sets of points (in N-space. 3-space for the example case of RGB colorspace, while a solution for 1-space 2-space differs only in the distance calculation). How do you find the point in the first set that is the farthest from its nearest ne...

Algorithm for matching lists of integers

For each day we have approximately 50,000 instances of a data structure (this could eventually grow to be much larger) that encapsulate the following: DateTime AsOfDate; int key; List<int> values; // list of distinct integers This is probably not relevant but the list values is a list of distinct integers with the property that for a ...

How does MPEG4 compression work?

Can anyone explain in a simple clear way how MPEG4 works to compress data. I'm mostly interested in video. I know there are different standards or parts to it. I'm just looking for the predominant overall compression method, if there is one with MPEG4. ...

How to design an efficient algorithm for least upper bound search

Let's say you have some set of numbers with a known lower bound and unknown upper bound, i.e. 0, 1, 2, 3, ... 78 where 78 is the unknown. Assume for the moment there are no gaps in between numbers. There is a time-expensive function test() that tests if a number is in the set. What is an efficient way (requiring a low amount of test() c...

Seeking algorithm to invert (reverse? mirror? turn inside-out) a DAG

I'm looking for an algorithm to "invert" (reverse? turn inside-out?) a DAG: A* # I can't ascii-art the arrows, so just / \ # pretend the slashes are all pointing B C # "down" (south-east or south-west) / / \ # e.g. G E D # A -> (B -> G, C -> (E -> F, D -> F)) \ / F ...

Stemming - code examples or open source projects?

Stemming is something that's needed in tagging systems. I use delicious, and I don't have time to manage and prune my tags. I'm a bit more careful with my blog, but it isn't perfect. I write software for embedded systems that would be much more functional (helpful to the user) if they included stemming. For instance: Parse Parser Par...

Algorithm to allocate a list of numbers to N groups under certain condition

Let's say I have a list of numbers: 2,2,3,4,4 Split the numbers into N groups (3 groups here as an example): A:2,3 sum:5 B:4 sum:4 C:2,4 sum:6 What I want is to minimize (the group with the highest sum (6 here) - the group with the smallest sum (4 here)) Does anyone think of an algorithm to achieve this? Another example: 7,7,...

Orbital equations, and power required to run them

Due to a discussion on the SO IRC today, I'm curious about orbital mechanics, and The equations needed to solve orbital problems The computing power required to solve complex problems The question in particular is calculating when the Earth will plow into the Sun (or vice versa, depending on the frame of reference). I suspect that a...

Sum array values with sum equals X.

I have an integer collection. I need to get all possibilites that sum of values are equal to X. I need something like this. It can be written in: delphi, c#, php, RoR, python, cobol, vb, vb.net ...

Pairwise priority queue

I have a set of A's and a set of B's, each with an associated numerical priority, where each A may match some or all B's and vice versa, and my main loop basically consists of: Take the best A and B in priority order, and do stuff with A and B. The most obvious way to do this is with a single priority queue of (A,B) pairs, but if there...