# Algorithm Questions

## Selecting best data structure for a 2-dimensional map that will shift the data

I need some help in the ways of implementing a faster way to do a full shift on a two-dimensional array. my problem is i have a 2

## What are the characteristics of an Abelian Sandpiles for a grid 3 x 3?

I have a c project which involves abelian sandpiles. the issue is, after a few days of research, i am still struggling to understand the

## Algorithm to randomly generate an aesthetically-pleasing color palette

I'm looking for a simple algorithm to generate a large number of random, aesthetically pleasing colors. so no crazy neon colors, colors

## CS50 Credit Problem is skipping "else if" part

I am really stuck here. the programm gives right answer to invald credit card numbers but never say if its visa, amex or mastercard. i need

## Good refresher course on 'O(N)' type stuff?

Learned all about computing algorithm costs in college, but that was so long ago i forgot it all. is there any sort of walkthrough that goes over

This is an

## How to split a string into words. Ex: "stringintowords" -> "String Into Words"?

What is the right way to split a string into words ? (string doesn't contain any spaces or punctuation marks) for example:

## Finding common blocks

I have two files (f1 and f2) containing some text (or binary data). how can i quickly find common blocks? e.g. f1: abc def f2:

## Algorithm to find a common multiplier to convert decimal numbers to whole numbers

I have an array of numbers that potentially have up to 8 decimal places and i need to find the smallest common number i can multiply them by so

## Meta-composition during music performances

A couple of weeks ago, my piano teacher and i were bouncing ideas off of each other concerning meta-composing music software. the idea was

## Looking for evolutionary music example code

I would like to implement an interactive evolutionary algorithm for generating music (probably just simple melodies to start with). i'd

## A good reference card / cheat sheet with the basic sort algorithms in C?

I've been looking (without great luck) for the perfect reference card with all the basic sorting algos in c (or maybe in pseudo code). wikipedia

## How do you detect Credit card type based on number?

I'm trying to figure out how to detect the type of credit card based purely on its number. does anyone know of a definitive, reliable way to find

## Looking for algorithm that reverses the sprintf() function output

I am working on a project that requires the parsing of log files. i am looking for a fast algorithm that would take groups messages like this:

## How to calculate the first n even integers?

So i am having a hard time calculating the first n even integers, n is the amount of number(s) so an example would be like calculate the first 10

## How to get scientific results from non-experimental data (datamining?)

i want to obtain maximum performance out of a process with many variables, many of which cannot be controlled. i cannot run

## What is this sorting algorithm? And is there a more efficient way?

I wrote this algorithm while learning about o(n) algorithms, and after the last

## What is this sorting algorithm?

I happened to write a simple sorting algorithm, but i am not sure what this algorithm is called. #include<stdio.h>

## Displaying the output of a sorted array causes problem

I tried applying bubble sort algorithm to an array of values. i have 5000 values in my input, from 1 to 5000. i imported values from a text

## hackerrank solution in c for "Array Manipulation"

Long arraymanipulation(int n, int queries_rows, int queries_columns, int** queries) { long num, a,

## Information on L-Systems

I am about to start a project for university to build a procedural city for a pre existing project. i was wondering if any of you have had

## Algorithm for Fogbugz pricing scheme

I'm looking for an algorithm to calculate total cost of licenses purchased based on the "fogbugz for your server" pricing scheme

## Fastest way to check if a list of sets has any containment relationship

I hava a list of 10,000 random sets with different lengths: import random random.seed(99) lst = [set(random.sample(range(1,

## Fastest way to find 4-connected regions

I have a 2d numpy array filled with values in range [0,1] and i want to loop on the 4-connected region where value < 0.2. in order

## Theoretical - Fastest way to compute different counts

I would like to know how experienced sql users would compute a lot of counts with different conditions. i have a table [population] and a table

## Fastest way to "sort" bit sequence by toggling bits

Given a finite random sequence of bits, how can the minimum number of bit toggles necessary to result in a sorted sequence (i.e. any and all 0's

## Fastest way to determine a boolean value based on other boolean values

Isoccupied and vacant are two keys that are destructured out of a document const { isoccupied, vacant } = doc || {};

## Best way to retrieve K largest elements from large unsorted arrays?

I recently had a coding test during an interview. i was told: there is a large unsorted array of one million

## How to do unsigned saturating addition in C?

What is the best (cleanest, most efficient) way to write saturating addition in c? the function or macro should add two unsigned inputs

## What are the core mathematical concepts a good developer should know?

Since graduating from a very small school in 2006 with a badly shaped & outdated program (i'm a foreigner & didn't know any better school

## Two marbles and a 100 story building

One of those classic programming interview questions... you are given two marbles, and told that they will break when dropped from some

## Optimizing a search algorithm in C

Can the performance of this sequential search algorithm (taken from

## multiplication chains that result in a constant modulo a power of 2

Is there a practical algorithm that gives "multiplication chains" to clarify, the goal is to produce a multiplication change of an

## Constant Amortized Time

What is meant by "constant amortized time" when talking about time complexity of an algorithm?

## How to pick color palette for a pie-chart?

I have some code that generates image of a pie chart. it's a general purpose class, so any number of slices can be given as input. now i have

## Graph (Chart) Algorithm

Does anyone have a decent algorithm for calculating axis minima and maxima? when creating a chart for a given set of data items, i'd like

## Generating all set of permutations

Recently in an interview, i was asked the following question: given a list of pairs of numbers, like (2, 6)(4, 5)(1,

## How to come up with a normal solution to the problem of brute force?

I came across an interesting problem. the input is a number from 1..n, where n <= 10^9. so you need to make a prime number out of it by

## I can't figure out how this loop not breaking and give the right value. It just keeps adding up

code to bring copy the unique value from array a to b. and return the number of unique value which is the number of element in b

## Algorithmic complexity of XML parsers/validators

I need to know how the performance of different xml tools (parsers, validators, xpath expression evaluators, etc) is affected by the size and

## What's the fastest way in Perl to get all lines of file1 that do not appear in file2?

I have two (very large) text files. what is the fastest way - in terms of run time - to create a third file containing all lines of file1 that do

## How can i sort array of objects based on numbers and spefific letters?

I have this array let arr = [ { "time": "3", "wholeobj": "abc mo sa 3

## Algorithm for shortening a series of actions?

It's been awhile since my algorithms class in school, so forgive me if my terminology is not exact. i have a series of actions that, when

## data maping facing issue to conver data given below

Hi everyone i have data given below nodes data var nodes=[ { name:'shanu', value:5 }, {

## Reorganization and cleaning of a 'treeview' JSON object

I want to create a javascript method that transforms a json ‘treeview’ object. my starting object has a structure with duplicated

## How can I make a set of numbers that increase every 30 seconds to line up in an ascending order?

If you run this javascript code below, var i = 20220215155; function increment(){ i++;

## Comparing two string using XOR return true but the strings are different

I'm testing some ways to identify anagrams and i found a situation that got me off guard. i found out that it's possible to do using xor so i was

## Result from audio FFT function makes it near impossible to inspect low/mid frequencies

I am trying to build a graphical audio spectrum analyzer on linux. i run an fft function on each buffer of pcm samples/frames fed to the audio

## Find the longest most common items in multiple lists (not substring)

Let's say we have a list of n lists. for example: l = [['a','b','c','d','e'], ['a','b','c'],['b','c','d'],['c','d'],['a','c','d']]

## Algorithm for integer solutions of a circle?

I am trying to search for integer solutions to the equation: y^2 + x^2 = 2n^2 if i search this in wolfram alpha,

## Fastest way to "reduce" nested array to object with keys + fastest way to find by key

I need to transform this type of nested array to be able to search by key (id) fastest way possible: [ { "id":1,

## Formatting JSON data for Tree Graph

I have a json array of the following format (this data is pulled from mongodb to be displayed as a tree graph on a react-based front-end):

## Validate combination of dice

I am buidling an app called thirty throws in android and i am completely stuck with my validation. in thirty throws you have the scores 4, 5, 6

## Algorithm to create a binary-like pattern

I have two numbers: n and sp. i want to create a pattern of list elements with sp elements that rotate like

## C# : is there an appropriate collection for fast range-related search?

I have data like that: time(seconds from start) value

## Tag based clustering with overlaps (soft clustering)

I am looking for an algorithm to cluster twitter feeds based on their hashtags, where hashtags would not be strictly assigned only to one

## Generating seemingly random looking unique numbers for url purposes

So i was wondering about youtube's url. specially the video id watch?v=xzmggabhqa0. same for similar tinyurl services. i came

## Find the longest parent-child chain in a dataframe

Scenario i have a dataframe. each row contains an item, which can be but not necessarily linked with a parent item or a

## Find number of groups, that can be formed from two lists

Goal of task is to group animals, so the enemies not in the same cage. there are m pairs (a[i],b[i]) which imply that animals a[i] and b[i] are

## Avoid synonyms in an array generated via AutoTag (Text Tagging Algorithm)

I have been working on a text analysis task. where i am supposed to identify the words used most in a paragraph. i am using algorithmia -

## increment the duplicate value of object in any array of objects in java script

I have a 5 age fields where user can enter same value they are not validating while sending to the api. i have to increment the duplicate ages

## Use Recursion to Create a CountdownPassed (JS Algorithm)

Question we have defined a function called countdown with one parameter (n). the function should use recursion to return

## Arbitrary depth nested loop

How do i turn the following into a recursive function that can accumulate a list of lists in an arbitrary-depth fashion? def

## How to draw squares between an array of points in p5.js?

I have an array containing 6 sets of random x, y coordinates. i'm able to draw lines connecting the points, like this:

## Javascript - Finding distinct properties in array of objects (matrix)

Background: pre-processing code will run on a lot of data to extract the properties that needs to be shown on a chart. the chart is a parallel

## Minimum replacements in a string to make all 'X' chars to the left of all 'Y chars

Hey everyone had this problem in an interview and can't seem to figure out the best way to do it. any help would be much appreciated.

## edit a string by removing characters without creating a new string, is it legit or not?

Edit: i think i've understood how this concept works, this is my code void delete_duplicate(char* str) { if (str == null) {

## Clearing dynamically added input fields

I am creating an app, where users should compose a correct sentence from shuffled one. like on the following picture. the problem is that i am not

## Python route finder for aviation

I made an app that besides all other things try to find a valid route between 2 airports. i have all the required data in a sqlite3 database witch

## How do I trace all unique paths of 1's in a binary matrix in python?

The goal is to create all paths where each node is visited a single time. a 1 represents a viable route and a 0 represents that no routes

## Leveinshtein and hash - finding one hash algorithm that results in correlation (closer distance)

I am looking for a hash-kind algorithm that does not provide any security but rather a fixed and distinct pattern for a string, in such a way that

## Two Sum Algorithm - Using Find Index - Javascript Algorithm

Question given an array of integers, return indices of the two numbers such that they add up to a specific target.

## Working Magic on Arguments - But only if they are Numbers (Javascript Algorithm)

Question create a function that sums two arguments together. if only one argument is provided, then return a function

## Finding the root elements of a set of elements/nodes in a multiway tree or a connected graph

I have a problem finding a proper algorithm to implement the below: i have a group of wifi links connected as a connected graph or a

## How to set latitude/longitude delta to display routeCoordinates?

I have this map, using react native map i can save the routecoordinates :[{lat,lng},...] to display the lines after.

## Get convex hull indices

I would like to calculate the convex hull of a set of points. most algorithms i've found online return a list of points but i need a list of

## Count the number of subarrays where the selected element is the largest value

We have an array of integers x. the task is to return an array y of the same size, where the ith element in

## Finding minimum weighted matching in sink source graph

I have three lists of nodes. sources, sinks, and pipes. there is a directed weighted graph from sources to pipes to sinks. sources are only

## How could I calculate the distance between the parent and neighbors node when there is a line of sight between two points?

I have completed my astar algorithm in python and now i need to convert it to a theta star algorithm, i have built my line of sight algorithm

## Creating a data structure of integers and finding which component a given integer lies in

I have a set of 32 bit integers with which i will be making a data structure that will put these integers in different components ( like dsu ) the

## B-Spline derivative using de Boor's algorithm

Wikipedia gives us a python implementation for the de boor's algorithm: def deboor(k, x, t, c, p): """ evaluates s(x).

## How to find element in graph?

I have the following entities: form block row cell field root element is

## Algorithm to get items from nested array structure structured around powers of 2

I have some constraints on how an array would be implemented under the hood. there can only be power-of-two contiguous elements up to 32 elements

## How could I distribute obstacles to my grid without writing them manually?

I'm working on a star algorithm and as my code below shown the gird is written manually and i'm thinking to make a grid with 100* 100 size. so, it

## first missing positive integer in an array using javascript?

I am trying to find missing positive integer in an. array.i don't know where my function not working ? question given

## how to tuning parameter entering the layer using for loop?

Here is my code model = sequential() model.add(lstm(128, input_shape=(none, 1),return_sequences=true)) model.add(dropout(0.3)) #i

## Randomly split sorted array into smaller sorted arrays

I have a big sorted array of unique numbers. i do want to split it into n smaller disjoint sorted

## calculating running speed

My problem is a wrong result. i have a function this function has a distance and a time. the result i want to achieve is calculating running

## Least number of stamps needed to pay certain postage

I wrote a c program to solve the stamp and postage problem using brute force. however, it looks really stupid... is there any better algorithms

## Japavascript and P5.js - Optimizing a 4D projection code

I know that "how to optimize this code?" kind of question is generally not welcomed in stack overflow. but i think this is only the way i could

## Detect unique colors in an image visible to eye

Aoa, i am currently working on a project and got stuck.actually i want an algorithm to detect number of colors in an image that are

## How to build a deterministic random plot

I have this interesting problem, a simple but (apparently) not easy one: my server is serving a json containing a random plot, in the

## Creating an array of numbers that add up to 1 with given length

I'm trying to use different weights for my model and i need those weights add up to 1 like this; def func(length): return ['a

I'm trying to create a list of items where there are always 3 displayed per row and when i click on show more button another 3 will be displayed.

## How do I split a list on certain conditions in Haskell?

As a programming exercise i'm trying to build a function in haskell where given a list it splits the list whenever an element is repeated.