Prefix search against half a billion strings

I have a list of 500 mil strings. The strings are alphanumeric, ASCII characters, of varying size (usually from 2-30 characters). Also, they're single words (or a combination of words without spaces like 'helloiamastring'). What I need is a fast way...
more »

2017-01-15 18:01 (3) Answers

C Multiple arrays permutations algorithm

I'm trying to write a program that generates permutations upon a list of words stored into several arrays. For example, my program asks for 2 groups of words like this : words #1: abc def ghi words #2: 123 456 What i'm trying to have is this outp...
more »

2017-01-13 11:01 (1) Answers

Time Complexity of permutation function

Given a collection of distinct numbers, return all possible permutations. For example, [1,2,3] have the following permutations: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1] ] My Iterative Solution is : public List<Li...
more »

2017-01-13 06:01 (2) Answers

XOR on contiguous subarrays of an array

From an array, I need to find the value obtained by XOR-ing the contiguous subarrays, following by XOR-ing the values thus obtained. INPUT One line containing integers that are elements of the array. e.g. [1,2,3] OUTPUT Print the answer correspo...
more »

2017-01-11 10:01 (1) Answers

Memory leak after algorithm in Rails?

I wrote an algorithm inspired by the merge part of the merge sort. def self.merge(arr) if arr.length == 1 return arr end groups = [] (0...-(-arr.length/2)).each do |i| groups << [] if !arr[2*i+1].nil? ...
more »

2017-01-11 03:01 (1) Answers

Graph search algorithm with fewest accessed nodes

I need an algorithm to find ANY path from point A to point B in a graph. The problem is that finding out wich nodes can follow a specific one needs a quite lengthy matlab simulation, so i want to access as few nodes as possible. I know some heuristi...
more »

2017-01-10 11:01 (0) Answers

Sort an array of integers into odd, then even

I have a problem I found on an algorithm forum elsewhere. I have an array with random numbers (for example, [5, 2, 7, 9, 2, 3, 8, 4]) which should be returned to me sorted by odd then even. The order of the odds/evens is not important so in the exam...
more »

2017-01-07 09:01 (10) Answers

Why Is This Factorial Algorithm Not Accurate

Sorry I feel stupid asking this and am prepared to lose half of my points asking this but why does this algorithm not work? It works up to a point. After the number 13 the factorials are a little off. For instance the numbers do not entirely match in...
more »

2017-01-06 17:01 (5) Answers

Performing a Binary Search

I am performing a binary search , let say i have to find the minimum value of x such that black_box(x) gives me true result. Property of black_box(x) If black_box(x) gives me true then x+1,x+2,x+3,x+4....upto infinty all gives me true For Intege...
more »

2017-01-06 11:01 (1) Answers

Average face - algorithm

Quesion and code is at the end I hope this question belongs here and not to the TCS's stack. I am trying to go through algorithms in Turk and Pentland's "Eigenfaces for Recognition". On page 74 one can read (last paragraph of left column): Let t...
more »

2017-01-03 22:01 (1) Answers

Wagner Fischer algorithm + display steps

I made an implementation of Wagner Fischer algorithm in java with input cost, but I want to display all steps. I search but can't find any idea.After a long time I tried to keep each transformation in matrix alongside cost and to go through back to f...
more »

2017-01-02 21:01 (2) Answers

non-binary tree search and insertion

I searched a bit but haven't found the answer to this question.. I built a non-binary tree, so each node can have any number of children (called n-ary tree i think) To help with searching, I gave every node a number when i built the tree, so that e...
more »

2017-01-02 04:01 (1) Answers

What is the space complexity of this code?

int f(int n) { if (n <= 1) { return 1; } return f(n - 1) + f(n - 1); } I know that the time complexity is O(2^n) and I understand why. But I don't understand why the space complexity is O(n). I was told that it's be...
more »

2016-12-31 22:12 (3) Answers

Divide and conquer trominos algorithm in C

This is the classic divide and conquer problem. We have a 2^n * 2^n board and we want to fill it with L shaped cubes. We know there is one block on the board that we can't assign a cube. This problem is also known as tromino problem (somewhat). Prob...
more »

2016-12-28 13:12 (1) Answers

Ruby - Determine Big O comparing two arrays

My algorithm skills are lackluster. I created a method to see if two arrays contain the same elements (duplicates don't matter): one = [1, "taco", 3, 2, :piece, 4, 5, 5, 5, 5] two = [:piece, 2, 5, 4, 1, "taco", 3] def same_elements?(array_one, arra...
more »

2016-12-27 21:12 (2) Answers