algorithm

Bitwise Interval Arithmetic

I've recently read an interesting thread on the D newsgroup, which basically asks, Given two (signed) integers a [amin, amax], b [bmin, bmax], what is the tightest interval of a | b? I'm think if interval arithmetics can be applied on general bitwise operators (assuming infinite bits). The bitwise-NOT and shifts are trivial sin...

Algorithm for performing decentralized search in social networks

I want to find out all the existing decentralized algorithms that exploit the structural properties of social networks. So far I know the following algorithms - 1) Best connected search - Adamic et al 2) Random Walk (does not exploit any structural property but still it is decentralized) 3) Hamming distance search 4) Weak/Strong tie...

PRIME1 problem in SPOj. i get a SIGSEGV error y?pls help me out

#include<stdio.h> main() { long long int m,n,i,j; int t; scanf("%d",&t); while(t--) { scanf("%lld",&m); scanf("%lld",&n); long long int a[n+2]; for(i=0;i<=n;i++) { a[i]=1; } for(i=2;i<=sqrt(n);i++) { j=2; while((i*j)<=n) ...

Fastest possible summing numbers up to N

Okay so i need really FAST algorithm or code in C if you have any it would be nice. The task is to sum all numbers from 1 to N for a given number N (it can be negative number too), so i did the usual way (you know just summing with loop from 1 to N) but it's not fast enough - i need something faster, i guess that i need the fastest possi...

Divide and conquer method to compute roots [SOLVED]

Hello, Knowing that we can use Divide-and-Conquer algorithm to compute large exponents, for exemple 2 exp 100 = 2 exp(50) * 2 exp(50), which is quite more efficient, is this method efficient using roots ? For exemple 2 exp (1/100) = (2 exp(1/50)) exp(1/50) ? In other words, I'm wondering if (n exp(1/x)) is more efficient to (n exp(1/y)...

Is there a name for this type of algorithm?

I have a 2 dimensional array forming a table: [color][number][shape ] ------------------------- [black][10 ][square ] [black][10 ][circle ] [red ][05 ][triangle] [red ][04 ][triangle] [green][11 ][oval ] and what I want to do is group largest common denominators, such that we get: 3 groups group #1: color=bl...

Extracting a given number of the highest values in a List

I'm seeking to display a fixed number of items on a web page according to their respective weight (represented by an Integer). The List where these items are found can be of virtually any size. The first solution that comes to mind is to do a Collections.sort() and to get the items one by one by going through the List. Is there a more e...

How to get predecessor and successors from an adjacency matrix

Hi I am am trying to complete an assignment, where it is ok to consult the online community. I have to create a graph class that ultimately can do Breadth First Search and Depth First Search. I have been able to implement those algorithms successfully however another requirement is to be able to get the successors and predecessors and ...

algorithm to calculate ETA of a file downloading session

Possible Duplicate: Estimating/forecasting download completion time Just curious how does ftp clients calculate estimated time to finish? Does it use any average number over past few minutes' data or any other algorithm to get more accurate time? Thanks. ...

How to calculate order (big O) for more complex algorithms (ie quicksort)

I know there are quite a bunch of questions about big O notation, I have already checked Plain english explanation of Big O , Big O, how do you calculate/approximate it?, and Big O Notation Homework--Code Fragment Algorithm Analysis?, to name a few. I know by "intuition" how to calculate it for n, n^2, n! and so, however I am completely...

Drawing the call stack in a recursive method

Hey, I want to draw the call stack for any recursive method, so I've created a schema like this, recursiveMethod(){ //Break recursion condition if(){ // Add value here to the return values' list- No drawing return } else{ //Draw stack with the value which will be pushed to the stack here variable <- recursive...

Help:Graph contest problem: maybe a modified Dijkstra or another alternative algorithm

Hi you all, I'm trying to do this contest exercise about graphs: XPTO is an intrepid adventurer (a little too temerarious for his own good) who boasts about exploring every corner of the universe, no matter how inhospitable. In fact, he doesn't visit the planets where people can easily live in, he prefers those where only a madman woul...

Al Zimmermann's Son of Darts

There's about 2 months left in Al Zimmermann's Son of Darts programming contest, and I'd like to improve my standing (currently in the 60s) to something more respectable. I'd like to get some ideas from the great community of stackoverflow on how best to approach this problem. The contest problem is known as the Global Postage Stamp Pro...

combinations of sizes for shipping

Hi there, I've got a bunch of products with sizes to ship and I need to find out the cheapest rate. Given a shipment made out of sizes, say [1,3,3,5] I need to decide how to ship - all together or separate. However it's not as simple as [1,3,3,5] or 1 & 3 & 3 & 5, i need all of the possible combinations something like: [ [[1,3,3,5]], ...

B-trees that use redistribution on insertion

If I insert the letters A, G, I, and Y into a B-tree of order 4 (meaning 4 pointers and 3 elements in each node), I get the following B-tree. G / \ A IY Would it look any different if redistribution on insertion were used? How does redistribution on insertion work? ...

Rectangles Covering

I have N rectangles with sides parallel to the x- and y-axes. There is another rectangle, model. I need to create an algorithm that can tell whether the model is completely covered by the N rectangles. I have some ideas. I think that first, I need to sort the rectangles by their left side (it can be done in O(n log n) time), and then...

Finding anagaram(s) of dictionary words

How can I take an input word (or sequence of letters) and output a word from a dictionary that contains exactly those letters? Does java has an English dictionary class (list of words) that I can use, or are there open source implementations of this? How can I optimize my code if this needs to be done repeatedly? ...

C - How to implement Set data structure?

Is there any tricky way to implement a set data structure (a collection of unique values) in C? All elements in a set will be of the same type and there is a huge RAM memory. As I know, for integers it can be done really fast'N'easy using value-indexed arrays. But I'd like to have a very general Set data type. And it would be nice if a...

How to determine the longest increasing subsequence using dynamic programming?

Let's say I have a set of integers. I want to find the longest increasing subsequence of that set using dynamic programming. This is simply out of practice, reviewing my old notes from my algorithms course, and I don't seem to understand how this works. Thanks ...

determine if intersection of a set with conjunction of two other sets is empty

For any three given sets A, B and C: is there a way to determine (programmatically) whether there is an element of A that is part of the conjunction (edit: intersection) of B and C? example: A: all numbers greater than 3 B: all numbers lesser than 7 C: all numbers that equal 5 In this case there is an element in set A, being the numb...