algorithm

Efficient algorithm for determining if a date is in DST

I'm looking for a better than O(n) algorithm to determine if a date in the future will have daylight savings time applied (and how much). Given a year, month, day, hour, minute and time zone (and a copy of the Olsen Time Zone database) how does one efficiently determine if that date will be in DST? I'm looking for the algorithm, not a ...

Best data structure to retrieve by max values and ID?

I have quite a big amount of fixed size records. Each record has lots of fields, ID and Value are among them. I am wondering what kind of data structure would be best so that I can locate a record by ID(unique) very fast, list the 100 records with the biggest values. Max-heap seems work, but far from perfect; do you have a smarter ...

Efficient EigenSolver Implementation

I am looking for an efficient eigensolver ( language not important, although I would be programming in C#), that utilizes the multi-core features found in modern CPU. Being able to work directly with pardiso solver is a major plus. My matrix are mostly sparse matrix, so an ideal solver should be able to take advantage of this fact and gr...

CRC32 and MD5 algorithms for dummies

I'd like to implement the CRC32 and MD5 algorithms on my own but I'm still trying to wrap my head around the different sources I've found on the subject. Could someone helpful point me to a ressource that explains the algorithms in a simple format or post a bullet list of the different steps so I can attempt to fill them in. TIA. Here's...

Map strings to numbers maintaining the lexicographic ordering

I'm looking for an algorithm or function that is able to map a string to a number in such way that the resulting values correspond the lexicographic ordering of strings. Example: "book" -> 50000 "car" -> 60000 "card" -> 65000 "a longer string" -> 15000 "another long string" -> 15500 "awesome" -> 16000 As a function it should be somet...

Checking for unique item in a list (C#)

Hello I have a list of items. Item is a object with two fields. One field is of type Dictionary<string, List<string> and second filed is of type int. Now I want to check if there is an item with both fields unique in that list. With dict field I care about key part, not value so value part may be the same between items. It is key that m...

How to fill a square with smaller squares/rectangles?

This is not a homework or interview question. In my office at work, we are not allowed to paint the walls, so I have decided to frame out squares and rectangles, attach some nice fabric to them, and arrange them on the wall. I am trying to write a method which will take my input dimensions (9' x 8' 8") and min/max size (1' x 3', 2', 4',...

Why having both str_replace() and preg_replace()?

I came to know PHP after Perl, so when I first found preg_* function I basically just used those. Later I read that str_replace() is faster when dealing with literal text. So my question is, can't preg_replace() be as efficient as str_replace() when the search pattern does not use special characters? Maybe just analyzing the pattern to c...

Reversing Part of a List in Prolog

My goal for this Prolog function is as follows: Given two lists, x and y, return true if y can be formed from x by reversing a contiguous part of list x. For example, if the input is x = [1, 3, 2, 4], y = [1, 2, 3, 4], the result should be "true" because we can reverse the second and third elements of x to get y. I really have no ide...

What kind of cool graphics algorithms can I implement?

I'm going to program a fancy (animated) about-box for an app I'm working on. Since this is where programmers are often allowed to shine and play with code, I'm eager to find out what kind of cool algorithms the community has implemented. The algorithms can be animated fractals, sine blobs, flames, smoke, particle systems etc. However...

How can I fairly choose an item from a list?

Let's say that I have a list of prizes: PrizeA PrizeB PrizeC And, for each of them, I want to draw a winner from a list of my attendees. Give that my attendee list is as follows: user1, user2, user3, user4, user5 What is an unbiased way to choose a user from that list? Clearly, I will be using a cryptographically secure pseudo-rand...

Strassen's algorithm for matrix multiplication

Can someone please explain strassen's algorithm for matrix multiplication in an intuitive way? I've gone through (well, tried to go through) the explanation in the book and wiki but it's not clicking upstairs. Any links on the web that use a lot of English rather than formal notation etc. would be helpful, too. Are there any analogies wh...

Minimum price selection

Situation looks like this: We have product 'A123' and we have to remember lowest price for it. Prices for one product comes from random number of shops and there is no way to tell when shop x will send us their price for 'A123'. So I had SQL table with columns: product_number price shop (from which shop this price comes) An SQL fun...

Data structure for storing thousands of vectors

I have upto 10,000 randomly positioned points in a space and i need to be able to tell which the cursor is closest to at any given time. To add some context, the points are in the form of a vector drawing, so they can be constantly and quickly added and removed by the user and also potentially be unbalanced across the canvas space.. I a...

Tree traversal algorithm for directory structures with a lot of files

When recursively traversing through a directory structure, what is the most efficient algorithm to use if you have more files than directories? I notice that when using depth-first traversal, it seems to take longer when there are a lot of files in a given directory. Does breadth-first traversal work more efficiently in this case? I have...

Explaining the AdaBoost Algorithms to non-technical people

I've been trying to understand the AdaBoost algorithm without much success. I'm struggling with understanding the Viola Jones paper on Face Detection as an example. Can you explain AdaBoost in laymen's terms and present good examples of when it's used? ...

Finding Common Sets within noisy data

Context: Consider each set within G to be a collection of the files (contents or MD5 hashes, not names) that are found on a particular computer. Suppose I have a giant list of giant sets G and an unknown to me list of sets H. Each individual set I in G was created by taking the union of some unknown number of sets from list H, then add...

General classes/source code for solving Java algorithmic problems?

I need to build a small repository of algorithms with implementation and description. I found recently, for example, an efficient permutations generator for permutations of arbitrary length. Where can I find full source code implementations with short descriptions of other such algorithms? Anything covered in the Java API is not needed,...

deep copy Linkedlist without destroying original list and extra storage space (using ANSI C)

this linkedlist is different than normal linkedlists is that besides the next pointer, it also has a other pointer that points to another node except itself in the linkedlist. so what's the best way to deep copy this linkedlist without destroying the original and no extra space? My approach was simply doing a O(n^2) loop , but should b...

Vehicle Routing / Resource Scheduling Algorithm Design

Hi Guys, My first post here – hoping you can help me with designing an algorithm that I’ve been considering for a little while now – not sure what approach to take (VRPTW or resource scheduling or something else entirely!?) To put it into a real word example, we have a whole lot of garden waste at a small number of locations (usually le...