Binary search when a part of array was reversed

Given an array(size N) (sorted but some part of it was reversed), And a series of elements (Q), we have to output Yes/No based on whether the element is present or not in the array. The solution which I came up was as below: Do a linear traversal ...
more »

2017-06-20 13:06 (3) Answers

Rotate the indices on a hexagon

I have hexagons made of little unit hexagons. Each hexagon has a hex number of unit hexagons. The first few are numbered like: Size 1: 0 Size 2: 0 1 2 3 4 5 6 Size 3: 0 1 2 3 4 5 6 7 8 9 A B C D E F 101112 (Last one is in hexad...
more »

2017-06-17 19:06 (4) Answers

Solving crosswords

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 always a solution for the given crossword and word list. I searched for clues on how to solve this problem an...
more »

2017-06-17 18:06 (4) Answers

Algorithm to find disconnected graph from sets

Goal: Want to efficiently find all the disconnected graphs from a large collection of sets For example, I have a data file like the following: A, B, C C, D, E A, F, Z G, J ... each entry represents a set of element. First entries A, B, C = {A, B,...
more »

2017-06-16 21:06 (3) Answers

Searching the k nearest elements

I have a bunch (more or less 3500) of vectors with 4096 components and I need a fast method to see, given an input of another vector with the same length, which are the nearest N. I would like to use some matlab functions to do that. Is this ok for w...
more »

2017-06-13 10:06 (1) Answers

Changing O(n^3) to O(n^2) in JavaScript

I'm trying to wrap my head around saving time in my coding solution. I have a function called tripletSum which takes two parameters x and a where x is a number and a is an array. This function is supposed to return true if the list a contains three...
more »

2017-06-12 23:06 (3) Answers

Java interpolation search with floating numbers

I am currently trying to implement interpolation search with floating numbers, here is my code: import java.util.Arrays; class InterpolationSearch { private static float comparisions = 0; public static int interpolationsearch (double arr[...
more »

2017-06-09 22:06 (2) Answers

Using A* search algorithm

I am working in graph mining, and for my current research, I am trying to fund the proximity between non-adjacent nodes in the graph. However, since non-adjacent nodes are ubiquitous, so I want to narrow-down the number of non-adjacent nodes that ar...
more »

2017-06-09 18:06 (1) Answers

What is the Complexity of Find() Function

I have two versions of find function, both of which search an integer value in an array and return its position if exists. Function find1() will search up to N elements in worst case on the other hand find2() function will search up to N/2 elements i...
more »

2017-06-09 07:06 (1) Answers

How to find a set of three or more number?

Can you please help me find a set of three numbers og more with a sum of X in a given list. Fx a set of tree numbers with a sum of 6 in the list 1,2,3,4,5,6,7,8,9 would be 1+2+3 I can do this with a set of two numbers se VBA code below Function Se...
more »

2017-06-05 10:06 (1) Answers

When to use a certain search algorithm?

There are several search algorithms that have been used extensively in Computer Science for a variety of purposes (, but I have found there is not a succint "cheat sheet" of the pro's and con's of each a...
more »

2017-06-03 23:06 (0) Answers

C program to convert Decimal to Binary

I've written a program in C to convert Decimal numbers to Binary and store it in a string. The issue is not the binary that's printed in reverse but how the output is displayed #include <stdio.h> #include <string.h> #include <stdlib.h...
more »

2017-06-02 15:06 (2) Answers

SPOJ Swift - NZEC probem

Hello i have problem with SPOJ, in all of my solution i had NZEC problem. I have read that is problem (non-zero exit code). SPOJ link: And my code below: for i in 1...100000{ let number = Int(readLine()!)! ...
more »

2017-06-02 11:06 (2) Answers

Greatest Prime Factor

I'm trying to complete an algorithm challenge to find the largest prime factor of 600851475143. I'm not necessarily asking for the answer. Just trying to figure out why this code isn't working. Why does it return 'undefined' instead of a number? let...
more »

2017-05-28 10:05 (2) Answers