algorithm

What is linear programming?

I read over the wikipedia article, but it seems to be beyond my comprehension. It says it's for optimization, but how is it different than any other method for optimizing things? An answer that introduces me to linear programming so I can begin diving into some less beginner-accessible material would be most helpful. ...

How to generate Fibonacci faster

Hello! I am a CSE student and preparing myself for programming contest.Now I am working on Fibonacci series. I have a input file of size about some Kilo bytes containing positive integers. Input formate looks like 3 5 6 7 8 0 A zero means the end of file. Output should like 2 5 8 13 21 my code is #include<stdio.h> int fi...

string of integers puzzle

I apologize for not have the math background to put this question in a more formal way. I'm looking to create a string of 796 letters (or integers) with certain properties. Basically, the string is a variation on a De Bruijn sequence B(12,4), except order and repetition within each n-length subsequence are disregarded. i.e. ABBB BABA B...

Algorithm for simplifying 3d surface?

I have a set of 3d points that approximate a surface. Each point, however, are subject to some error. Furthermore, the set of points contain a lot more points than is actually needed to represent the underlying surface. What I am looking for is an algorithm to create a new (much smaller) set of points representing a simplified, smoother...

Algorithm help: Fit a text blurb to its textbox by length

I have a rather unusual problem, and it is hurting my brain. Problem: Given a textbox of known length, and the text that will go inside it, make the text "fit" by truncating it with room for "..." to fit inside the box. (Context : This is for ASP.NET C#, but I think the algorithm is language agnostic.) Example : [_________] Text : ...

Algorithm to count the number of valid blocks in a permutation

Possible Duplicate: Finding sorted sub-sequences in a permutation Given an array A which holds a permutation of 1,2,...,n. A sub-block A[i..j] of an array A is called a valid block if all the numbers appearing in A[i..j] are consecutive numbers (may not be in order). Given an array A= [ 7 3 4 1 2 6 5 8] the valid blocks ar...

Resources about different Computer Science fields

I am going to begin my final year at university this September so I need to do a project for my dissertation. I had a look at the list with the projects suggested by the uni last year and I don't find any of them THAT interesting. That, combined to my "love" for "theoretical" computer science as a whole got me into thinking that it would...

Thoughts on a recursive algorithm.

Hi. I have a problem at hand, which can be stated as follows. There are two set of nodes (in a bipartite directed graph), type1 and type2. For every node in the graph of type1, I have to find out a set which is constructed in this fashion: Let node1 be the first node of type1. Add node1 in the set. For node1, find out the list of nod...

What is the proper behaviour for a Paxos agent in this scenario?

I'm looking into Paxos and I'm confused about how the algorithm should behave in this contrived example. I hope the diagram below explains the scenario. A few points: Each agent acts as a proposer/acceptor/learner Prepare messages have form (instance, proposal_num) Propose messages have form (instance, proposal_num, proposal_val) Se...

Algorithm(s) for the constrained degree + bounded diameter minimum spanning tree?

Suppose I have 3 kinds of restrictions to computing a spanning tree: Constrained degree (eg: a node in a spanning tree may only be connected up to 3 other nodes) Bounded diameter (eg: all edges' weights, once summed, cannot exceed 100). 2.1. If possible, show all subtrees that meet this criteria. Both Are there any good algorithms t...

need an ideea to optimize an algorithm for matching multipart rar files from input in php

Hello, i'm looking for a better optimized way to find and group multipart archives from an array of filenames I have as an input for example: array( books.part1.rar, books.part3.rar, 00000114.rar, svoy_20ostrov.rar, svoy_20ostrov.rar, koncert_20v_20dk_20mir.rar, koncert_20v_20centralnom_20teatre_20kukol.rar, LP_LIVE_PR_Tampa.part2.rar...

Algorithm to iterate through sample space of numbers

I hope this isn't a dupe, but it's hard to boil down the problem into keywords! This is always something that I've wondered about. Let's say you have a black box that takes n integers as an input (where n > 1). Given that there is a bounds on the integer values, how would you go about writing an algorithm that will push the entire sampl...

Machine scheduling problem

i have a combinatoric problem as such: You are given N testers. Each tester is one of M different types. Each tester can be configured to use one of P different configs. . You have L lots of products to test, Each product can only be tested on specific Tester type, Each product can only be tested by Tester configured with specifi...

How to convert a tree recursive function ( or algorithm ) to a loop one?

I have written a recursive Tree Function in pascal ( or delphi ) but i had an 'Out of Memory' message when I ran it. I need to turn the Calculate recursive function in this code to non-recursive function, can you tell me how please : program testing(input,output); type ptr = ^tr; tr = record age:byte; left,right:ptr; end...

How to sort three variables using at most two swaps?

The following algorithm can sort three variables x, y and z of type K which are comparable using operator<: void sort2(K& x, K& y) { if(y < x) swap(x, y); } void sort3(K& x, K& y, K& z) { sort2(x, y); sort2(y, z); sort2(x, y); } This needs three swaps in the "worst case". However basic mathematics tells us, th...

How to get arbitrary shapes, defined by images with transparency, to snap to one another such that there is no seam between the two?

I have an application where the user can drag their images (.pngs) around on a virtual table. The images are of shapes - mostly regular polygons, but some jigsaw pieces, tetris blocks, et cetera. I want the shapes, as they are being dragged, to snap to one another like two jigsaw pieces might.(Like in MS Word "Snap to grid") How might ...

Image comparison - rotation, alignment and scaling

Hello guys, I have the following needs. There are some number of forms, i.e blanks - for example the ones used in surveys. The ones which aren't filled with information, I will call image templates from now on. Apart from the image templates, I have also many images, which are essentially the image templates filled with information. For...

Which of my friends have the same 'like' ?

Hi, I have web app where each user can have friends. Users can look at different pages on my site, like: pizza.html hamburger.html etc.. If I am userA, and I'm looking at page 'pizza.html', I'd like to know which of my friends have also 'liked' this page. Assuming I want to show this when I load pizza.html, I could do it on demand re...

Sorting/Shuffling an NSMutuable Array

Hi, Im just starting getting into Objective-C, i'm trying to sort an array so it is as low discrepancy as possible. int main() { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSMutableArray *myColors; myColors = [NSMutableArray arrayWithObjects: @"Red", @"Red",@"Red", @"Red", @"Red", @"Green", @"Green", @"Gr...

MySQL: How do I SUM non duplicates values when doing multiples JOINS

I try to SUM values from columns, from a query which contains some JOINS. Example: SELECT p.id AS product_id, SUM(out_details.out_details_quantity) AS stock_bought_last_month, SUM(order_details.order_quantity) AS stock_already_commanded FROM product AS p INNER JOIN out_details ON out_details.product_id=p.id INNER JOIN or...