algorithm

Programming Pearls Problem: Checking for sorted array in binary search

In Programming Pearls (second edition) Column 5, problem 5 the question is about implementing binary search on an unsorted array. How can you add partial checking to the function at significantly less than O(n-1) cost? I know you can check with every iteration and achieve O(log n), but the hint in the back suggests there is an ...

Algorithm: Find index of 2nd smallest element from an unknown array

I have been pondering about my homework question for a while. I welcome (and prefer) any suggestions or approach on how to attack this problem. Basically, I have an array A of size N. We do not know the elements but we know they are distinct. The only thing that I have is a person who will take two indices (i,j) in N. This person will t...

Shortest path problem dijsktra with arc flags

On large graphs like 2M node road network, dijkstra can not solve shortest path problem in suitable time. We need to shortest path query execution time under 1 second and I am implementing arc flag way to make dijkstra fast. Is there anybody know about how to implement arc flags preprocessing and query. Preprocessing of arc flags has som...

My Qustion 1: It's an assignmnt

The number 3797 has an interesting property...Being prime itself , it is possible to continuously remove digits from left to right,but remain prime at each stage....:3797,797,97,7....similarly we can work from right to left:3797,379,37,3. Find the of only 11 primes that are both truncatable from left to right....and right to left. Pls tr...

How can I fill an outline with predefined tangram shapes ?

I am interested in using shapes like these: Usually a tangram is made of 7 shapes(5 triangles, 1 square and 1 parallelogram). What I want to do is fill a shape only with tangram shapes, so at this point, the size and repetition of shapes shouldn't matter. Here's something I manually tried: I am a bit lost on how to approach this...

What is the formula to calculate the font-size for tags in a tagcloud?

I have a tag cloud and I need to know how can I change the font-size for the most used tags. I need to set a min-font-size and a max-font-size. ...

Calculate "Busy hour"

Baselines - table: date / time of call, duration of call How to calculate "Busy hour"? http://en.wikipedia.org/wiki/Busy_hour - In a communications system, the sliding 60-minute period during which occurs the maximum total traffic load in a given 24-hour period. ...

C#: Adding working days from a cetain date.

I have trouble doing this. I'm creating a method that add working days on a specific date. for example, I want to add 3 working days to sept 15, 2010 (Wednesday), the method would return sept 20 (Monday next week). it disregards saturday and sunday because its non-working day.. Something like this in C#: DateTime AddWorkingDays(DateTim...

Dijkstra on adjacency matrix in C

Hi all, I need some help with Dijkstra's algorithm in C. I've generated my adjacency matrix, that looks something like: int mat[NB][NB] = {{0, 171, MAX, 132, [...]}, {171, 0, 30, 39, [...]}, , [...]}; I've found this implementation: http://www.answers.com/topic/dijkstra-s-algorithm-1 but the path is an 1-dimensional array and my ma...

Fastest safe sorting algorithm implementation

Hi everybody! I spend some time implementing a quicksort algorithm in C#. After finishing I compared the speed of my implementation and C#'s Array.Sort-Method. I just compare speed working on random int arrays. Here's my implementation: static void QuickSort(int[] data, int left, int right) { int i = left - 1, j = right; ...

Solution finder algorithm based on answers to a given questionnaire

Consider the following scenario: Potential customers are presented with a questionnaire where they can select none, one or multiple answers for every question. An automated algorithm should recommend the optimal solution based on the customers' answers. Example: There are 3 possible solutions S1, S2, S3 The questionnaire contains 1...

Generating potential schedules for college students.

Hello, Here is my problem: I am designing an application that will allow students to select the classes they want to take for the semester and create potential schedule layouts for them. Each class typically has several possible sections that occur at different times. So I am looking for a good data structure to use in order to develo...

Most efficient way of randomly choosing a set of distinct integers

I'm looking for the most efficient algorithm to randomly choose a set of n distinct integers, where all the integers are in some range [0..maxValue]. Constraints: maxValue is larger than n, and possibly much larger I don't care if the output list is sorted or not all integers must be chosen with equal probability My initial idea wa...

Interview Question: How to efficiently search in an ordered matrix?

I have a x by y matrix, where each row and each column are in ascending order as given below. 1 5 7 9 4 6 10 15 8 11 12 19 14 16 18 21 How to search this matrix for a number in O(x+y)? I was asked this question for an interview, but could not figure out the way. Curious to know if it could be done. ...

Need help with a math trick question

Possible Duplicate: Easy interview question got harder: given numbers 1..100, find the missing number(s) Hi guys, I wasn't sure where to ask this but since this is an algorithmic question here it goes. I've come face to face with a math problem and can't seem to get over it for the last couple of days. It goes like this: Y...

Clustering with a distance matrix

Hi, I have a (symmetric) matrix M that represents the distance between each pair of nodes. For example, A B C D E F G H I J K L A 0 20 20 20 40 60 60 60 100 120 120 120 B 20 0 20 20 60 80 80 80 120 140 140 140 C 20 20 0 20 60 80 80 80 120 140 140 140 D 20 20 20 0 60 80 80 8...

A network flow problem

I am recently preparing for the acm-icpc contest. Here I want to know how to find the minimum flow with the least cost given the condition that each edge in the graph has a capacity C, a cost V, and a lowerbound flow L (L ≤ C). ...

String comparison algorithm, relevancy, how much "alike" 2 strings are

I have 2 sources of information for the same data (companies), which I can join together via a unique ID (contract number). The presence of the second, different source, is due to the fact that the 2 sources are updated manually, independently. So what I have is an ID and a company Name in 2 tables. I need to come up with an algorithm t...

How does the image recognition work in Google Shopper?

I am amazed at how well (and fast) this software works. I hovered my phone's camera over a small area of a book cover in dim light and it only took a couple of seconds for Google Shopper to identify it. It's almost magical. Does anyone know how it works? ...

Substring algorithm suggestion

I have a large set (100k) of short strings (not more than 100 chars) and I need to quickly find all those who have a certain substring. This will be used as a search box where the user starts typing and the system immediately gives "suggestions" (the strings that have as a substring the text that the user typed). Something similar to th...