algorithm

Does anyone have C# code to repair a linked list that cycles?

http://stackoverflow.com/questions/1285560/how-do-you-remove-a-cycle-in-a-single-linked-list Before I write some sample code to do what this answer describes, does anyone already have a C# example of repairing a singly linked list that points back into itself? I understand the detection part (tortoise/hare) but the repair part is a lit...

Unfamiliar symbol in algorithm - What does ∀ mean?

I'm reading about an algorithm (it's a path-finding algorithm based on A*), and it contains a mathematical symbol I'm unfamiliar with: ∀ Here is the context: v(s) >= g(s) = min[s'∈pred(s)](v(s') + c(s', s)) ∀s != s[start] Note: items in [brackets] are supposed to be subscript Can someone explain the meaning of ∀? ...

"For" loop first iteration

Greetings pyc-sires and py-ladies, I would like to inquire if there is an elegant pythonic way of executing some function on the first loop iteration. The only possibility I can think of is: first = True for member in something.get(): if first: root.copy(member) first = False else: somewhereElse.copy(memb...

Clever algorithm to find times where the sum of digits equals the number of segments in the digital dispay

So, my friend sent me a puzzle this morning: Find the number of distinct times of the day (using 24-hour display and assuming that morning hours are presented as 8:15 as opposed to 08:15) where the number of segments are equal to the sum of the digits. Eg. 8:15 has 7+2+5=14 segments in electronic format and the sum of t...

What's the standard algorithm for syncing two lists of objects?

I'm pretty sure this must be in some kind of text book (or more likely in all of them) but I seem to be using the wrong keywords to search for it... :( A common task I'm facing while programming is that I am dealing with lists of objects from different sources which I need to keep in sync somehow. Typically there's some sort of "master ...

I need a little bit of help with my logic here. How can I have a picture select change image on Click?

Here's what I have: private void HeroMouseEnter(object sender, MouseEventArgs e) { //I did things this was because it is easier to maintain code in a sense that is is a generic //method made for all of the heroes images. ((Image)sender).Source = GetGlowingImage(((Image)sender).Name); ...

Please help me speed up this mahjong algorithm

I am writing some mahjong-related functions in JavaScript. Here is what I have below, with code for test cases. Note that mahjong hands are represented by arrays, with: element 0 being the total number of tiles in the hand elements 1 through 34 being the number of tiles of each type in the hand first craks, then dots, then bams, the...

Searchable Static String Storage

We have a a large set of objects that include composition and name properties, both string values that contain values with a lot of duplication, what would be a suitable data structure to store the strings which can be searchable and small? The data includes many chemical and product names that are duplicates or differ only slightly. I'...

What is a good solution for calculating an average where the sum of all values exceeds a double's limits?

I have a requirement to calculate the average of a very large set of doubles (10^9 values). The sum of the values exceeds the upper bound of a double, so does anyone know any neat little tricks for calculating an average that doesn't require also calculating the sum? I am using Java 1.5. ...

Create a sum of 1000, 2000, etc. from set of numers

Ok, so here's the problem: I need to find any number of intem groups from 50-100 item set that add up to 1000, 2000, ..., 10000. Input: list of integers Integer can be on one list only. Any ideas on algorithm? ...

Java: Iterating HashMap - Algorithm needed

Hi! I have a question. I have a list of names, say 8 names: Joe, Bob, Andrew, Bill, Charlie, Sarah, Ann, Victor The count of names might differ**. 1) What should I use as name list? Hashmap, Vector, Hashtable, List, ArrayList? 2) I need to match them up like this: Joe-Bob, Andrew-Bill, Charlie-Sarah, Ann-Victor. Could you please sho...

Prim's algorithm for minimum spanning trees - confusion in algorithm.

I've been studying from the Cormen et al book and I'm a bit confused regarding the algorithm they have provided. I've understood how the concept of Prim's algo works through wikipedia, but I can't mimic that working using the algorithm provided in my book. Refer to this online copy of the chapter: http://www.cs.cmu.edu/afs/cs/academic/c...

ePic - what’s the relations with physics ?

What is the relation with Physics and techniques ? I am interested in learning the algorithms followed in this 3d photo viewer ePic. Any other known physics engine ? ...

Linked List insertion running time confusion...

I've tried to confirm the running time for the insertion for Linked List and it seems like there are two different answers. For inserting an element at the end of a Linked List, I would think that it would take O(n) since it has to traverse to the end of the list in order to access the tail. But some of the answers I've seen says O(1)?...

Flattening a forest into a sorted list, using only the set of nodes and an "is parent" predicate (or: sorting a list with an incomplete comparison function)

I have a set of objects, and I need to produce a sorted list, but my comparison function is incomplete and leaves some room for "imagination" on the part of the sorting algorithm. Specifically, given a collection of trees like the following: A E | | B--C F | D What I have on hand is the set of nodes {A, B, C, D...

When is each sorting algorithm used?

What are the use cases when a particular sorting algorithm is preferred - merge sort vs quick sort vs heap sort vs introsort, etc? Is there a recommended guide in using them based on the size, type of data strucutre, available memory and cache, and CPU performance. thanks, Sam ...

where is the best algorithm exercises like euler project?

i need learn algorithm... ...

Subset generation by rules

Let's say that we have a 5000 users in database. User row has sex column, place where he/she was born column and status (married or not married) column. How to generate a random subset (let's say 100 users) that would satisfy these conditions: 40% should be males and 60% - females 50% should be born in USA, 20% born in UK, 20% born in...

Project Euler #75: ways to optimize the algorithm

I'm looking at ways to optimize my algorithm for solving Project Euler #75, two things I have done so far are, Only check L with even values as this can be easily proved. Store L values that have been verified to have only one way to form an integer sided right angle triangle. Later on, when checking a new L value, I look for L's divis...

Bubble sort worst case example is O(n*n), how?

I am trying Bubble sort. There are 5 elements and array is unsorted. Worst case for bubble sort shuold be O(n^2). As an exmaple I am using A = {5, 4, 3, 2, 1} In this case the comparison should be 5^2 = 25. Using manual verification and code, I am getting comparison count to be 20. Following is the bubble sort implemenation code usi...