Questions tagged [algorithm]
An algorithm is a sequence of well-defined steps that define an abstract solution to a problem. Use this tag when your issue is related to algorithm design.
5,087 questions
5votes
2answers
439views
Single Consumer Single Producer Wait-Free Zero-Copy Circular Message Queue
The title describes pretty well what the algorithm is for. It will be used for a realtime inter-process communication library that only uses shared memory for exchanging data. For realtime systems, it'...
4votes
4answers
463views
Finding Special Parts in a Word
Task description: Imagine you have a long word made up of small letters like "a", "b", "c", ancd so on. Let’s call this word a puzzle word. We want to look at all the ...
4votes
1answer
82views
Efficient way to win points in chocolate bowl game
I'm working on an optimization problem involving a turn-based chocolate-sharing game, and I need help optimizing my current brute-force solution. Problem Description: You and your friend take turns ...
2votes
0answers
74views
backward induction algorithm computation
Is there a way to significantly speed-up this code? I'm solving a dynamic programming model using a backward induction algorithm. A crucial step is to calculate the current-period value function (VF), ...
7votes
1answer
210views
bilateral_filter Template Function Implementation for Image in C++
This is a follow-up question for An Updated Multi-dimensional Image Data Structure with Variadic Template Functions in C++. Bilateral filter is implemented in this post. By Wikipedia, the bilateral ...
2votes
0answers
134views
How to make this arbitrary precision π calculator using Machin-like formula run faster?
Two days ago (or yesterday depending on your timezone) was π-day. So I thought it was a good day to calculate π. I used Machin-like formula to calculate π, in homage of William Shanks, who calculated ...
5votes
4answers
477views
Count number of substrings in less time
Given an input string contains letters from 'a' to 'g' Count how many substrings are there in the input string such that frequency of any character inside the substring is not more than the number of ...
4votes
1answer
133views
otsu_threshold Template Function Implementation for Image in C++
This is a follow-up question for An Updated Multi-dimensional Image Data Structure with Variadic Template Functions in C++, histogram Template Function Implementation for Image in C++, Histogram of ...
4votes
2answers
520views
Simple Java program to aggregate lines of a text file
I have just written a small application to aggregate the lines of a text file, for example to group the lines according to the frequency of IP addresses in a log file. Would the code be sufficiently ...
6votes
3answers
786views
Collision detection of two rects with rounded borders
I wrote an algorithm how to detect the collision detection of two rects with rounded borders (the code was written using TypeScript but I tried to name things as clear as possible to code be readable ...
3votes
1answer
83views
Depth-first ListIterator over JTree
I wrote a depth-first ListIterator for JTrees. Considerations: It must be a ListIterator, ...
13votes
5answers
2kviews
solve n*m matrix processing in less time
I want to solve a problem in less time complexity. Here are the details: Given an n*m matrix, n rows and m columns. Initially, the matrix is empty filled with 0s. ...
9votes
2answers
1kviews
"Weird Algorithm" (Collatz) from CSES Problem Set
I had to solve the following problem: Consider an algorithm that takes as input a positive integer n. If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by ...
4votes
1answer
132views
Fuzzy search in C#
I was asked to implement a FuzzySearch class in a C# project with the ability to change the degree of fuzziness. It is to be used in a clinical setting where we get names with different linguistic ...
3votes
1answer
97views
Swift Arrays: Write a rotate-right function
Task: Write a function which rotates all elements of a given array to the right. Example: [1, 2, 3] => [3, 1, 2] My solution: ...