Category "algorithm"

How to improve Merge Sort speed in python

Yes, it is homework, but I ended up doing it in Java just to get it done, but now the python implementation is bothering me. I'm pretty sure I've implemented it

What's the difference between big O and big Omega?

Big Omega is supposed to be the opposite of Big O, but they can always have the same value, because by definition Big O means: g(x) so that cg(x) is bigger or

Zig-zag scan an N x N array

I have a simple array. The array length always has a square root of an integer. So 16, 25, 36 etc. $array = array('1', '2', '3', '4' ... '25'); What I do, is

Zig-zag scan an N x N array

I have a simple array. The array length always has a square root of an integer. So 16, 25, 36 etc. $array = array('1', '2', '3', '4' ... '25'); What I do, is

how to make my own auto increment in php?

The in-built Auto-Increment in MySQL doesn't meet my requirement so I'm thinking about making a new one. Here is my requirement: Create an increment serial num

Heap's algorithm for permutations

I'm preparing for interviews and I'm trying to memorize Heap's algorithm: procedure generate(n : integer, A : array of any): if n = 1 then output

How to do the Bisection method in Python

I want to make a Python program that will run a bisection method to determine the root of: f(x) = -26 + 85x - 91x2 +44x3 -8x4 + x5 The Bisection method is a

Russia VAT Number validation

Does anyone have code to validate for validating Russian TAX Registration number (VAT). C# code will be great, but if someone have some other language it will b

Find the Longest Subarray

Given an array of integers, what is the length of the longest subarray containing no more than two distinct values such that the distinct values differ by no mo

Algorithm for straightening tilted document

I'm on a project involving OCR. After detecting each character, I need to combine close characters to create words. To do that I tried to create a priority queu

Find all subsets of length k in an array

Given a set {1,2,3,4,5...n} of n elements, we need to find all subsets of length k . For example, if n = 4 and k = 2, the output would be {1, 2}, {1, 3}, {1,

Solving crosswords efficiently [closed]

I have a crossword puzzle and a list of words which can be used to solve it (words can be placed multiple times or not even once). There is al

How to find if there are n consecutive set bits in a 32 bit buffer?

Maybe you can help me with the following problem that can help me speed a memory manager I am thinking of (I am not sure a solution exists – I did not fin

Nested for loop in Big Oh Complexity

for(int i = 0; i < n; i++) { for(int j = 0; j < i; j++){ // do swap stuff, constant time } } I read that single for loop is O(N) and trav

How to invert a permutation array in numpy

Given a self-indexing (not sure if this is the correct term) numpy array, for example: a = np.array([3, 2, 0, 1]) This represents this permutation (=> is

Algorithm to find same substring from a list of strings

I'm a bit lost here, some help is welcomed. The idea is to find a matching substring from a list of strings. It doesn't has to be perfect. Let's explain this wi

What is meant by k-anonymity and l-diversity, and what is difference between them? [closed]

What is meant by k-anonymity and l-diversity, and what is difference between them? This concept is used in the following IEEE paper.

Expected pair of collisions in two choice hashing

In two choice hashing(with chaining), two random hash functions h1, h2 are selected to hash n keys to m positions. The process goes like this: Insert all n key

Building general trees in java (with recursion)

I have been stuck on a problem for quite a few days. My end goal is to perform preorder, inorder, and postorder traversals on a general tree. The problem I am h

Merge Overlapping Regions

Given a set of intervals, we can efficiently merge the overlapping intervals using this algorihtm: http://www.geeksforgeeks.org/merging-intervals/ However, if