algorithm

Algorithms in C

Hi, Can anyone please suggest to me the best place or link to learn algorithms in C? How do you know when and where to use the implementation of algorithms by just looking into the problems. Thanks and regards, Maddy ...

Given an array of numbers, except for one number all the others, occur twice. Give an algorithm to find that number which occurs only once in the array.

What I can think of is: Algo: Have a hash table which will store the number and its associated count Parse the array and increment the count for number. Now parse the hash table to get the number whose count is 1. Can you guys think of solution better than this. With O(n) runtime and using no extra space ...

How to improve this mergesort in scheme ?

Hi, I am a C++ programmer, I wrote this code to see if I can think functionally :) Any hints to improve it ? (define (append listOne listTwo) (cond ((null? listOne) listTwo) (else (cons (car listOne) (append (cdr listOne) listTwo))))) (define (merge listOne listTwo) (cond ((null? listOne) listTwo) ((null? listTwo) l...

Get all factors of a number (iterators showdown :)

You are given all the prime factors of a number, along with their multiplicities (highest powers). The requirment is to produce all the factors of that number. Let me give an example: Prime factors: 2 (power: 3) 3 (power: 1) (meaning the number is 2^3 * 3^1 = 24) The expected result is: 1, 2, 3, 4, 6, 8, 12, 24 I'm thinking of d...

Draw for golf

how do you calculate a draw for say 16 people to play in groups of 4 over 4 days to achieve a result that they play with different people each day ...

Motion planning without a graph across an infinite plane

An object is positioned at A and wants to move to B. I want to calculate a movement vector there that doesn't move within the distance D of the to-be-avoided points in array C. So if the move vector (B-A) normalized and multiplied with the objects speed would bring it within D of any point in C the vector is rotated so that it doesn't. ...

An algorithm for estimating the runtime for a program

I need to find the total timings for the execution of a program over different inputs. The program reads some data and writes it into another file. The values of the data value and the size of the data are different every time. I want to find how long it will take in general for all size of data. Is the algorithm for finding this base...

Building an activity chart combining two kinds of data

I'm building, for example, an application that monitors your health. Each day, you're jogging and doing push-ups and you enter the information on a web site. What I would like to do is building a chart combining the hours you jogged and the number of push-ups/sit-ups you did. Let's say on the first day, you jogged 1 hour and did 10 push...

Faster to malloc multiple small times or few large times?

When using malloc to allocate memory, is it generally quicker to do multiple mallocs of smaller chunks of data or fewer mallocs of larger chunks of data? For example, say you are working with an image file that has black pixels and white pixels. You are iterating through the pixels and want to save the x and y position of each black pi...

Is there a problem that has only a recursive solution?

Possible Duplicates: Is there a problem that has only a recursive solution? Can every recursion be converted into iteration? Necessary Uses of Recursion in Imperative Languages Is there a problem that has only a recursive solution, that is, a problem that has a recursive solution, but an iterative solution has yet to be foun...

Simple database-like collection class in Java.

The problem: Maintain a bidirectional many-to-one relationship among java objects. Something like the Google/Commons Collections bidi maps, but I want to allow duplicate values on the forward side, and have sets of the forward keys as the reverse side values. Used something like this: // maintaining disjoint areas on a gameboard. Locat...

How can I efficiently calculate the binomial cumulative distribution function?

Let's say that I know the probability of a "success" is P. I run the test N times, and I see S successes. The test is akin to tossing an unevenly weighted coin (perhaps heads is a success, tails is a failure). I want to know the approximate probability of seeing either S successes, or a number of successes less likely than S successes...

Implement an algorithm to insert a node into a circular linked list without traversing it.

I was thinking of a solution to this problem. My input: 1. Have a tail pointer which points to the last node. 2. Once you know the last pointer you can easily add a new node next to it. Void Insert(Node N) { if (head == null) // linked list is empty { head = N; tail = N; tail.Next = head; } else { ...

What kind of algorithm is this?

What kind of algorithm is this, I know pretty much nothing but this is what I'm trying to do in code... I have class 'Item', properties int A and int B -- I have multiple lists of List<Item> with a random amount of Item in each list, incosistent with any other List. I must choose 1 item from each list to get the highest possible value of...

Learning F# - printing prime numbers

Yesterday I started looking at F# during some spare time. I thought I would start with the standard problem of printing out all the prime numbers up to 100. Heres what I came up with... #light open System let mutable divisable = false let mutable j = 2 for i = 2 to 100 do j <- 2 while j < i do if i % j = 0 then divisab...

Algorithm for multiple word matching in text

I have a large set of words (about 10,000) and I need to find if any of those words appear in a given block of text. Is there a faster algorithm than doing a simple text search for each of the words in the block of text? ...

Classifying english words into rare and common

Hi all, I'm trying to devise a method that will be able to classify a given number of english words into 2 sets - "rare" and "common" - the reference being to how much they are used in the language. The number of words I would like to classify is bounded - currently at around 10,000, and include everything from articles, to proper noun...

What algorithm to use to calculate a check digit?

What algorithm to use to calculate a check digit for a list of digits? The length of the list is between 8 and 12 digits. see also: How to generate a verification code/number? ...

Why isn't speech recognition advancing?

What's so difficult about the subject that algorithm designers are having a hard time tackling it? Is it really that complex? I'm having a hard time grasping why this topic is so problematic. Can anyone give me an example as to why this is the case? ...

What is an efficient algorithm to find whether a singly linked list is circular/cyclic or not?

How can i find whether a singly linked list is circular/cyclic or not? I Tried searching but couldn't find a satisfactory solution. If possible, can you provide pseudocode or Java? For Example 1 3 5 71 45 7 5 -stop , its a circular linked list ...