Skip to main content

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.

Filter by
Sorted by
Tagged with
5 votes
1 answer
463 views

Intro (See the version A Java program for compressing/decompressing files via Huffman algorithms (version 1.1.1).) (The full repository is here. It contains also some unit tests that do not fit in ...
coderodde's user avatar
  • 32.3k
2 votes
1 answer
146 views

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 ...
coderodde's user avatar
  • 32.3k
4 votes
2 answers
357 views

(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 ...
coderodde's user avatar
  • 32.3k
2 votes
3 answers
1k views

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 ...
Jared McCarthy's user avatar
4 votes
3 answers
482 views

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 ...
coderodde's user avatar
  • 32.3k
2 votes
2 answers
256 views

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 ...
coderodde's user avatar
  • 32.3k
5 votes
1 answer
532 views

(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, ...
coderodde's user avatar
  • 32.3k
2 votes
1 answer
152 views

Intro This time, I have implemented the Shannon-Fano coding. Code io.github.coderodde.compression.ShannonFanoEncoder.java ...
coderodde's user avatar
  • 32.3k
1 vote
1 answer
111 views

(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....
coderodde's user avatar
  • 32.3k
4 votes
2 answers
509 views

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 (...
Jared McCarthy's user avatar
5 votes
2 answers
365 views

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 ...
LazyCauchPotato's user avatar
4 votes
1 answer
92 views

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 \...
coderodde's user avatar
  • 32.3k
7 votes
4 answers
686 views

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 ...
LazyCauchPotato's user avatar
0 votes
1 answer
88 views

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 ...
coderodde's user avatar
  • 32.3k
4 votes
2 answers
144 views

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)\$...
coderodde's user avatar
  • 32.3k
5 votes
5 answers
1k views

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 ...
Jared McCarthy's user avatar
8 votes
2 answers
306 views

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 ...
Pangi's user avatar
  • 370
5 votes
2 answers
418 views

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: ...
coderodde's user avatar
  • 32.3k
0 votes
0 answers
62 views

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\$ ...
coderodde's user avatar
  • 32.3k
4 votes
1 answer
291 views

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\$ ...
coderodde's user avatar
  • 32.3k
1 vote
0 answers
64 views

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 ...
coderodde's user avatar
  • 32.3k
2 votes
2 answers
119 views

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 ...
coderodde's user avatar
  • 32.3k
7 votes
1 answer
882 views

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 ...
Viliam Holly's user avatar
4 votes
1 answer
137 views

Intro I am currently working on this project (PathFinding.java). This time, I need to get the following class reviewed: Code ...
coderodde's user avatar
  • 32.3k
3 votes
1 answer
139 views

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 ...
ayaan098's user avatar
  • 125
4 votes
3 answers
452 views

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 ...
Stony's user avatar
  • 107
5 votes
3 answers
570 views

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 ...
Stony's user avatar
  • 107
5 votes
2 answers
409 views

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 ...
Aya Noaman's user avatar
2 votes
1 answer
128 views

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. ...
michael.zech's user avatar
  • 5,042
11 votes
3 answers
1k views

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 ...
darksun's user avatar
1 vote
0 answers
65 views

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 ...
Pritish Nayak's user avatar
0 votes
0 answers
18 views

I ported C++ implementation of Lempel method for constructing Costas arrays to Mathematica. How to fix my code? Thanks in advance. ...
138 Aspen's user avatar
  • 469
6 votes
3 answers
764 views

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 ...
turral's user avatar
  • 127
1 vote
0 answers
71 views

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 ...
coderodde's user avatar
  • 32.3k
2 votes
0 answers
56 views

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 ...
138 Aspen's user avatar
  • 469
2 votes
0 answers
34 views

I ported C++ implementation of Welch method for constructing Costas arrays to Mathematica. Any feedback would be appreciated. ...
138 Aspen's user avatar
  • 469
5 votes
3 answers
1k views

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 ...
toolic's user avatar
  • 16.4k
1 vote
0 answers
40 views

Intro I have this GitHub repository containing some iterative deepening pathfinding algorithms. Code ...
coderodde's user avatar
  • 32.3k
4 votes
0 answers
85 views

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 ...
Rohit Tanwar's user avatar
8 votes
5 answers
2k views

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 ...
Xavier Pedraza's user avatar
5 votes
2 answers
102 views

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 ...
dawnandrew100's user avatar
4 votes
2 answers
254 views

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: ...
michael.zech's user avatar
  • 5,042
7 votes
3 answers
582 views

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. ...
tomi bell's user avatar
5 votes
2 answers
162 views

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-...
JimmyHu's user avatar
  • 7,575
2 votes
1 answer
217 views

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 ...
mindoverflow's user avatar
6 votes
2 answers
569 views

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. ...
User192837's user avatar
3 votes
1 answer
86 views

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 ...
tomka700's user avatar
  • 203
5 votes
4 answers
679 views

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'...
mausys's user avatar
  • 199
4 votes
3 answers
570 views

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 ...
CodeCrusader's user avatar
4 votes
1 answer
119 views

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 ...
CodeCrusader's user avatar

1
2 3 4 5
103