algorithm

Sort distributed couples from two lists

Having two lists, I want to get all the possible couples. (a couple can be only one element from list 1 and another from list 2) If I do a double "foreach" statement, I get it immediately (I am using python): couples = [] for e1 in list_1: for e2 in list_2: couples.append([l1, l2]) How can I sort couples list in a way tha...

Data structures for huge graphs in C++

I want to understand how huge graphs can be implemented, so that graph algorithms run faster with huge graphs. ...

Building an expression with maximum value

Given n integers, is there an O(n) or O(n log n) algorithm that can compute the maximum value of a mathematical expression that can be obtained by inserting the operators -, +, * and parentheses between the given numbers? Assume only binary variants of the operators, so no unary minus, except before the first element if needed. For exam...

Test graphs and solutions for MAXCUT

Hey all, I'm doing some work on Max Cut, and the algorithm I have works on every graph that I can think to throw at it, but those have been graphs that I can work out the solution by hand to validate, so they've been somewhat small. I am looking for a bunch of medium/large graphs (in any format, I dont mind writing parsers) that already...

Determining a mean camber line

Fellow programmers, I know this is a little outside your juridistiction, but I was wondering perhaps if you have time, if you could help me with one "procedure". Not in view of math but what would be the best way to take. This is an airfoil / profile. Usually, profiles are defined with two sets of data. One is the position of mean c...

How to get the item that appear the most time in an array?

var store = ['1','2','2','3','4']; I want to find out that 2 appear the most in the array. How do I go about doing that? ...

Effective Timetabling Algorithm

I've got a job that I've been asked to do which involves writing a program to determine where various people are to work on a given day. For example the input may be: 4-6pm, Site A 1-2pm, Site B 9-11am & 2-4pm Site A Essentially there can be many sites and people can work during multiple blocks. I get the feeling that this kind of pr...

How can I improve this algorithm for solving a modified Postage Stamp problem?

Son of Darts Problem was a contest on Al Zimmermann's Programming Contests that ended on 20 Jun 2010 : Suppose that you have a dartboard that is divided into R regions. Each dartboard region has a positive integer value associated with it. Further suppose that you have D darts and that you throw each of them at the dartboard. Each...

Fast logistic function

I am looking for a way to implement a fast logistic function. The classic definition of logistic function is: y(x) = 1 / (1 + (1/e^x)) where ^ is exponentiation. or equally: y(x) = (e^x) / (e^x + 1) However, my special logistic function has a base E instead of e, so: y(x) = E^x / (E^x + 1) E and x in my case are 32-bit integer, fix...

Recreate sets from combinations of these sets

hi, I came across a specific problem and looking for some algorithm for it. The problem to solve is as described below. Let's say we have combinations like below 1 - 3 - 5 1 - 4 - 5 1 - 8 - 5 2 - 4 - 5 3 - 4 - 5 2 - 4 - 7 These combinations were generated from given sets, in this particular case let's say from {1},{3,4,8},{5} ...

I need help solving a problem on codechef

Statement Consider a string of length N consisting only of lowercase alphabets a-z. Let s[i] be the character at the i-th position in the string (1-based). The string is a K-string if there are EXACTLY K values of i (1 <= i < N) such that s[i+1]<s[i] (we assume 'a'<'b'<'c'<...<'z'). Given K, find the shortest K-string. If there are mult...

Generate a list of primes in R up to a certain number

Hey, I'm trying to generate a list of primes below 1 billion. I'm trying this, but this kind of structure is pretty shitty. Any suggestions? a <- 1:1000000000 d<- 0 b <- for (i in a) {for (j in 1:i) {if (i %% j !=0) {d <- c(d,i)}}} ...

Asymptotic Growths of Functions

How to determine if a given f(n) and g(n) is in theta, omega, big oh, little omega, or little oh? - I think one way of doing it is by plotting graphs of both functions f(n) and g(n). Even by plotting graphs how do we say when a f(n) is in theta, omega, big oh, little omega, or little oh? Am not clear on that. Can someone throw more detai...

finding time complexity of recurrence relation in algorithms

Can anyone help me finding the time complexity of T(n)=1 if n<=0 T(n)=T(n-1)+T(n-2)+n ...

Examples of Asymptotic analysis

Here I will be giving two functions f(n) and g(n) and my aim is to decide if the f(n) is in theta, omega, big o, little o or little omega. Please provide detailed proof if you are confident with such problems. Problem 1: f(n) = (1/2)n^2 - 3n, g(n) = n^2 Problem 2: f(n) = 6n^3, g(n) = n^2 Problem 3: f(n) = 3n+5, g(n) = n^2 Problem 4: ...

What kind of algorithm do I need?

I'm trying to figure out all the different ways I can create groups of 4 from 6 objects using objective-c. For example, if I had the following objects: a, b, c, d, e, f Then I could create groups like a, b, c, d b, c, d, e a, d, e, f and so on. Order doesn't matter. If I wanted to figure out all the different possibilities, what ki...

Are You A Prime Number

I've been interested in the problem of finding a better prime number recognizer for years. I realize this is a huge area of academic research and study - my interest in this is really just for fun. Here was my first attempt at a possible solution, in C (below). My question is, can you suggest an improvement (without citing some other...

How to continually filter interesting data to the user?

Take an example of a question/answer site with a 'browse' slideshow that will show one question/answer page at a time. The user clicks the 'next' button and a new question/answer is presented to him. I need to decide which pages should be returned each time the user clicks 'next'. Some things I don't want and reasons why: Showing ...

Finding an intersection between something and a line

I have a set of points which are interpolated with an unknown method, or to be more precise, the method is known but it can be one of the several - it can be polynomial interpolation, spline, simple linear ... - and a line, which, let's for now imagine it is given in the simple form of y = ax + b. For interpolation, I don't know what me...

Find the successor in a BST without using parent pointer

The successor of an element in a BST is the element's successor in the sorted order determined by the inorder traversal. Finding the successor when each node has a pointer to its parent node is presented in CLRS's algorithm textbook. (Intro to algorithm by MIT press). Now I am thinking another question, can we find the successor without ...