algorithm

Brackets matching using BIT

edit: I was trying to solve a spoj problem. Here is the link to the problem : http://spoj.pl/problems/BRCKTS I can think of two possible data structures for solving the problem one using segment tree and the other using a BIT. I have already implemented the solution using a segment tree. I have read about BIT but i can't figure out how ...

When do hashes collide?

I understand that according to pigeonhole principle, if number of items is greater than number of containers, then at least one container will have more than one item. Does it matter which container will it be? How does this apply to MD5, SHA1, SHA2 hashes? ...

What is the best 32bit hash function for short strings (tag names)?

What is the best 32bit hash function for relatively short strings? Strings are tag names that consist of English letters, numbers, spaces and some additional characters (#, $, ., ...). For example: Unit testing, C# 2.0. I am looking for 'best' as in 'minimal collisions', performance is not important for my goals. ...

Combination without repetition

I have Collection List<Car>. How to compare each item from this collection with rest without repeatition. Ex: iteration: this car is Audi and secondCar is BMW bool IsSimilar(Car secondCar) { if(this.Name==secondCar.Name) return true; return false; } this is not permitted: n iteration this car is BMW and secondCar is Audi ...

Find a number in an array

I came up with 3 algorithms to attempt the above problem, but I am not sure which one is the best in terms of running time. I'm listing my ideas for the algorithms below and could really use some help to figure out the most efficient algorithm for this. Algo-1 I used selection sort and stopped it once the numbers are sorted. Algo-2 ...

Is there an O(n) integer sorting algorithm?

The last week I stumbled over this paper where the authors mention on the second page: Note that this yields a linear running time for integer edge weights. The same on the third page: This yields a linear running time for integer edge weights and O(m log n) for comparison-based sorting. And on the 8th page: In particular...

How to master in-place array modification algorithms?

I am preparing for a software job interview, and I have trouble with in-place array modifications. For example, in the out-shuffle problem you interleave two halves of an array, so that 1 2 3 4 5 6 7 8 would become 1 5 2 6 3 7 4 8. This question asks for a constant-memory solution (and linear-time, although I'm not sure that's even possi...

Solving Recursion in fibonacci numbers

I'm unaware of the mathematics in this algorithm and could use some help. Algorithm: if n<2 then return n else return fibonacci(n-1) + fibonacci(n-2) Statement n < 2 is O(1) Time n >=2 is O(1) Return n is O(1) Time n>=2 is - Return fib(n-1) + fib(n-2) is - and time n>=2 is T(n-1) + T(n-2) +O(1) Total: ...

Pascal programming help

I posted this earlier and it got closed because I did not show my try at coding it, so here is the question: SECTIONS $160 = section 1 $220 = section 2 $280 = section 3 $350 = section 4 $425 = section 5 Develop pseudocode that accepts as input the name of an unspecified number of masqueraders who each have paid the full cost of their ...

What technique do I use for when I want to check all possible combinations of a set?

I'm working through an interview question that goes like: Given an array of integers and sum, check whether any combination adds up to the sum. What programming technique does one use when they want to try all possible combinations of a set? Even if that isn't the best solution to this problem, I come across problems where I...

When is the appropriate time to use Radix Sort?

What are the constraints on your data for you to be able to use Radix sort? If I'm sorting a large list of integers, would it be appropriate to use Radix sort? Why is Radix sort not used more? ...

Algorithm to check whether a certain hour falls into a given time period

Assume I've got a start and stop hour in which some processing should take place: Start 20:00 End 07:00 Now what is the best algorithm to check if a certain DateTime hour value falls within this range? Thanks in advance! Please note that the start and end times mentioned above indicate that we are dealing with an "overnight-job". Mean...

Fourier transform and maximum

Is there a way to compute efficiently the Fourier transform of the max of two functions (f,g), knowing their Fourier transform? ...

"(1:k) Tree-Matching" - Solvable in polynomial time?

Some months ago there was a nice question regarding a "1:n matching problem" and there seems to be no poly-time algorithm. I would like to add constraints to find a maximum matching for the 1:n matching problem with a polynomial algorithm. I would like to say: "For vertex A1 choose either {B1,B2,B5} or {B2,B3} if the vertices are not a...

AStar in a specific case in C#

Hello. To an intership, I have use the A* algorithm in the following case : the unit shape is a square of height and width of 1, we can travel from a zone represented by a rectangle from another, but we can't travel outside these predifined areas, we can go from a rectangle to another through a door, represented by a segment on corres...

Which data mining algorithm would you suggest for this particular scenario?

This is not a directly programming related question, but it's about selecting the right data mining algorithm. I want to infer the age of people from their first names, from the region they live, and if they have an internet product or not. The idea behind it is that: there are names that are old-fashioned or popular in a particular ...

Calculate the cosine of a sequence

Hi, I have to calculate the following: float2 y = CONSTANT; for (int i = 0; i < totalN; i++) h[i] = cos(y*i); totalN is a large number, so I would like to make this in a more efficient way. Is there any way to improve this? I suspect there is, because, after all, we know what's the result of cos(n), for n=1..N, so maybe there's so...

Minimal path - all edges at least once

Hello, I have directed graph with lot of cycles, probably strongly connected, and I need to get a minimal cycle from it. I mean I need to get cycle, which is the shortest cycle in graph, and every edge is covered at least once. I have been searching for some algorithm or some theoretical background, but only thing I have found is Chines...

Non-cycle path to all nodes

Is there an algorithm or set of algorithms that would let you find the shortest walking distance from an arbitrary start node so that every node gets visited in a weight, undirected graph? It's not quite Traveling Salesman, because I don't care if a node is visited more than once. (It doesn't even matter if you make it back to the start ...

How does Batcher Merge work at a high level?

I'm trying to grasp the concept of a Batcher Sort. However, most resources I've found online focus on proof entirely or on low-level pseudocode. Before I look at proofs, I'd like to understand how Batcher Sort works. Can someone give a high level overview of how Batcher Sort works(particularly the merge) without overly verbose pseudocode...