121,491 questions
-1
votes
0
answers
64
views
Understanding Time Complexity and Space Complexity in Recursive Algorithms [closed]
I am trying to analyze and optimize recursive algorithms, particularly with regards to their time and space complexity. I have written a recursive solution for the Fibonacci sequence and a merge sort ...
0
votes
0
answers
46
views
How can I sync a frame counter between two computers with potentially high ping?
I have a game with a frame counter which increments at a fixed rate, and my goal is for two instances of the game on different computers to sync this number so that they will have the same number at ...
-3
votes
0
answers
58
views
Can we solve the following optimization problem by dynamic programming [closed]
Suppose we have an 𝑚*𝑛 grid, let 𝑖=0,...,𝑚−1 and 𝑗=0,...,𝑛−1. For each grid point we have an array 𝑆𝑖𝑗 of size 𝑁 that serves as local score function. We want to to find a way that assigns ...
Advice
0
votes
2
replies
60
views
slicing html text based on length of plain text
I have a problem where I need to cut off text based on a max length. But the inputted string could be html a la <p>hello</p>. the html tags do not count towards the max length.
for example ...
4
votes
1
answer
151
views
LZSS - handling the compression of data that contains token-like strings
I've been working on implementing some compression algorithms in C/C++ and JavaScript, I've started by building out LZSS. So far everything seems good. I check my dictionary buffer for matches, and if ...
Advice
1
vote
8
replies
131
views
Making a palindrome out of a string of random letters (or any given value type inputs)
Found this code exercise on W3R. Been trying to figure out the relationship between the outer and inner loop (i and j), but can't seem to wrap my head around it. If anyone could walk me through this ...
-4
votes
0
answers
140
views
How do you make an algorithm that'll find the shortest way to sort a sequence of numbers by applying function that converts to closest lower prime? [closed]
Imagine you get sequence of integers:
[a1 a2 a3 ... an]
where:
1 <= a <= 10^6
1 <= n <= 10^6
You are given a function f(x) that can change a number to the closest lower prime number, or ...
2
votes
1
answer
117
views
Why does my Python solution for selecting 2 points from each interval give incorrect results for overlapping intervals?
I’m trying to solve the following Leetcode problem:
You are given a 2D integer array intervals where intervals[i] = > [starti, endi] represents all the integers from starti to endi
inclusively.
A ...
0
votes
1
answer
207
views
How to implement a list with an efficient "index of" operation?
I'm interesting in possible implementation approaches for a quite special variant of a list, with the following requirements:
Efficient inverse lookup ("index of"): "give me an index ...
Advice
1
vote
3
replies
76
views
Python library recommendation for the implementation of a neural network modification algorithm
I want to implement in python some algorithms from a paper that allow for a pre-trained neural network to be modified (adding or removing neurons or layers) conserving (theoretically) the outputs of ...
6
votes
2
answers
300
views
Efficient algorithm to count contiguous subarrays that can form arithmetic progressions
I'm working on a problem where I need to count, for each possible common difference D, the number of contiguous subarrays whose elements can be rearranged to form an arithmetic progression with common ...
0
votes
0
answers
73
views
Why does alpha and best score/move get updated before a beta cutoff in Negamax with Alpha-Beta Pruning?
In the code block below is my current Negamax implementation, it is currently barebones. My question is why do Blocks 1 & 2 have to occur for a node that is expected to incur a beta-cutoff (i.e. ...
0
votes
2
answers
75
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
60
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
70
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 ...