algorithm

Sort N numbers in digit order

I found out about this question recently. Given a N number range Eg. [1 to 100], sort the numbers in digit order (i.e) For the numbers 1 to 100, the sorted output wound be 1 10 100 11 12 13 . . . 19 2 20 21..... 99 This is just like Radix Sort but just that the digits are sorted in reversed order to what would be done in a normal Radix...

Algorithm to find whether 2 objects on a 2D Plane will collide

I'm trying to determine whether Object1 will collide with Object2 given the following information: 1) Objects' bounding boxes (uses bounded-box collision detection) 2) Objects' speeds 3) Object's current locations (x, y coordinate) 4) Objects' directions (Up, Down, Left, or Right) For a bit of imagery, imagine the objects traveling ...

Count connected dots in a grid

I have a grid of m X n cells. Some of them are on and off state. Find an efficient algorithm to count the no of connections. Many dots connected in top, left, right, bottom still be considered 1 connection. ...

Minimum Window for the given numbers in an array

Saw this question recently: Given 2 arrays, the 2nd array containing some of the elements of the 1st array, return the minimum window in the 1st array which contains all the elements of the 2nd array. Eg : Given A={1,3,5,2,3,1} and B={1,3,2} Output : 3 , 5 (where 3 and 5 are indices in the array A) Even though the range 1 to 4 als...

Is it possible to find out which hash algorithm was used in these strings?

I don't want to reverse it. I just want to be sure what hash algorithm was used on these strings (I'm not sure if it's md5): d27918bcc2a8562dc4549c2c00111e66 889f071e04755db26579a19f4303654e 47a21a13ee822c1450155bd0033b0f1d Is there a way to do it? One of the source for the strings above is certainly: '9915757678' ...

Solving a recreational square packing problem

I was asked to find a 11x11-grid containing the digits such that one can read the squares of 1,...,100. Here read means that you fix the starting position and direction (8 possibilities) and if you can find for example the digits 1,0,0,0,0,4 consecutively, you have found the squares of 1, 2, 10, 100 and 20. I made a program (the algori...

Wireless Node Discovery

what is the best algorithm for wireless node discovery. suppose you have a large wireless or bluetooth network, were every node has its own range of discovery. what is the best algorithm that makes any node discover about the full graph topology, ie any node will know about all other nodes in the graph? ...

How do I design an algorithm to find the biggest number in a list of numbers?

I also need to convert my answer into javascript code that displays the largest value. ...

Loading powershell script around 10000 times.

I have a powershell script that runs during an msbuild process and validates some stuff by extracting info from log files. The script loads 2 xml files and then does some validation from the data extracted from the log files. Usually the script takes on average 1 to 2 seconds to run. Loading the xml files takes around 800ms to run. Sinc...

Algorithm for activation key- Security

I'm writing a software application that the user needs to buy a license for and activate it. I need suggestions on how to start about writing a powerful algorithm for code generation and of course, code checking. I know that people can reverse engineer the code and make a keygen, however, my question is two parts: In general, regardles...

Limit floating point precision?

Is there a way to round floating points to 2 points? ex: 3576.7675745342556 becomes 3576.76. Thanks ...

Data structure for updating values and querying the state of values at a time in the past

Suppose you're interested in a bunch of independent time-varying values, each of which represents the current state of something. The values don't change on any fixed schedule and new values can't be predicted from old ones. For the sake of a concrete example, let's say you have a bunch of stocks and you're interested in keeping track of...

Pseudocode for Swept AABB Collision

I think swept means determining if objects will collide at some point, not just whether they are currently colliding, but if I'm wrong tell me. I have objects with bounded boxes that are aligned on an axis. The boxes of objects can be different sizes, but they are always rectangular. I've tried and tried to figure out an algorithm to ...

Writing Simulated Annealing algorithm for 0-1 knapsack in C#

I'm in the process of learning about simulated annealing algorithms and have a few questions on how I would modify an example algorithm to solve a 0-1 knapsack problem. I found this great code on CP: http://www.codeproject.com/KB/recipes/simulatedAnnealingTSP.aspx I'm pretty sure I understand how it all works now (except the whole Bol...

Difference between two maps

I need to very efficiently compare two maps in Clojure/Java, and return the difference as determined by Java's .equals(..), with nil/null equivalent to "not present". i.e. I am looking for the most efficient way to a write a function like: (map-difference {:a 1, :b nil, :c 2, :d 3} {:a 1, :b "Hidden", :c 3, :e 5}) => {:b nil, :c 2...

Algorithmic issue: determining "user sessions"

I've got a real little interesting (at least to me) problem to solve (and, no, it is not homework). It is equivalent to this: you need to determine "sessions" and "sessions start and end time" a user has been on in front of his computer. You get the time at which any user interaction was made and a maximum period of inactivity. If a ti...

How to prove a binary tree is indeed a binary search tree?

Hello, Given a simple binary tree, how can we prove that tree is a binary search tree? When we traverse a binary tree, how do we know if the node we are on is the left or right child of its parent? I came up with one solution where i would pass some flag in recursive function call which could keep track of whether the node is left or ri...

finding a number appearing again among numbers stored in a file

Hello, Say, i have 10 billions of numbers stored in a file. How would i find the number that has already appeared once previously? Well i can't just populate billions of number at a stretch in array and then keep a simple nested loop to check if the number has appeared previously. How would you approach this problem? Thanks in advance...

Understanding the motion of a disk using two static switches

This is a major re-write of the original question, I tried to clarify those points that were evidently confusing for some in my first version of the question. Thanks for the input in helping formulate the problem better! CONTEXT The challenge comes from a real-life coding problem. The first thing that responders should be aware of, is ...

C# 4.0, Most efficient way to determine if a string length != 0? Part 2

(My apologies, this is a 2nd post to http://stackoverflow.com/questions/3390175/most-efficient-way-to-determine-if-a-string-length-0 but I can't figure out how to reply to people's answers, my reply becomes posted as an 'answer') Ideally, what I'm looking for is the most efficient algorithm to do the following (which will be called 100m...