Category "algorithm"

Algorithm for drawing profiles using long thin rectangles

I want to draw profiles similar to the ones at https://steeldoor.org like: programmatically. (Probably in FreeSCAD, but possibly Python). I want to define a g

Reduce time in searching a list of strings with Regex

I have 130,000 records of strings. I want to find the number of occurance of each string element in those 130,000 records by doing the regex search for each rec

longest subsequence: missing last element

Hi guys I'm working on the longest subsequence algorithm, the idea is to find the subsequence of numbers from an array. I'm using Ruby, so far I'm missing the l

Big O notation calculation for nested loop

for ( int i = 1; i < n*n*n; i *= n ) { for ( int j = 0; j < n; j += 2 ) { for ( int k = 1; k < n; k *= 3 ) { cout<<k*n;

Runtime complexity of insertion sort for half sorted array and half reversed sorted

Wondering what is the average runtime complexity for half sorted and half reverse sorted array. For example the array: [0,7,2,5,4,3,6,1], number on every even i

How do I correctly memoize this recurrence relation?

I am solving a problem: Given a list of integers nums, write a function that returns the largest sum of non-adjacent numbers. Numbers can be 0 or negative. Fo

How to search nested hash of arrays and arrays of hash and return multiple matching objects from the parent node?

Say I have the below ruby hash nested hash_or_array = [{ "book1" => "buyer1", "book2" => { "book21" => "buyer21", "book22" => ["buyer23", "b

SM2 algorithm, the length of public key encryption is inconsistent with the expectation

The public key encrypts a 48Char data, and the result is arranged according to the format of C1C3C2. C1 (randomly generating a point on the elliptic curve of SM

Find position of all unique elements in array

let arrr = [7, 9, 30, 40, 50, 8, 1, 2, 3, 40, 90,2, 88,1]; output=[0, 1, 2, 3, 4, 5, 6, 7, 8 ,10, 12 ] I saved this code at javascript playgroun

The best algorithms to detect continuing decrease pattern on conversion data

I'm tring to use an algorithm for finding and ranking continuing decreases in my data. The base condition: The breakpoint location (blue arrow) is unknown but b

Spiral Iteration

I need an Algorithm that I will use to scan pixels out from the center. Problem is with different lengths and sizes, it sometimes can't get to the position (See

Printing all the paths in a tree from root to each leaf

I am trying to print all the paths from root to leaf in a tree, but having some issues collecting the path items. Consider the following graph: In my case thou

Tweaking Dijkstra's Algorithm to detect minimum length cycle in directed graph

I am trying to find the minimum length cycle in a directed graph but this time using a greedy algorithm. I think the smartest way to do it is using Dijkstra's A

python: what is a best way to find paths with x length in 2d array?

Assume that I have an array like this [[0, 1, 0, 0], [1, 0, 2, 5], [0, 2, 0, 0], [0, 5, 0, 0]] each index is a node index so [0, 1, 0, 0] means node0 has a edge

How to implement Modular Exponentiation Code

Please I was learning from the book Introduction to algorithm (Chapter 31 page 957) and came across this pseudocode. This pseudocode is how we can implement the

Peak and Trough of Numeric Data

Can anyone help me please. I need to find the peak and troughs in a data series but with 2 conditions which are: Peak or trough is peak for minimum of n(days) L

Find the nth character of an increasing sequence

Recently i saw a competitive coding question, the bruteforce approach doesn't meet the time complexity, Is there any other solution for this, Question: An expan

Latex algorithm cross-column typesetting

How to use latex to implement the multi-column algorithm in the link below, thank you very much. multi-column algorithm

determine if the shortest path in a graph is unique

Say I have a cyclic graph containing bi-directional and parallel edges e.g. Assume all edge weights equal 1. How would I determine if the shortest path is a un

Power of 3 in mod 1000000007

Let k be a positive integer. Is it possible to find out the value of 3^k in mod 1000000007? I have written a C program code to do this but it gives a message on