Category "algorithm"

Infected Fish can eat another fish having size less that its own. Minimum number of operation required

An evil scientist has developed an injection that induces insatiable hunger in a fish. On giving this injection, a fish of size x can eat another fish of smalle

My check for whether a graph is a Binary Tree always returns false

I have this question that is medium level and couldn't even think on how to solve this problem, my solution could be overkill as I have no idea on how to traver

Algorithm to return all combinations of 3 combinations from a array of length 6 without the number appearing with the same set of numbers

I was trying to write a algorithm in javascript that returns all the possible 3 digit numbers numbers from a given array of length 6 For Example var arr = [1, 2

Merging overlapping axis-aligned rectangles

I have a set of axis aligned rectangles. When two rectangles overlap (partly or completely), they shall be merged into their common bounding box. This process w

Is there a solution to the TSP problem that is effective and not limited to space?

Is there any method of solving the traveling salesman problem effective and that is not limited by space (as is the case of the Held-Karp algorithm), excepting

Merging 4 sorted Arrays into one

I have this method to merge 2 sorted arrays into one sorted array: public void merge(T[] a, int l1, int r1, T[] b, int l2, int r2, T[] c, int l3) {

Determine if relation is in BCNF form?

How do I determine if the following relation is in BCNF form? R(U,V,W,X,Y,Z) UVW ->X VW -> YU VWY ->Z I understand that for a functional dependency A

What is the time complexity of while loops?

I'm trying to find the time complexity of while loops and I have no idea where to begin. I understand how to find the complexity class of for loops, but when it

'int' object is not subscriptable?

I'm doing an algorithm challenge on www.edabit.com, where you have a list of dice rolls, and: if the number is 6, the next number on the list is amplified by a

Javascript twoSum algorithm: Given an array of integers, return indices of the two numbers such that they add up to a specific target

Given an array of integers, return indices of the two numbers such that they add up to a specific target. Example: Given nums = [3, 2, 4], target = 6, Because

Recursive and Iterative Binary Search: Which one is more efficient and why?

I have written the algorithms for recursive and iterative binary search: Recursive AlgorithmBinSrch(a, i,l,x) // Given an array a[i :l] of elementsin nondecre

TI-84 Plus Random Number Generator Algorithm

Edit: my main question is that I want to replicate the TI-84 plus RNG algorithm on my computer, so I can write it in a language like Javascript or Lua, to test

algorithm to merge two arrays into an array of all possible combinations

Example given in JavaScript: Suppose we have two arrays [0,0,0] and [1,1,1]. What's the algorithm to produce all possible ways these two arrays can be combine.

Check if a permutation of a string can become a palindrome

Write a method to test if a string meets the preconditions to become a palindrome. Eg: Input | Output mmo | True yakak | True travel |

Javascript - Generating all combinations of elements in a single array (in pairs)

I've seen several similar questions about how to generate all possible combinations of elements in an array. But I'm having a very hard time figuring out how to

Why the insertion sort is slower than selection sort?

The code for selection sort in Java: public class Selection { public static void sort(Comparable[] a) { int n = a.length; for (int i = 0; i

Finding union of 2 sorted arrays (with duplicates)

I'm trying to find the union of 2 sorted arrays (with duplicates) but I feel I'm not coming up with the most elegant code (what I have works btw, I just feel I

Python Connected Components edges list

I use these algorithms in python for finding connected components from edges. components = [] def connected_components(pairs): for a, b in pairs:

Neighboring gray-level dependence matrix (NGLDM) in MATLAB

I would like to calculate a couple of texture features (namely: small/ large number emphasis, number non-uniformity, second moment and entropy). Those can be co

Bilinear interpolation with non-aligned input points

I have a non-grid-aligned set of input values associated with grid-aligned output values. Given a new input value I want to find the output:     &nbs