algorithm

Append a digit to an integer and make sure sum of each digits ends with 1

What is the algorithm in c# to do this? Example 1: Given n = 972, function will then append 3 to make 9723, because 9 + 7 + 2 + 3 = 21 (ends with 1). Function should return 3. Example 2: Given n = 33, function will then append 5 to make 335, because 3 + 3 + 5 = 11 (ends with 1). Function should return 5. ...

Is O(logn) always a tree?

We always see operations on a (binary) tree has O(logn) worst case running time because of the tree height is logn. I wonder if we are told that an algorithm has running time as a function of logn, e.g m + nlogn, can we conclude it must involve an (augmented) tree? EDIT: Thanks to your comments, I now realize divide-conquer and binary ...

Algorithms question/problem lists

Hi, This may not be question of programming and people are open to close. Does anyone has list of questions/problems to solve which helps to improve algorithms skills may be for interview purpose. ...

fast sphere-grid intersection

hi! given a 3D grid, a 3d point as sphere center and a radius, i'd like to quickly calculate all cells contained or intersected by the sphere. Currently i take the the (gridaligned) boundingbox of the sphere and calculate the two cells for the min anx max point of this boundingbox. then, for each cell between those two cells, i do a bo...

Find the length of the largest increasing sequence

What's a fast algorithm for finding the length of largest monotonically increasing sequence in an array of integers. ...

Impossible compression algorithm

Consider US Patent #5533051: To my best understanding, what the patented algorithm says is that it can guarantee a lossless one-bit compression on any input. Clearly this is totally impossible (recursivly apply the algorithm to reach a one-bit representation of any input). Am I understanding this algorithm the wrong way? ...

What encryption algorithm would be best for data transfer between Python and Php?

Hi all, I am writing a client / server based program, Server side is with Php and Client is with Python, and I need to make sure the transfer data is safe both way. So, My question is What encryption algorithm would be best for data transfer between Python and Php? I couldn't use Https Need to decrypt/encrypt with key on both Pytho...

Efficient comparison of 1 million vectors containing (float, integer) tuples

I am working in a chemistry/biology project. We are building a web-application for fast matching of the user's experimental data with predicted data in a reference database. The reference database will contain up to a million entries. The data for one entry is a list (vector) of tuples containing a float value between 0.0 and 20.0 and an...

How to create endless stories for telenovela or tv-series programmatically?

Do you know any (web) sources that describe ways to continually produce stories from an initial base of parameters/objects and some given relationships? I'm interested in - theory and algorithms - real projects where it was done - how to measure redundance in such a system - (fun) sites with examples of something comparable ...

How to calculate the shortest path between two points in a grid

Hello! I know that many algorithms are available for calculating the shortest path between two points in a graph or a grid, like breadth-first, all-pairs (Floyd's), Dijkstra's. However, as I noticed, all of these algorithms compute all the paths in that graph or grid, not only those between the two points we are interested in. MY QUES...

Creating an ASP.Net Table is very slow, is there a better solution ?

Hello all, I have a DataTable with 20.000 row and 15 column. I need to create an ASP.Net Table, my code is similar to this: //foreach Row in my DataTable do the following: TableRow t2Row = new TableRow(); TableCell t2Cell0 = new TableCell(); t2Cell0.Text = Count.ToString(); t2Row.Cells.Add(t2Cell0); ...

How does OAuth work?

I mean not how is it implemented but rather what steps should user pass? I'm working with Photobucket now and I found in its docs that I should generate new token for every request due to token can expire in certain (but secret) period of time. How does this generation works? Do I need separate request for generating token? ...

The Definitive Algorithm Book List

Possible Duplicate: Modern books on algorithms Though there are a few questions on algorithm book recommendation,I thought we could make a more comprehensive and definitive version.Please provide book with suitable category such as reference,graph,etc. Encyclopaedia Style The Art of Computer Programming by Donald E. Knuth...

How to Find the Right Category for Each Product?

I need to submit my hundreds of products to hundreds of websites. For most websites I need to select a directory/category for each product. But it seems each website has a different definition of categories. For example, some list laptops under computers/hardware, some under computers/laptop, some under /electronics/computers, some unde...

How to get 2-Sat values

Whenever I search for an algorithm for 2-Sat, I get back the algorithm for the decision form of the problem: Does there exist a legal set of values that satisfy all the clauses. However, that does not allow me to easily find a set of satisfying boolean values. How can I efficiently find a legal set of values that will satisfy a 2-Sat in...

Calculate mode of a sequence of numbers without using arrays/vectors

I'm a TA for an Introduction to MATLAB course, and the class has not yet learned the use of arrays (or in MATLAB, vectors). There is an exam coming up and one of the questions on the study guide is as follows: [Tough problem] A mode is the number in a sequence that appears the most number of times. A user is prompted to enter a sequen...

How can I write a function that returns a list of keys in a nested table?

I have a hierarchically nested associative array. It looks like this: A = { B = { C = {}, D = {}, }, E = { F = { G = {} } }, H = {} } I would like to write a function that returns the "ancestors" of each key. So: f("A") = {"A"} f("B") = {"B","A"} f("C") =...

What is the algorithm to search an index for multiple values?

This is actually a real problem I'm working on, but for simplicity, let's pretend I'm Google. Say the user searches for "nanoscale tupperware". There aren't very many pages with both words... only about 3k. But there are ~2 million pages with "nanoscale" and ~4 million with "tupperware". Still, Google finds the 3k for me in 0.3 seconds....

City building strategy algorithms

I'm looking for some papers on finding an infrastructure development strategy in games like Starcraft / Age of Empires. Basic facts characterising those games are: continuous time (well - it could be split into 10s periods, or something like that) many variables describing growth (many resources, buildings levels, etc.) many variables ...

What is a Deterministic Quicksort?

I have been reading about Quicksort and found that sometimes it' s referred to as "Deterministic Quicksort". Is this an alternate version of the normal Quicksort ? What is the difference between a normal Quicksort and a Deterministic Quicksort ? ...