algorithm

A simple example for someone who wants to understand Dynamic Programming

I am looking for a manageably understandable example for someone who wants to learn Dynamic Programming. There are nice answers here about what is dynamic programming. The fibonacci sequence is a great example, but it is too small to scratch the surface. It looks a great subject to learn about although I haven't taken the algorithms clas...

Bubble Breaker Game Solver better than greedy?

For a mental exercise I decided to try and solve the bubble breaker game found on many cell phones as well as an example here:Bubble Break Game The random (N,M,C) board consists N rows x M columns with C colors The goal is to get the highest score by picking the sequence of bubble groups that ultimately leads to the highest score A bu...

C#, Search string, ASP

Hello, I have a MultiLine textbox, txtReadDocs.Text; I'd like to search the contents of text "txtReadDocs". To use a simple search algorithm: Search for the entire search term entered by the user. For example, if the user enters "hello", search only for "hello". If the user enters "hello world", search only for the complete term "...

Is this lock-free .NET queue thread safe?

My question is, is the class included below for a single-reader single-writer queue class thread-safe? This kind of queue is called lock-free, even if it will block if the queue is filled. The data structure was inspired by Marc Gravell's implementation of a blocking queue here at StackOverflow. The point of the structure is to allow a ...

Сrossover operation in Genetic algorithm for TSP

Hello everybody. I'm trying to solve the Travelling Salesman Problem (TSP) with Genetic algorithm My Genome is permutation of vertex in graph (path for Salesman). How should I perform the crossover operation over my genomes? Where I can find implementations of my problem in C#? ...

What algorithm would you use to solve a very large tic-tac-toe game?

A small (3x3, 4x4) tic-tac-toe can be easily solved by considering all the cases. But for example, you have a 30x30 tic-tac-toe. What algorithm would you use to decide the next best move in that case? Minimax + alpha-beta pruning is one way that I know. Is there some other way that is more efficient/not more efficient but cooler? ...

Learning Java and logic using debugger. Did I cheat?

After a break from coding in general, my way of thinking logically faded (as if it was there to begin with...). I'm no master programmer. Intermediate at best. I decided to see if i can write an algorithm to print out the fibonacci sequence in Java. I got really frustrated because it was something so simple, and used the debugger to ...

Python k-means algorithm

I am looking for Python implementation of k-means algorithm with examples to cluster and cache my database of coordinates. ...

open source gossip-based membership protocol?

I am looking for a library which I can plug into a distributed application which implements any gossip-based membership protocol. Such a library would allow me to send/receive membership lists, merge received membership lists, etc... Even better would be if the library implemented a protocol with performance O(logn) performance guarante...

Java How to find a value in a linked list iteratively and recursively

Hi I have a method that has a reference to a linked list and a int value. So, this method would count and return how often the value happens in the linked list. So, I decided to make a class, public class ListNode{ public ListNode (int v, ListNode n) {value = v; next = n;) public int value; public ListNode next; } Then, the metho...

HTML Parsing/Scraping Algorithm Help..Java

I am writing a program that an HTML scraper that when it grabs the HTML from the page, it returns the HTML, and I want to Grab words that are All Capital letters, and then stores these words into a database. My problem right now is I cannot right the algorithm to parse each line of the HTML I got back in order to store the words. This is...

Grouping data points into series

I have a series of data points (tuples) in a list with a format like: points = [(1, 'a'), (2, 'b'), (2, 'a'), (3, 'd'), (4, 'c')] The first item in each tuple is an integer and they are assured to be sorted. The second value in each tuple is an arbitrary string. I need them grouped in lists by their first value in a series. So give...

Design patterns for converting recursive algorithms to iterative ones

Are there any general heuristics, tips, tricks, or common design paradigms that can be employed to convert a recursive algorithm to an iterative one? I know it can be done, I'm wondering if there are practices worth keeping in mind when doing so. ...

Resources about Shen Castan algorithm

I have started some simple project about Text Detection in images. And one of steps in solving this problem is implementation of Edge detector. I wanted to implement Shen Castan, because it gives better results with noisy images. Problem is that I cannot find anywhere some usefull resources about this algorithm. Does anyone knows how Sha...

I was asked this in a recent interview

I was asked to stay away from HashMap or any sort of Hashing. The question went something like this - Lets say you have PRODUCT IDs of up to 20 decimals, along with Product Descriptions. Without using Maps or any sort of hashing function, what's the best/most efficient way to store/retrieve these product IDs along with their descripti...

What Software Engineering Areas should be stressed upon while Interviewing Candidate for Fulltime Software Engineering Position ?

Hi, This question is somewhat related to other posts which I found on Stackoverflow but not exactly and so am prompted to ask about it. I know we must ask for Data-Structures and Algorithms but what specific data-structures or Algorithms or other CS Concepts should be asked while interviewing Sr. Software Engineering Fulltime Positio...

Hashing-algorithm for dates

What would be a good hash-algorithm to hash dates, e.g. 24/12/09 and 31/10/89? The dates would range from about year 1950 to 2050. Could using the unix timestamp somehow, be possible? ...

Is there any metadata associated with word document?

Hi, I am trying to generate check sum of a word document by opening at binary level. I generate the check sum of the document. Copy the document to a different location. When I generate the checksum at the new location I get a different value though I haven't changed the contents of the document. The check sum varies even if I copy the ...

Generate random directories/files given number of files and depth

I'd like to profile some VCS software, and to do so I want to generate a set of random files, in randomly arranged directories. I'm writing the script in Python, but my question is briefly: how do I generate a random directory tree with an average number of sub-directories per directory and some broad distribution of files per directory?...

How to automatically tune parameters of an algorithm?

Here's the setup: I have an algorithm that can succeed or fail. I want it to succeed with highest probability possible. Probability of success depends on some parameters (and some external circumstances): struct Parameters { float param1; float param2; float param3; float param4; // ... }; bool RunAlgorithm (const Parameters...