algorithm

Algorithm for Room Allocation Using PHP

Hi, I need help with an algorithm to allocate rooms to people. I need to shuffle through a list of rooms to assign a room to a person and after the fourth person is assigned to the room, it should be out of the list(should be unavailable). I have not had any luck with PHP shuffling and sorting functions yet. Any help (pointers, referenc...

Help In Solving Algorithm

Hi Guys, Am suppose to return the number of character comparisons. In the while() loop i compare the index of the characters and update the counter. My question is, is it right to do it that way or i have to compare the characters themselves. I think comparing the index and updating the counter is the same as comparing the characters t...

Chi-Square Test algorithm

Hi all, I'm randomly selecting nodes from a Binary Tree and I have to build a black-box test that proves all nodes have the nearly the same probability of being selected. I'm adapting the Chi-Square test algorithm based on this article http://en.wikibooks.org/wiki/Algorithm_Implementation/Pseudorandom_Numbers/Chi-Square_Test but I'm a ...

Help In Generating Graph From Executing Algorithm

Hi Guys, I am suppose to generate graph from the results/execution of my algorithm . I have heard something about using CSV file in Excel and generating the graph. I have no idea what this CSV file is and how to do it. I googled CSV file but the answer i got was in connection with databases. I am asking if someone can show me or poin...

Retrieve set of rectangles containing a specified point

I can't figure out how to implement this in a performing way, so I decided to ask you guys. I have a list of rectangles - actually atm only squares, but I might have to migrate to rectangles later, so let's stick to them and keep it a bit more general - in a 2 dimensional space. Each rectangle is specified by two points, rectangles can ...

Good programming puzzle requiring a lot of conditional logic?

Hi guys, What is a classic programming puzzle which will require a lot of conditional logic and branches to solve? Thanks ...

how could I make a search match for similiar words

I'm working trying to automatically categorize short articles and I'm trying to figure out how to match similar words - eg, shelf shelves or painting and repaint I'm using the Porter stemming algorithm but it only helps for certain situations and only with the end of the word (both examples above don't work with it). Is there an algo...

Answer to a interview question

Jessica asked a viral question ( link ): You're passed an array with n integers in it. Each integer is between 1 and n (inclusive). These numbers are not in sorted order and there may be duplicates or missing numbers. The problem is to figure out if there are any duplicates in the array in O(n) time and O(1) space wi...

Find a string pattern in a set of strings

I have a set of strings, set<string>, and a string to check, I would like to do a binary search over it, obviously, a set is sorted. The purpose is to find the longer string in the set that is contained in the supplied string to check. It's basically to check for urls and registered handlers. I'm digging in the std algorithms and com...

Best algorithm for comparing a base coordinate to a list of n coordinates and determining the closest m coordinates?

I have some code doing this right now. It works fine with small to medium sized lists, but when I have a list of size n > 5000 then the my algorithm can take almost 1 minute on a mobile device to run. I'm basically comparing a Coordinate object in Java to a list (Vector) of Coordinate objects. Here's my basic algorithm: traverse each ...

Heap insert, delete k elements

Hello, I have the following problem (I think it's well known/standard) that I am thinking at: Verify that listing k smallest elements in a binary min-heap is O(k). I was thinking at traversing the big min-heap in BFS, maintaining a min-heap instead of a simple queue. Initially, the auxiliary min-heap contains the root of my big min-he...

Algorithm for 2D grid problem?

Hello everyone, I will be honest, this is an assignment question but I just cant find a solution to it. Please remember I am not asking for the answer but simply some guidance. Problem: Design an algorithm that runs in O(n) time (linear) which can locate a single suspicious house (point) on a 2D grid. It is suspicious if it consumes eq...

BigO bound on some pseudocode

AllDistinct(a1 , . . . , an ) if (n = 1) return True for i := n down to 2 begin if (LinearSearch(a1 , . . . , ai−1 ; ai ) != 0) return False end return True Give a big-O bound on the running time of AllDistinct. For full credit, you must show work or briefly explain your answer. So the actual answer for this according to ...