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
5
votes
3
answers
471
views
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'...
4
votes
4
answers
499
views
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 ...
4
votes
1
answer
87
views
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 ...
2
votes
0
answers
74
views
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), ...
7
votes
1
answer
210
views
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 ...
2
votes
0
answers
134
views
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 ...
5
votes
4
answers
477
views
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 ...
4
votes
1
answer
133
views
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 ...
4
votes
2
answers
520
views
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 ...
6
votes
3
answers
786
views
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 ...
3
votes
1
answer
83
views
Depth-first ListIterator over JTree
I wrote a depth-first ListIterator for JTrees.
Considerations:
It must be a ListIterator, ...
13
votes
5
answers
2k
views
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.
...
9
votes
2
answers
1k
views
"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 ...
4
votes
1
answer
134
views
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 ...
3
votes
1
answer
97
views
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:
...