algorithm

Binary Searching

Hi So, I want to understand more about binary searching, cause I don't really understand. Binary search requires a precondition that an array is sorted. I got that right? It seems like a method should check this precondition and throw an exception if it is not met. But, why is checking the precondition a bad idea? ...

Find a prime number?

To find whether N is a prime number we only need to look for all numbers less or equal to sqrt(N). Why is that? I am writing a C code so trying to understand a reason behind it. ...

translation algorithm

Recently I am working into the ability of translating a PHP web application from one language to another. Well, most of those I read involves having language files, then display the selected one like this: en.lang.php: <?php $_TEXT = array(); $_TEXT['welcome'] = 'Welcome to My Application'; ?> fr.lang.php: // french (i translated t...

Understanding word alignment

I understand what it means to access memory such that it is aligned but I don’t understand why this is necessary. For instance, why can I access a single byte from an address 0x…1 but I cannot access a half word (two bytes) from the same address. Again, I understand that if you have an address A and an object of size s that the access i...

O Notation Help

I am getting stuck with the class work we got this week and its a subject i really want to learn so for once i thought i would do the additional reading!!!! The method is provided for us and i am just writign some test cases. This is where my knowledge gets a little hazy. If the time increases then i am underestimatign the complexity i ...

How to implement in Excel: If cell A1 is 0, cell A2 = "foo". Else, let the user specify an input.

It's pretty straight forward. If a certain cell, such as A1, is the value "0", I would like A2 to contain an arbitrary value. Otherwise, I would like the user to be able to enter their own value. The first part is easy: A2=IF(A1 = "0", "value", "") However, if A2 is empty, and the user goes to edit the value, Excel presents the formula...

What algorithms do DNS servers use for faster lookups?

DNS servers have to be fast in order to avoid latency. What algorithms do DNS Servers use to reduce latency? Are they any caching mechanisms that could be effectively used to improve speed? ...

How to find the intersection point between a line and a rectangle?

I have a line that goes from points A to B; I have (x,y) of both points. I also have a rectangle that's centered at B and the width and height of the rectangle. I need to find the point in the line that intersects the rectangle. Is there a formula that gives me the (x,y) of that point? PS: I'm working with C# but a solution in a simila...

given 5 numbers, what is the minimum number of comparisons needed to find the median?

how do you setup minimum number of comparisons in general? ...

Big-O algorithm analysis

The questions: What I've done: But I've got totally no idea the difference between 3.5 and 3.6. ...

Combine Gyroscope and Accelerometer Data

I am building a balancing robot using the Lego Mindstorm's NXT system. I am using two sensors from HiTechnic, the first being an Accelerometer and the second being a Gyroscope. I've successfully filtered out noise from both sensors and derived angles for both in a range between -90 and 90 degrees, with 0 degrees being perfectly balanced....

What is test best sorting algorithm for a Doubly LinkedList

Hi, Can someone recommend me a sorting algorithm for my custom link list + example, basically it is similar to the Generic LinkedList so if you could give examples for the Generic LinkedList it will be great. I am planning to implement the merge sort, please advice on the pros/cons as I am not so familiar with any algorithm, just taken...

Find the Smallest Integer Not in a List

An interesting interview question that a colleague of mine uses: Suppose that you are given a very long, unsorted list of unsigned 64-bit integers. How would you find the smallest non-negative integer that does not occur in the list? FOLLOW-UP: Now that the obvious solution by sorting has been proposed, can you do it faster than O(n lo...

how to get the similar texts from a lot of pages?

get the x most similar texts from a lot of texts to one text. maybe change the page to text is better. You should not compare the text to every text, because its too slow. ...

Optimization! - What is it? How is it done?

Its common to hear about "highly optimized code" or some developer needing to optimize theirs and whatnot. However, as a self-taught, new programmer I've never really understood what exactly do people mean when talking about such things. Care to explain the general idea of it? Also, recommend some reading materials and really whatever y...

Which algorithm does Neatimage use to denoise images?

Which kind of algorithm does Neatimage use to remove noise and grain from photos? I understand that this is proprietary software, but probably someone has an idea. References to publications or to similar algorithms are welcome. ...

Distinguishing extra element from two arrays?

One of my friend was asked this question in an interview - You have given two integer arrays each of size 10. Both contains 9 equal elements (say 1 to 9) Only one element is different. How will you find the different element? What are different approaches you can take? One simple but lengthy approach would be - sort both arrays,...

Simple queue algorithm question

This is not a request for a queueing algorithm, I know there are plenty. I'm reading a C# book and it explains the Circular Queue algorithm with a code example. On lines 13, 14 and 15, he explains how to check if the queue is full. However I can't understand why the first optional condition is necessary. Could someone show me a situatio...

What's wrong with my random wandering algorithm?

I've created a 2 dimensional 'grid' for a game world I'm creating in Java. I'm having a problem with the 'wander' mode algorithm I've created. I noticed a problem that the objects would seem to favor the bottom right corner of the grid. I changed the algorithm and thought it was fixed. Today, while stress testing, I noticed that the p...

DB design for synced desktop application

I'm building a desktop application that will run on multiple laptops. It will need to sync up to a central database whenever the user is back in the office and has access again. My biggest problem to overcome is how to design the database so that it is easily synced with the central database server. One of the major hurdles is trying t...