121,484 questions
0
votes
2
answers
39
views
(Shell Sorting) Applying Ciura's gap sequence (or some other optimal sequence formula)
I've been trying to teach myself various sort methods just for the sake of being able to use them in the future and right now I've been teaching myself about shell sorts. I understand the way shell ...
0
votes
0
answers
45
views
How do I properly insert 3 into my nested list tree?
I am working on a program that is supposed to build a tree using nested lists in Racket. I believe I am very close, but I am stuck on one section of my insertion testing process.
The syntax for my ...
Advice
0
votes
3
replies
51
views
Is there a Julian date algorithm without any restriction on the date?
The context is implementing conversion functions between Gregorian calendar dates and Julian dates.
Most (nearly all?) such implementations have restrictions on the dates - typically requiring that ...
0
votes
2
answers
78
views
Why doesn't a Wallace tree produce numbers with more than 2n final product bits?
I am trying to understand Wallace Trees.
The algorithm goes
multiply each bit of one number a by each bit of the other (b), which is accomplished as a simple AND gate, where the partial product of ...
2
votes
1
answer
158
views
Accurate computation of the inverse gamma function with the standard C math library
The inverse of the gamma function over the reals is multivalued with an infinite number of branches. This self-answered question is about the principal
inverse of the gamma function, Γ0-1(x), whose ...
-3
votes
1
answer
129
views
Monotonic Stack Algorithm: Is the Average Time Complexity θ(n) or O(n)? [closed]
The algorithm I've written for an assignment is closely related to this monotonic stack approach
https://www.geeksforgeeks.org/dsa/next-greater-element/
Best case:
n pushes → Time complexity: O(n)
...
2
votes
1
answer
151
views
Minimum number of sign flips for prefix sum positivity
Problem:
We are given a list of integers of length n. What is the minimum number of elements whose sign you need to flip such that every prefix sum is non-negative? (A prefix sum is the sum of the ...
2
votes
1
answer
136
views
Quick Sort in GNU COBOL produces invalid result
I am trying to implement Quick Sort in GNU COBOL (version 3.2.2) using a recursive subprogram.
The sorting logic is standard and works perfectly in other languages (C, Python), but when I run it in ...
0
votes
1
answer
244
views
+50
Trouble implementing the Cooper–Harvey–Kennedy algorithm for finding immediate postdominators in C++
I'm trying to implement the Cooper–Harvey–Kennedy algorithm from this paper in C++. The original is used to find dominators, however in my case I need to find the postdominators. For this, I am aware ...
8
votes
2
answers
368
views
Finding a maximum "score" of a permutation
Consider an array of a permutation P of length n (n > 2), namely some order of the integers 1 through n.
Example of P with length n = 7,
[6,5,2,3,7,1,4]
A "score" of a permutation is ...
-2
votes
1
answer
175
views
Why does my Quick Sort implementation sometimes cause stack overflow on large arrays with duplicates? [closed]
I’m trying to implement an in-place Quick Sort in Python. I have two slightly different versions of my partitioning logic, and I’m confused because both seem correct on small arrays, but the second ...
6
votes
3
answers
383
views
Find any single 2D point within radius, but fast
I've got a list P of 2-dimensional points, 100 ≤ |P| ≤ 100000, and a list C of circle centers, 100 ≤ |C| ≤ 100000.
All coordinates (x,y) ∈ P or (x,y) ∈ C are integral, 0 ≤ x,y ≤ 4095.
P and C may ...
2
votes
1
answer
130
views
How to find minimum number of days for a schedule according to a preference via graph?
I am tasked with a question as follows:
We have n players and we want to hold a wrestling tournament with exactly n * (n - 1) / 2 matches. In each day a player can only play at most one match. However,...
-2
votes
1
answer
95
views
Algorithm to calculate how much blend of points is a specific 2D point [closed]
I have a Set of 2D points that I want to create a set of areas from, similar to a Voronoi Diagram.
The difference is that I would like these areas to be blended, like in the following image.
I wouldn'...
2
votes
1
answer
116
views
Fast vectorized maximal independent set greedy algorithm [closed]
I need a really fast vectorized maximal independent set algorithm implemented in pytorch, so I can use it for tasks with thousands of nodes in reasonable time.
I cannot use networkx, it is way too ...
-2
votes
1
answer
117
views
Arabic Word Normalization and Search Ignoring Prefixes and Suffixes in quran app [closed]
I’m developing a Qur’an search application that allows users to search for Arabic words and find their occurrences across the Qur’an.
To improve accuracy, I added a feature that removes Arabic ...
3
votes
3
answers
188
views
Swapping corresponding negative and positive elements in an array while keeping constant order in their respective groups
The problem:
Given an array in which the number of negative elements is equal to the number of positive elements (arranged in arbitrary order). Swap the first negative and the first positive, then ...
1
vote
2
answers
128
views
Why is the worst-case binary selection sort time complexity considered O(n^2)?
Wikipedia and other textbooks reference binary selection sort's asymptotic worst-case time complexity to be O(n^2), usually justifying this with any extra computation caused by swaps. I don't ...
7
votes
3
answers
240
views
Swapping two array elements with two other specific array elements without using an if-statement
I have an array x of n >= 4 elements, at indices 0..n-1. I want to swap the elements at indices j and k, where 0 <= k < j < n with the elements at indices 0 and 1 (it doesn't matter ...
-3
votes
1
answer
97
views
How does Google Fonts browser optimize their font preview experience? [closed]
Analysis of Google Fonts
Here is me scrolling through the Greek fonts
As you scroll, you'll see it progressively calls the css2 url like:
https://fonts.googleapis.com/css2?family=STIX%20Two%20Text%...
2
votes
1
answer
123
views
Calculating a light volume that comes in through a window
I have a room that is a box. There is a single rectangular window on one of the walls of the room. A directional light source is shining into the room through the window. The light source has a ...
-2
votes
1
answer
152
views
I need a Python implementation of my Longest Possible Common Subsequence (LPCS) algorithm [closed]
Please be merciful - I've never asked a question here (I've answered a few) and am a total Python noob.
I developed an algorithm in SQL Server to compute the Longest Possible Common Subsequence (LPCS) ...
5
votes
3
answers
220
views
Efficient ways to check if two binary trees are the same
I implemented a recursive solution in Python to check if two binary trees are identical, which traverses nodes recursively and compares values and structure. The time complexity is O(n), space O(h).
...
8
votes
1
answer
237
views
Does std::find still guarantee first element with std::execution::par?
Parallel policy states that order of iterator evaluation is not guaranteed. However, std::find*, std::search and std::mismatch all say that they return first iterator matching condition. How do those ...
3
votes
2
answers
483
views
Find employees with overlapping wortktime hours
Given StartTime and endTime for N employees, an employee can form a team if his working hour overlaps with other employees' (both startTime and endTime inclusive).
Find the maximum team size.
Example:
...
4
votes
1
answer
308
views
How to make Beam Stack Search optimal and complete
I was reading the paper Beam-Stack Search: Integrating Backtracking with Beam Search by Rong Zhou and Eric A. Hansen and I was attempting to implement it in Java (see PathFinding.java repository in ...
0
votes
0
answers
90
views
Data structure indexing data by key value pairs
I have a bunch of data which is indexed by key/value pairs. For example I might have x=1, y=2, z=3 => data="1,2,3" and x=1,y=2 => data="1,2" etc.
The operations I need to ...
0
votes
0
answers
71
views
Weird Results in Robot Pathfinding Algorithm Testing Using MATLAB
Recently, I developed a MATLAB-based simulation to evaluate my robot pathfinding algorithm. The robots operate on a network of unidirectional tracks, where each robot computes a single path from its ...
7
votes
3
answers
293
views
How to find the longest elementary path in a graph?
The problem is to find the longest sequence of numbers from 1 to 100 such that each number is either multiple or divisor or the previous, and with no repetition. For example, 50 25 5 35 7 63 21 is a ...
0
votes
1
answer
96
views
How to check search time limits efficiently in a C++ UCI chess engine?
I’m writing a chess engine in C++ that communicates via the UCI protocol, and I need an efficient way to check whether the allocated search time has been exceeded without adding too much overhead. The ...
1
vote
1
answer
110
views
Why is my sliding window algorithm not showing results?
The current problem I'm having is that when the code runs it shows me "None" in the terminal.
/usr/local/bin/python3.12/Users/jaredmccarthy/Desktop/2025/ejercicios_leetcode.py
None
Process ...
1
vote
1
answer
76
views
Binary Tree Level Order Traversal problems
Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level).
What's the problem with the following implementation?
How to fix it?...
2
votes
0
answers
114
views
JIRA Lexorank in depth
I'm researching about maintaining order in a list like JIRA, and I come across Jira Lexorank. I've already understood it's core concept, but there are 2 questions that I struggle to find the in depth ...
5
votes
2
answers
251
views
Generate all permutations which contains a number at least once given length, and number of digits
Okay, here's the problem I have. I'd like to do something like this:
V(n,k) generates all n-sized permutations in which each permutations contains all digits from 0 to k-1 in lexicographic order.
V(2,...
-2
votes
2
answers
150
views
Performance of frequently reordering a short list [closed]
I have an application where I have a Rule object that has a list of Filter predicates. I will be comparing many Events to the predicates, and want to know if they all match. Most Events will not match ...
7
votes
2
answers
1k
views
Lexicographically minimal grid path algorithm
I'm trying to solve the following problem: Minimal Grid Path (CSES). Here is the content of the problem:
You are given an n x n grid whose each square contains a letter.
You should move from the ...
-2
votes
3
answers
845
views
Solve CSES Mountain Range efficiently
This is CSES Mountain Range problem: https://cses.fi/problemset/task/3314/
There are n mountains in a row, each with a specific height. You begin your hang gliding route from some mountain. You can ...
4
votes
2
answers
399
views
Number of lexicographical swaps to make the array non decreasing
A lexicographical swap is defined as:
At each step, pick the earliest possible inversion (i, j) (smallest i, then smallest j > i with a[i] > a[j]) and swap them.
Repeat until the array is sorted....
3
votes
2
answers
194
views
Max subArray => IllegalArgumentException: 6 > 5
The method is working as intended, but while I was trying multiple cases, I got this weird issue, so hopefully someone can understand why and explain it to me, since 6 > 5 looks logically sound to ...
0
votes
2
answers
246
views
How to rotate one vector around another by a certain angle using struct and quaternion in C language?
I am solving this problem-
U and K are vectors is R3. U rotated around K by an angle θ in radian produces a new vector V. Find the components of V as functions of U , K and θ.
I solved the problem ...
5
votes
3
answers
154
views
Why the second letter is being ignored when using my Typewriter component?
I'm currently building my portfolio and im making a typewriter effect for some text :
"use client"
import { useEffect, useState } from "react"
type Typewriter = {
textToWrite: ...
2
votes
2
answers
140
views
How can I optimize my viterbi algorithm for chord detection?
I am building a Digital Audio Workstation in the likes of FL Studio and have a chord detection algorithm. It works as it is but is extremely inefficient which I need to optimize for.
First we start ...
0
votes
4
answers
589
views
Answer sum of values on tree path, with updates, efficiently
You are given an unweighted tree with N nodes and each node starts with value 0. There will be Q queries. The 1st type of query will change the value at a node to a new value. The 2nd type of query ...
1
vote
1
answer
157
views
LeetCode 199. Binary Tree Right Side View constant memory complexity
I'm trying to solve LeetCode 199.
Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.
I've ...
0
votes
0
answers
47
views
How to filter a curve to prevent overlap of segments during rendering
I have a sequence of points in 2d that are rendered as a thick line by using quads.The quads are formed by extruding the curve around its center line in the normal direction.
The figure is showing a ...
3
votes
0
answers
255
views
Iterating over special semiprimes
For a project of mine related to prime counting, I am interested in iterating over special kind of semiprimes.
For a given n, I want to iterate over semiprimes k=pq with the following properties/...
2
votes
1
answer
302
views
Minimum cost to convert all 1's to 0's using window of size k
There is a row of toys, where each toy is represented as either:
1 → red toy (needs to be painted blue),
0 → blue toy (already painted).
An integer k is given. An operation can be performed as ...
2
votes
1
answer
201
views
Subset data structure with O(1) insert, find, and delete_greater_equal
An abstract data type maintains a subset of numbers {0,1,2,...,n-1}. The operations allowed on this are:
insert(i) - Insert element i in the subset if not already present.
find(i) - Return True iff ...
10
votes
3
answers
611
views
Better way to search for a node in binary tree
This is the code I have written for searching a node in a tree as a part of my assignment:
typedef struct NODE
{
int key;
struct NODE *left, *right;
} Node;
Node *search(Node *head, int key)...
4
votes
1
answer
224
views
Spelling Bee optimal word set search
The NYT Spelling Bee game is a word game, where given 7 letters including 1 "center letter", you find words at least 4 letters long that must use the "center letter". The scoring ...