Category "algorithm"

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

Minimum car required to accommodate given people

I had one coding round where question statement was like this *You have a given number of friends and seating capacity of their cars now you need to find minimu

Generating integers in ascending order using a set of prime numbers

I have a set of prime numbers and I have to generate integers using only those prime factors in increasing order. For example, if the set is p = {2, 5} then my

Daily Coding Problem 260 : Reconstruct a jumbled array - Intuition?

I'm going through the question below. The sequence [0, 1, ..., N] has been jumbled, and the only clue you have for its order is an array representing whether e

dynamic minimum spanning tree

I want to make a dynamic minimum spanning tree. I have an existing MS tree over n vertices and I add one more vertex and edges to all the existing vertices from

algorithm to calculate portfolio weights with negative returns?

Summary Below is the full question (a bit complicated in its full form) here's a super simplified version (which is the heart of what I'm asking). If I told you

Two robots on a line

You probably know the problem with the two robots dropped on a line when you need to program them to meet. Two robots are dropped from an airplane and land

Generating combinations in c++

I have been searching a source code for generating combination using c++. I found some advanced codes for this but that is good for only specific number predefi

Given a number, find the next higher number which has the exact same set of digits as the original number

I just bombed an interview and made pretty much zero progress on my interview question. Given a number, find the next higher number which has the exact same se

Mapping coordinates from plane given by normal vector to XY plane

So, I have this algorithm to calculate cross-section of 3D shape with plane given with normal vector. However, my current problem is, that the cross-section is