Category "algorithm"

How to find the winner(s) of Brazil's Mega Sena lottery most efficiently?

Mega Sena is Brazil's most famous lottery. The number set ranges from 1 to 60 and a single bet can contain each from 6 to 15 numbers selected (the more numbers

Map of sets into list of all combinations

I'm stuck with a simple task. What I want to do is to transform Map<K,Set<V>> into the List<Map<K,V>> getting all possible combinations:

Algorithm to find edit distance to all substrings

Given 2 strings s and t. I need to find for each substring in s edit distance(Levenshtein distance) to t. Actually I need to know for each i position in s what

How to simulate velocity in a falling sand game?

I'm creating a falling sand game and would like to implement velocity so elements can travel in different directions at varying speeds. Games such as Noita use

Squares of a Sorted Array, why sorted() method is faster than O(n) method? [closed]

I am working on leetcode algorithm problem 977. Squares of a Sorted Array. Why the submissions using built-in method sorted is faster than my

Sorting 10GB Data in 1 GB memory. How will I do it?

Here is the problem: I have only 1GB RAM in computer. I have a text file of 10 GB data.This file contains numbers. How will I sort them? Adding some more detai

Unable to convert class syntax to function syntax for a Linked List

Okay so I'm learning Data Structures where my tutorial is following class syntax. So now I am trying to convert it to function declarations as I want to practic

Average transformation matrix for a list of transformations

I have multiple estimates for a transformation matrix, from mapping two point clouds to each other via ICP (Iterative Closest Point). How can I generate the av

Algorithm for finding the fewest rectangles to cover a set of rectangles without overlapping

I have a set of rectangles and I would like to "reduce" the set so I have the fewest number of rectangles to describe the same area as the original set. If poss

Why do we check up to the square root of a number to determine if the number is prime?

To test whether a number is prime or not, why do we have to test whether it is divisible only up to the square root of that number?

Using Big O Notation, what is the correct label for this algorithm?

I am curious. What is the correct way to describe this using Big-O Notation? var prices = [100, 180, 260, 590, 40, 310, 535, 10, 5, 3]; var biggest_profit = 0;

Find the closest integer with same weight O(1)

I am solving this problem: The count of ones in binary representation of integer number is called the weight of that number. The following algorithm finds the

Grouping/Bucketing latitude and longitude

This is more of a logical problem than the technical one. So request you guys to please not to flag it. I want to write a method in python, that takes two para

Detecting loops in tree structures (graphs)

I'm writing a library which is configured using a recursive structure. For the sake of this discussion I'm calling these graph structures a "tree" since ther

3-PARTITION problem

here is another dynamic programming question (Vazirani ch6) Consider the following 3-PARTITION problem. Given integers a1...an, we want to determine whether it

How to merge 3 sorted arrays into 1 sorted array in Big-O(N) time?

Trying to merge 3 arrays into one so that the final array is in order. Given int[] a = {1,3}; int[] b = {2,4}; int[] c = {1,5}; Merge the arrays so that t

Algorithm for pow(float, float)

I need an efficent algorithm to do math::power function between two floats, do you have any idea how to do this, (i need the algorithm not to use the function

Determining if a number is prime

I have perused a lot of code on this topic, but most of them produce the numbers that are prime all the way up to the input number. However, I need code which

Quicksort with Python

I am totally new to python and I am trying to implement quicksort in it. Could someone please help me complete my code? I do not know how to concatenate the th

Testing whether a polygon is simple or complex

For a polygon defined as a sequence of (x,y) points, how can I detect whether it is complex or not? A complex polygon has intersections with itself, as shown: