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,128 questions
5
votes
1
answer
380
views
A Java program for compressing/decompressing files via Huffman algorithms
Intro
(The full repository is here. It contains also some unit tests that do not fit in this post due to size limits.)
I am making my very first steps in data compression, and so, decided to practice ...
2
votes
1
answer
117
views
Huffman code builder in Java - computing prefix codes for arbitrary (generic) alphabets - Take II
Intro
(This is the continuation of HuffmannEncoder.java - computing prefix codes for arbitrary (generic) alphabets.)
(See the GitHub repository.)
This time:
I have fixed the misspelled ...
4
votes
2
answers
342
views
HuffmannEncoder.java - computing prefix codes for arbitrary (generic) alphabets
(See the continuation of this post at HuffmanEncoder.java - computing prefix codes for arbitrary (generic) alphabets - Take II.)
I have this Java implementation of the Huffmann encoding. It looks like ...
2
votes
3
answers
1k
views
LeetCode 3542: Minimum Operations to Convert All Elements to Zero
I am working on this LeetCode problem where I have to count the minimum number of operations to make all elements in an array equal to zero 3542. Minimum Operations to Convert All Elements to Zero
...
4
votes
3
answers
469
views
A simple method for compressing white space in text (Java) - Take II
Intro
In this post, I will elaborate on A simple method for compressing white space in text (Java). Here, I have incorporated some advice offered by Chris. Also, this version preserves a single new ...
2
votes
2
answers
252
views
Benchmarking in Java some super linearithmic sorting algorithms
Intro
A sort is called super linearithmic if its running time is \$\omega(N \log N)\$. For example, \$f(N) = \omega(g(N))\$ means that \$f(N)\$ grows "faster" than \$g(N)\$. In this post, I ...
5
votes
1
answer
525
views
A simple method for compressing white space in text (Java)
(The story continues in A simple method for compressing white space in text (Java) - Take II.)
Intro
Now I have that text space compressor. For example,
...
2
votes
1
answer
147
views
ShannonFanoEncoder.java - computing prefix codes in Java
Intro
This time, I have implemented the Shannon-Fano coding.
Code
io.github.coderodde.compression.ShannonFanoEncoder.java
...
1
vote
1
answer
110
views
Jump point search in Java for faster pathfinding in grid mazes
(Refer to the entire repository in GitHub.)
How it looks like
Intro
This time, I present my take on Jump point search that I translated from Javascript (PathFinding.js/src/finders/JumpPointFinderBase....
4
votes
2
answers
506
views
Finding a sequence of xors to change a to b
I'm resolving a problem from CodeForces: C. Beautiful XOR. This is what the code is supposed to do:
You have two numbers a and b.
You must transform a into b using XOR operations (...
5
votes
2
answers
362
views
BRESort - Bitwise Relationship Extraction - Intelligent Adaptive Sorting Engine for 32/64-bit & Floating-Point Data
I want to begin by sincerely thanking the community for the invaluable feedback on my previous BRESort byte-sorting research. Your insights about enums, named constants, loop optimizations, and test ...
4
votes
1
answer
91
views
Dijkstra's algorithm for non-uniform undirected hypergraphs: Take II - bidirectional Dijkstra's algorithm with excellent performance
Intro
(See the full repository here.)
A non-uniform undirected hypergraph is a generalization of an undirected graph. It is defined as \$H = (X, E)\$, where \$X\$ is the set of vertices and \$E \...
7
votes
4
answers
675
views
My BRESort adaptive sorting engine in C
I've created BRESort - an adaptive sorting engine that dynamically selects
optimal algorithms based on data patterns. It achieves 3.6-4.2x speedup over stdlib qsort ...
0
votes
1
answer
82
views
Computing loan cuts leading to a global zero equity in a financial graph (Java)
Intro
I won't specify the problem here, but instead, provide the link to the blog post discussing the problem and the full implementation.
Code
...
4
votes
2
answers
142
views
Dijkstra's algorithm for non-uniform undirected hypergraphs
Intro
(Repo here.)
A non-uniform undirected hypergraph is a generalization of an undirected graph. It is defined as \$H = (X, E)\$, where \$X\$ is the set of vertices and \$E \subseteq \mathcal{P}(X)\$...
5
votes
5
answers
1k
views
Check whether a binary tree is symmetric
I implemented a recursive solution that compares the left and right subtree in mirrored fashion. It works for my test cases, but I would like to know if there are any best practices that would make ...
8
votes
2
answers
301
views
Implementation of a kd-tree header-only library
I've took inspiration from https://www.geeksforgeeks.org/cpp/kd-trees-in-cpp/ and implemented a kdtree library and I would like to get a review of it. The main target was to have a kd-tree ...
5
votes
2
answers
418
views
Ordinary insertion sort vs. straight insertion sort in Java (benchmark)
Intro
So this time I wanted to find out which of the two insertion sort flavours are faster:
Code
io.github.coderodde.util.StraightInsertionSort.java:
...
0
votes
0
answers
60
views
Computing \$k\$ most reliable paths in undirected probabilistic graphs in Java
Intro
(See MostProbablePath.java.)
This time, I elaborate on Computing most probable (reliable) path in a probabilistic graph (take II): instead of computing the most reliable path I now return \$k\$ ...
4
votes
1
answer
286
views
Computing most probable (reliable) path in a probabilistic graph (take II)
Intro
A probabilistic graph \$G = (V, E)\$ is an undirected graph with weight function \$w \colon E \rightarrow [0, 1]\$. In the most reliable path problem we -- given two terminal nodes \$s \in V\$ ...
1
vote
0
answers
64
views
PathFinding.java: Drawing a random perfect maze via randomized DFS
Intro
Still working on PathFinding.java. This time I concentrate on three private methods of GridModel that are responsible for generating random perfect mazes. A maze is perfect if for each two cells ...
2
votes
2
answers
106
views
Checking for weak string isomorphism in Java
Intro
I call two \$n\$-strings \$s\$ and \$z\$ over the alphabet \$\Sigma\$ weakly isomorphic if their character frequency multisets are equal. In other words, for an input strings \$s\$, we derive a ...
7
votes
1
answer
878
views
Move generation in my C++ chess engine [closed]
I am building a chess engine in C++ and currently working on the move generation. To measure performance I use perft, but my main goal is to make the move generator itself faster.
I already use ...
4
votes
1
answer
137
views
PathFinding.java: Beam search in Java
Intro
I am currently working on this project (PathFinding.java). This time, I need to get the following class reviewed:
Code
...
3
votes
1
answer
138
views
Calculate optimal game upgrades, v3
This is the third iteration of the code from Calculate optimal game upgrades, v2 and Calculate optimal game upgrades. I'm looking for suggestions to further optimize this code. A brief summary of the ...
4
votes
3
answers
447
views
FOLLOW-UP to the Strength of a Pyramid Top post with a revised code example
As a follow-up to my previous question, I've decided to post a follow-up question with a revised code that accommodates most of the inputs from the previous question's comments, namely:
Used ...
5
votes
3
answers
565
views
Strength of a Pyramid Top
I need to solve the following competitive programming problem from coderun.ru:
Strength of a Pyramid Top
The pyramid consists of n horizontal layers of blocks: the first layer contains n blocks, the ...
5
votes
2
answers
407
views
Wordsearch Generator (Tracking Success/Failure)
I'm creating a wordsearch generator that takes a list of words and outputs a 10x10 grid (2D array) of letters. This is roughly how it works:
loop over words
use boolean ...
2
votes
1
answer
128
views
Swift: Find neighbor-elements within an array
I need a function which finds the left and right neighbor-element within an integer-array, based upon a given index. If the given element is 0, then it shall return largest index as left neighbor. ...
11
votes
3
answers
1k
views
Golden-section optimization with complication
I'm trying to implement the so-called golden-section optimization in C++.
This is a simple algorithm to find an extremum of a univariate function \$f\$ within an interval \$[a,b]\$.
The crux is to ...
1
vote
0
answers
65
views
Lock free Leaky Bucket Rate Limiter
I want to validate my solution for a lock-free leaky bucket rate limiter. Given a queuing capacity and rate limit per second, it should queue requests till capacity is reached and it should allow only ...
0
votes
0
answers
18
views
Mathematica implementation of Lempel method for constructing Costas arrays
I ported C++ implementation of Lempel method for constructing Costas arrays to Mathematica.
How to fix my code? Thanks in advance.
...
6
votes
3
answers
762
views
N queen problem-like (+rooks and a different goal)
The problem is:
You have Q queens and R rooks on a board with sides of length (R+Q) ≤ 8, and you have to place all the pieces so that none attack any other piece. Each square on the board has a score ...
1
vote
0
answers
71
views
Fixed BIDDFS (bidirectional iterative deepening depth first search) in Java
Intro
I have this GitHub repository for doing pathfinding in directed unweighted graphs. This post is about BIDDFS proposed by Richard Korf in his paper.
Code
...
2
votes
0
answers
56
views
Use Mathematica to calculate Treewidth
The treewidth is a measure of the count of original graph vertices mapped onto any tree vertex in an optimal tree decomposition.
I wrote Mathematica code to calculate Treewidth
based on the Python ...
2
votes
0
answers
34
views
Mathematica implementation of Welch method for constructing Costas arrays
I ported C++ implementation of Welch method for constructing Costas arrays to Mathematica.
Any feedback would be appreciated.
...
5
votes
3
answers
1k
views
Project Euler Problem #1: Multiples of 3 or 5
Project Euler Problem #1
Multiples of 3 or 5 states:
If we list all the natural numbers below 10 that are multiples of 3 or
5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of ...
1
vote
0
answers
40
views
LibID: a Java library containing some iterative deepening algorithms for pathfinding on directed unweighted graphs
Intro
I have this GitHub repository containing some iterative deepening pathfinding algorithms.
Code
...
4
votes
0
answers
85
views
SHA1 Algorithm Implementation in Zig
I have implemented the SHA1 algorithm in Zig, as a learning exercise, to teach myself both Zig and the actual algorithm behind SHA1. Now the second part I think I understood well enough. The ...
8
votes
5
answers
2k
views
C method to determine whether a byte array is homogeneous
I engineered myself into a situation where I wanted to check whether a region of memory consists of identical bytes. I wanted to at least try to avoid the obvious solution of an O(n) loop, but also ...
5
votes
2
answers
102
views
Calculate distance score for local alignments (ex. Gotoh local)
Is there a better way to calculate distance scores for local alignment than this? Or is the method that I'm currently using robust enough? The full code is here with the actual alignment ...
4
votes
2
answers
253
views
Ruby Array#own_shuffle method
I have tried to implement the Array-shuffle method myself. Haven't had a look on some similar algorithm-examples by purpose and tried to figure out something myself.
The actual Array-extension:
...
7
votes
3
answers
580
views
Team picker command line application
I've made a program for randomly splitting game participants into different teams. The code works and solves the problem. I'm interested in advice on what you'd do differently or better.
...
5
votes
2
answers
153
views
N-dimensional 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++ and bilateral_filter Template Function Implementation for Image in C++. The N-...
2
votes
1
answer
217
views
Attempt at a Different Variation of the strstr(...) Function
I decided to work on an idea I had to 'optimize' the classic C function strstr.
Most of the implementations I had seen that did not make use of advanced ...
7
votes
2
answers
567
views
Subtracting the sum of the current digits from a positive integer N until it reaches 0
Given a positive integer N, subtract the sum of its digits and count how many times this operation must be applied to make N become 0.
...
3
votes
1
answer
86
views
More shortest unrestricted paths to touch every square in an n by n grid
This is a part two.
The problem originates from here,
it is solved for \$n<11\$. A GitHub repository for this code, printing paths, and a collection of all proven best paths, it is open to ...
5
votes
4
answers
677
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
3
answers
570
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
119
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 ...