121,484 questions
Advice
0
votes
4
replies
73
views
Finding substrings from the string using sets: algorithm's logic
I was solving the algorithm problem: find all unique substrings from the string, using sets.
Here is the model solution, but I can't understand what line 6 means. Why does the end go up to length + 1? ...
Advice
0
votes
4
replies
74
views
Possible solution to prime numbers
P(n) = sum_{k=0}^{100} [ p_k * product_{j=0, jâ k}^{100} (n - j)/(k - j) ] this is called a polynomial interpolation formula which gives a streak of 100 prime numbers higher than Euler's n²+n+41 which ...
4
votes
1
answer
246
views
How can one algorithm add the same fractions faster than another one in the same environment?
I need to add many fractions together. I don't use float because IEEE-754 Double Precision Floating Point has only 53 bits for mantissa thus 53 * log10(2) = 15.954589770191003 accurate decimal digits.
...
Best practices
2
votes
7
replies
141
views
How to add many fractions together as fast as possible?
This is related to this question.
Basically, I need to add many fractions together. Seems simple enough? Except it isn't simple.
I can't use fractions.Fraction class, that thing stupidly does fraction ...
9
votes
2
answers
331
views
Function object returning the nth item of a tuple
With std::ranges::max, it is possible to use a projection as follows
std::vector<std::tuple<char,int,double>> v = {
{'a',2,1.0}, {'c',1,3.0}, {'b',4,2.0}, {'d',3,4.0}
};
auto m = std::...
Advice
0
votes
7
replies
71
views
Find an explicit criterion about a specific class of integer sequences expressed by a recursive predicate
Let a "branching" operation be an operation that, given a finite sequence of integers, increments and duplicates one element in place. For example:
(3,1,4,1,7) â (3,1,5,5,1,7)
A tree ...
Advice
0
votes
31
replies
252
views
I made a simple collision-detection algorithm, can you take a look at it?
Unlike conventional collision detection algorithms (using right-angled triangles), I created an algorithm using the theta value with objects. (Theory, etc., got a little help from the Gemini, but I ...
Best practices
0
votes
8
replies
73
views
How to estimate subâsample peak positions for very sharp periodic peaks with few cycles?
I have a sampled 1D signal that contains very sharp periodic peaks. The peaks are narrower than the sampling resolution, and the lower part of the signal contains noise.
The goal is to estimate the ...
10
votes
1
answer
641
views
Is the brute-force solution for "Is Binary Tree Balanced" really O(n^2) with early exit?
Iâm looking at the classic âis binary tree balancedâ problem (LeetCode 110 style):
Given a binary tree, determine if it is height-balanced.
A binary tree is height-balanced if for every node, the ...
4
votes
1
answer
98
views
DFS Algorithm for undirected graph
I am studying Depth First Search (DFS) on undirected graphs and I am confused about discovery order.
I have attached a figure of an undirected graph with DFS discovery (d) and finishing (f) times ...
1
vote
1
answer
214
views
Can arbitrary precision integer increment in Brainfuck be done in O(1) code size?
I was fiddling with the Brainfuck esolang over the past few days, and tried to implement an increment operation on an N-byte-wide integer in big-endian format. Note that I am imposing a structural ...
0
votes
0
answers
56
views
deleting a node from a red black tree
I have been following the Cormen algorithm for RB trees, but I have a question regarding deletion, specially in this case:
38
31 41
all the nodes are black and I want to delete 38. After ...
0
votes
1
answer
138
views
How to calculate the points on the "perimeter" on a bitmask?
I am making a drawing application and i have to show the borders of the pencil. To know where to place the pixels I use a list of integer offsets from the cursor that make up a shape, so the cursor is ...
Tooling
0
votes
11
replies
122
views
Filtering an inconsistent string
I'm working on a project in which I need to filter out specific strings from an inconsistent API, where the strings are not always what I want. I need to filter out eligibility for different education ...
Advice
2
votes
3
replies
57
views
How does DP provide optimization over backtracking in 0-1 Knapsack problem
0-1 Knapsack problem is often used as a starting problem to understand dynamic programming. This problem can also be solved using backtracking. Now, backtracking explores all possible subsets and uses ...