algorithm

Comparing SIFT features stored in a mysql database

Hi, I'm currently extending an image library used to categorize images and i want to find duplicate images, transformed images, and images that contain or are contained in other images. I have tested the SIFT implementation from OpenCV and it works very well but would be rather slow for multiple images. Too speed it up I thought I could ...

Resource scheduling problem

I'm developing a motorcycle hire website. The problem I have is how to solve the problem of assignment a guest to a motorcycle in an efficient way. I know how to do it in a "silly" way, but I want to know if there is a classical algorithm that solves this kind of problem. It's the same problem as the assignment of a guest to rooms in a h...

Check whether a line-segment intersects the perpendicular line draw from a particular point?

As shown in this image: I have a set of line segments. I want to check which line-segments intersect with the perpendicular line drawn from a given point (x0,y0). (E.g.: AB passes the check and BC does not.) The only information I've got is two points of the line-segment, (x1,y1), (x2,y2), and the target point (x0,y0). Is it possi...

Bayesian rating system with multiple categories for each rating

I'm implementing a rating system to be used on my website, and I think the Bayesian average is the best way to go about it. Every item will be rated in six different categories by the users. I don't want items with only one high rating to shoot to the top though, which is why I want to implement a Bayesian system. Here is the formula: ...

How to get a specific sequence like this?

There are 100 numbers: 1,1,2,2,3,3,...,50,50 How can I get a sequence which has 1 number between two 1s, and two numbers between two 2s, three numbers between two 3s,..., and fifty numbers between two 50s using the 100 numbers? Does anyone have a better idea than Bruteforce? Or prove it there's no solution when n = 50. Thanks. ...

Finding frequent sequence of numbers in an array

Array (3, 5, 1, 3, 5, 48, 4, 7, 13, 55, 65, 4, 7, 13, 32) the frequent sequence of numbers will be (3, 5) f=2 + (4, 7, 13) f=2 any Algorithm or Pseudo code to find that ? Update(1): if (7, 13) also occurrence it will be included in the longest one by update its frequency so (4, 7, 13) f=3 and so on... Update(2): in case of (1,2,...

faster than in_array?

Dear all, I need to compare a value to a set of array. However, I need to compare multiple values in foreach. If using in_array, it can be slow, real slow. Is there any faster alternative? My current code is foreach($a as $b){ in_array($b, $array); } Thank you. ...

Variation on Travelling salesman problem - pick a good subroute from many nodes based on constraints

TLDR version: Most important issue is, that in a TSP problem, instead of finding the shortest Hamiltonian cycle, what are good ways to find the best path (I suppose the one that visits the most nodes) which is at most X length, with a fixed starting point. Full version: I'm interested in some ideas for a problem that involves TSP. Fir...

Algorithm to calculate the number of combinations to form 100

Hi I am struck in a tricky situation where I need to calculate the number of combinations to form 100 based on different factors. Those are Number of combinations Multiplication factor distance Sample input 1: (2-10-20) It means list the valid 2 way combination to form 100. the distance between the combination should be less ...

Writing Program for desktop that can switch to web

Hi guys, I am being asked to write a desktop application in .net and MSSQL for record keeping. I do have to build forms for keeping records printed in 15 pages or more related to single person. I am fine with seperating data layer and presentation layer. For future i am planning now. My client is gonna ask to make it live [web based] ...

calculating the number of bits using K&R method with infinite memory

I got answer for the question, counting number of sets bits from here. http://stackoverflow.com/questions/109023/best-algorithm-to-count-the-number-of-set-bits-in-a-32-bit-integer long count_bits(long n) { unsigned int c; // c accumulates the total bits set in v for (c = 0; n; c++) n &= n - 1; // clear the least signif...

Is there an algorithm for positioning nodes on a link chart?

I'm a member of a small but fairly sociable online forum, and just for fun we've been plotting a chart of who's met who in real life. Here's what it looked like fairly recently. (The colour is the "distance" from the currently-selected user, e.g., yellow is someone who's met someone who's met them. And no, I'm not Zak.) Apologies for the...

Create smallest unique number from two byte

As we all know a byte range is 0 to 255 i have two byte, I want to create another number that is reversible but with minimum length that combine these two number and create a new one, the simplest solution is a = b1 * 1000 + b2 reverse would be b1 = a / 1000 b2 = a % 1000 the length of above solution varying 0 to 6 length, i want a ...

Minimum size that matches aspect ratio

I need to find the minimum size that has an aspect ratio of exactly (or within 0.001) some value. Are there any quick math tricks or framework tricks for doing this? Here's the pseudo code for the current bad idea I had running in O(n^2): epsilon = 0.001; from x = 1 to MAX_X { from y = 1 to MAX_Y { if(Abs(x / y - aspectRatio) ...

How to generate Generate lighter/darker color PHP?

Hello . I have a code of color. For example #202010 . How to generate a new color code which is either lighter or darker by 20% (or given x%) in php.? Please help me . I see a sample in javascript but i don't understand it. PLEASE HELP ME ...

Create an optimal grid based on n-items, total area, and H:W ratio

I'm creating an application that takes a number of equally sized rectangles and positions them in a grid on the screen. I have most of the logic complete for resizing and centering a rectangle within a cell but I'm having trouble with the actual portion that defines the grid the rectangles must conform to. Ideally, in the end I'd have a...

Algorithm/approximation for combined independent set/hamming distance problem

Input: Graph G Output: several independent sets, so that the membership of a node to all independent sets is unique. A node therefore has no connections to any node in its own set. Here is an example path. since clarification was called for here another re phrasal: divide a given graph into sets so that i can tell a node from all oth...

Convert a number from Base B1 to Base B2 without using any intermediate base.

Hey Guys Is there a way Convert a number from Base B1 to Base B2 without using any intermediate base. Ex: 214 from base 5 to base 16 without converting it first to decimal and then decimal to hexadecimal. -- Thanks Alok Kr. ...

How can I find which jobs in a dependency tree can be run in parallel?

Currently, I am using a graph to store the dependencies and then running all of the vertices the don't have any dependencies. This works, but it feels kludgy. Is there a better algorithm or data structure I should be using? #!/usr/bin/perl use strict; use warnings; use Graph; #FIXME: naive implementation, there may be a much better...

Help with a URL Shortening Algorithm

Could anyone recommend a preferred algorithm to use for URL shortening? I'm coding using PHP. Initially I thought about writing something that would start at a character such as "a" and iterate through requests, creating records in a database and therefore having to increment the character to b, c, d ... A, B and so on as appropriate. H...