algorithm

Calculating the Bounding Rectangle at an Angle of a Polygon

I have the need to determine the bounding rectangle for a polygon at an arbitrary angle. This picture illustrates what I need to do: The pink rectangle is what I need to determine at various angles for simple 2d polygons. Any solutions are much appreciated! Edit: Thanks for the answers, I got it working once I got the center point...

Stuck on solving the Minimal Spanning Tree problem.

I have reduced my problem to finding the minimal spanning tree in the graph. But I want to have one more constraint which is that the total degree for each vertex shouldnt exceed a certain constant factor. How do I model my problem? Is MST the wrong path? Do you know any algorithms that will help me? One more problem: My graph has dup...

Algorithm to Divide a list of numbers into 2 equal sum lists

There is a list of numbers. The list is to be divided into 2 equal sized lists, with a minimal difference in sum. The sums have to be printed. #Example: >>>que = [2,3,10,5,8,9,7,3,5,2] >>>make_teams(que) 27 27 Is there an error in the following code algorithm for some case? How do I optimize and/or pythonize this? def make_teams(q...

Calculating slope in -ve, zero and +ve domains

Imagina a sine wave oscillating about a zero line. My task is to calculate the slope at several random points along the wave using a fairly coarse x axis scale. (yes this has a real application) When the wave is in +ve terrirtory (above the zero line) slope can be calculated from: Slope = (y(n) / y(n-1)) - 1 This yeilds +ve slope vla...

Resources to learn Dynamic Programming, NP Complete, Knapsack Problems, and more on Algorithms

What are the good resources that discuss Algorithms, P NP problems, Dynamic Programming, Special cases of those- Knapsack problems and such. The resource must have working code, preferably in Python. Advantage if it explains some of the TopCoder SRM Dynamic Programming questions. PS: I am a web developer interested in algorithms and an...

Algorithm to recognise mouse movements

Hello, Am wondering if there has been any research/algorthms which specify the amount of deviation of the mouse while recognizing characters like say "?" drawn using the mouse. Something a sort of optical character recognition, but probably a simpler version. Is there some algorithm using which I can say that a question mark drawn by th...

How do I optimize this method for breaking a string in chunks?

Here's the method. I want to know if I am violating any best practices here or if I am doing something wrong as far as the language is concerned. private List<String> breakStringInChunks(String text, int chunkSize) { List<String> chunks = new ArrayList<String>(); String temporary = ""; int numberOfChunks = text.l...

Algorithm for unique CD-KEY generation with validation

Hi, I am trying to create a unique CD-KEY to put in our product's box, just like a normal CD-KEY found in standard software boxes that users use to register the product. However we are not selling software, we are selling DNA collection kit for criminal and medical purposes. Users will receive a saliva collection kit by mail with the ...

Create a hashcode of two numbers

I am trying to create a quick hashcode function for a complex number class (a + bi) in C#. I have seen repeatedly the a.GetHashcode()^b.GetHashCode() method. But this will give the same hashcode for (a,b) and (b,a). Are there any standard algorithm to do this and are there any functions in the .Net framework to help? ...

Pixies in the custard swamp puzzle

(With thanks to Rich Bradshaw) I'm looking for optimal strategies for the following puzzle. As the new fairy king, it is your duty to map the kingdom's custard swamp. The swamp is covered in an ethereal mist, with islands of custard scattered throughout. You can send your pixies across the swamp, with instructions to fly low or high...

Bubble Sort Homework

In class we are doing sorting algorithms and, although I understand them fine when talking about them and writing pseudocode, I am having problems writing actual code for them. This is my attempt in Python: mylist = [12, 5, 13, 8, 9, 65] def bubble(badList): length = len(badList) - 1 unsorted = True while unsorted: f...

Automatic regex builder

I have N strings. Also, there are K regular expressions, unknown to me. Each string is either matching one of the regular expressions, or it is garbage. There are total of L garbage strings in the set. Both K and L are unknown. I'd like to deduce the regular expressions. Obviously, this problem has infinite number of solutions. I need ...

Grouping problem

Well, I have a question about what algorithm would be most appropriate for my problem. Let's say that I have 3 groups: Group A) 1 2 3 Group B) 5 4 Group C) 9 6 7 8 Now I would like to get all possible groups with this members (1-8) and groups with capacity 3, 2, 4. Note: Group A) 3 1 2 Group B) 5 4 Group C) 7 8 9 6 counts as same g...

Recursively generate ordered substrings from an ordered sequence of chars?

Edited after getting answers Some excellent answers here. I like Josh's because it is so clever and uses C++. However I decided to accept Dave's answer because of it's simplicity and recursion. I tested them both and they both produced identical correct results (although in a different order). So thanks again everyone. Say I have a st...

social graph problem (path between users)

I have received the task to make a social graph, where, with one user in the center, it shows the connections he has. But before we can reach that, our focus is how we can determine the shortest path between 2 users. I found some algorithm to do it, but it seems that it takes a lot of time, and because it's about social links, we are loo...

Looking for an algorithm to map out an area and then methodically trace over the area.

I'm looking at playing with some basic robotics, I'm looking at building a simple bot that navigates around a room. The idea is that it would find edges and as it goes it would build up a map of the area. Once that's done I'd like it to be able to walk methodically over the entire area to find any obstacles inside the area. Does anyone...

Can I use SQL to find missing numbers in the example table I give below?

Let's say I have the following table with three columns: id | start_block | end_block ----------------------------- 01 | 00000000001 | 00000000005 02 | 00000000006 | 00000000011 03 | 00000000012 | 00000000018 04 | 00000000025 | 00000000031 05 | 00000000032 | 00000000043 Each row was a "Start Block" and an "End Block". If the data was...

What would a P=NP proof be like, hypothetically?

Would it be an polynomial time algorithm to a specific NP-complete problem, or just abstract reasonings that demonstrate solutions to NP-complete problems exist? It seems that the a specific algoithm is much more helpful. With it, all we'll have to do to polynomially solve an NP problem is to convert it into the specific NP-complete p...

Recommended Resources for Data Compression Research

I'm looking for recommended resources on data compression; any studies on techniques, data structure and/or algorithms; any useful resources related to research, any books, organizations or any other information would be helpful. I know it's kind of a general query, but just interested in expanding my knowledge on the subject matter. ...

Why we use Hash Code in HashTable instead of an Index?

How that integer hash is generated by the GetHashCode() function? Is it a random value which is not unique? In string, it is overridden to make sure that there exists only one hash code for a particular string. How to do that? How searching for specific key in a hash table is speeded up using hash code? What are the advantages...