Quantcast
Channel: Everyday I'm coding » algorithm
Browsing all 11 articles
Browse latest View live

Throwing the fattest people off of an overloaded airplane.

Let’s say you’ve got an airplane, and it is low on fuel. Unless the plane drops 3000 pounds of passenger weight, it will not be able to reach the next airport. To save the maximum number of lives, we...

View Article



Image may be NSFW.
Clik here to view.

Undo/Redo implementation

Give me some thoughts how to implement undo/redo functionality – like we have in text editors. What algorithms should I use and what I may read. thanks. Solution: I know about two major divisions of...

View Article

Why does Java’s hashCode() in String use 31 as a multiplier?

In Java, the hash code for a String object is computed as s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1] using int arithmetic, where s[i] is the ith character of the string, n is the length of the...

View Article

what is effective way to find duplicate between two sets?

I have set A and B set A has 100 million number(each number is 64bit) set B has 100 million number(each number is 64bit) two sets are same size. data is all random and not sorted. what algorithm would...

View Article

Are there any sites that do Python programming challenges similar to...

I really learned a lot about programming doing some of the problems on Project Euler, but I’m not much of a math guy. I am looking for similar programming projects just for fun. Does anyone know any...

View Article


FFT Algorithm: What goes IN/OUT? (re: real-time pitch detection)

I am attempting to extract pitch data from an audio stream. From what I can see, it looks as though FFT is the best algorithm to use. Rather than digging straight into the math, could someone help me...

View Article

Determine if two rectangles overlap each other?

I am trying to write a C++ program that takes the following inputs from the user to construct rectangles (between 2 and 5): height, width, x-pos, y-pos. All of these rectangles will exist parallel to...

View Article

How exactly does tail recursion work?

I almost understand how tail recursion works and the difference between it and a normal recursion. I only don’t understand why it doesn’t require stack to remember its return address. // tail recursion...

View Article


Image may be NSFW.
Clik here to view.

List of Big-O for PHP functions

After using PHP for a while now, I’ve noticed that not all PHP built in functions as fast as expected. Consider the below two possible implementations of a function that finds if a number is prime...

View Article


Maximum number of characters using keystrokes A, Ctrl+A, Ctrl+C and Ctrl+V

This is an interview question from google. I am not able to solve it by myself. Can somebody shed some light? Write a program to print the sequence of keystrokes such that it generates the maximum...

View Article

Kruskal vs Prim

I was wondering when one should use Prim’s algorithm and when Kruskal’s to find the minimum spanning tree? They both have easy logics, same worst cases, and only difference is implementation which...

View Article
Browsing all 11 articles
Browse latest View live




Latest Images