algorithm

Ads System

I am creating an Ad system for an ASP.NET website. The website has a section for advertisers. They register their and posts there ads, They will pay the maximum budget for the ad first, There is a daily budget , so the advertiser can control his budget, There will be a lot of ads from different advertisers to show in the website. The ads...

algorithm to find best combination

Assume that I have a list of 100 products, each of which has a price. Each one also has a energy (kJ) measurement. Would it be possible to find the best combination of 15 products for under $10 of which the sum of the energy (kJ) was greatest, using programming? I know C#, but any language is fine. Cheers. Update: Having a bit of tro...

Quick Sort Vs Merge Sort

Why might quick sort be better than merge sort ? ...

How to calculate the odds of a collision in hash algorithms?

Say I have a hash algorithm, and it's nice and smooth (The odds of any one hash value coming up are the same as any other value). Now say that I know that the odds of picking 2 hashes and there being a collision are (For arguments sake) 50000:1. Now say I pick 100 hashes. How do I calculate the odds of a collision within that set of 10...

OnLive: How does it work?

OnLive is a cloud computing solution for gaming. It offers streaming of high-end games to any pc, regardless of its hardware. I wonder how it works: sending raw HD res image and audio data seems unlikely. Would relatively simple compression, like jpeg and mp3/ogg, do the trick? ...

Arrange 0's & 1's in a array

This is one of an interview question which I had recently. I would like to know others perception of approach for this problem. Question: You are given a structure which holds an employee details with two elements as int Deptartment and string Name. struct Employee { string Name; int Dept; } You are given details of N Emplo...

Fast sampling and update of weighted items (data structure like red-black trees?)

What is the appropriate data structure for this task? I have a set of N items. N is large. Each item has a positive weight value associated with it. I would like to do the following, quickly: inner loop: Sample an item, according it its weight. [process...] Update the weight of K items, where K << N. When I say sample ...

How can I search a graph for a path?

Say I have a list of edges each containing two nodes (to and from). What is the best way to find the edge two given nodes? Note that nodes in the edge may repeat. Say I have edge in this format: 1 <-> 5 3 <-> 7 5 <-> 6 2<-> 6 Then query such as 1 5 will return true. Then query such as 5 2 will return true because...

Mixing two arrays by alternating elements (zipper style)

What is an elegant algorithm to mix the elements in two arrays (of potentially differing sizes) so that the items are drawn in an alternating fashion from each array, with the leftovers added to the end? E.g. Array 1 - A, B, C, D, E, F, G Array 2 - 1, 2, 3, 4 Mixed array - A, 1, B, 2, C, 3, D, 4, E, F, G I would prefer the solution...

design a stack such that getMinimum( ) should be O(1)

This is one of an interview question. You need to design a stack which holds an integer value such that getMinimum() function should return the minimum element in the stack. For example: consider the below example case #1 5 --> TOP 1 4 6 2 When getMinimum() is called it should return 1, which is the minimum element in the stack. ...

Algorithm to find a square root of a number?

The only algorithm that I know for this problem is the Newton's method (make a guess, then improve it until it's good enough). Any other ideas (use any language you prefer)? PS: Of course I don't have any use case for this, I'm just researching it for academic reasons. ...

Permuting a binary tree without the use of lists

I need to find an algorithm for generating every possible permutation of a binary tree, and need to do so without using lists (this is because the tree itself carries semantics and restraints that cannot be translated into lists). I've found an algorithm that works for trees with the height of three or less, but whenever I get to greater...

What data structure should I use to keep track of recently used items?

I need something like a bounded queue where I can only insert say 10 elements. A new element should override the last inserted element. There should be only n distinct elements I am looking for suggestions in Java by the way. ...

How do I solve this without recursion?

I'm trying to help my son solve a math problem. This seems like a good opportunity to expose him to some programming. I can see the recursive solution but perhaps an iterative one would be easier to explain. The language he has learned so far has been SmallBasic which doesn't support recursion very well (no local variables). I'm not ...

Implement Stack using Two Queues

A similiar question was asked earlier there, but the question here is the reverse of it, using two queues as a stack. The question... Given two queues with their standard operations (enqueue, dequeue, isempty, size), implement a stack with its standard operations (pop, push, isempty, size). There should be TWO versions of the solution...

Convert a decimal into an alphabetic column id?

Working with some spreadsheet stuff, internally the columns are referred to by a simple decimal number (0 indexed), but for the output, I need it to be in the standard human readable format: A, B, C, .. Z, AA, AB, AC, .. AZ, BA .. I first thought "easy! I'll just switch to base 26 and use [A-Z] instead of [0-9A-P]", except that using ...

Complicated Algorithm - How to store rules separate from processing code?

I'm working on a project which will do some complicated analyzing on some user-supplied input. There will be 3 parts of the code: 1) Input supplied by user, such as keywords 2) Rules, such as if keyword 1 is repeated 3 times in keyword 5, do this, etc. 3) And the analyzing itself which executes the rules and processes the user input, ...

Find the mode of an array of floating point numbers using hashing

I recently read that a method involving hashing could be a good way to find the mode of an array of floating point numbers. I don't know much about hashing or its applications and the text didn't explain further. Does anyone know what this method would involve? ...

Algorithm to establish ordering amongst a set of items

I have a set of students (referred to as items in the title for generality). Amongst these students, some have a reputation for being rambunctious. We are told about a set of hate relationships of the form 'i hates j'. 'i hates j' does not imply 'j hates i'. We are supposed to arrange the students in rows (front most row numbered 1) in a...

Occlusion algorithms collection

The occlusion algorithm is necessary in CAD and game industry. And they are different in the two industries I think. My questions are: What kind of occlusion algorithms are applied respectively in the two indurstries? and what is the difference? I am working on CAD software development, and the occlusion algorithm we have adopted is ...