Questions tagged [algorithms]
An algorithm is a sequence of well-defined steps that defines an abstract solution to a problem. Use this tag when your issue is related to design and analysis of algorithms.
11,780 questions
2
votes
1
answer
80
views
Flaw in logic to solution to two generals problem
I am failing to find the flaw in logic to a “partial” solution to the two generals problem and would appreciate help seeing where I went wrong (knowing it’s unsolvable)
There are two generals A and B, ...
0
votes
0
answers
33
views
Which types of outputs are more likely to be produced by simple rule-based programs with fixed rules?
I’m interested in knowing how the complexity of outputs relates to the programs that generate them. For example, in cellular automata like Conway’s Game of Life (a grid-based system where simple rules ...
-2
votes
1
answer
53
views
Can't understand why my algorithm is not correct [DFS AND BACKTRACKING]
I'm trying to solve the following Leetcode problem: https://leetcode.com/problems/path-sum-ii/description/
This solution I came up with is working: https://pastebin.com/ma3DtU5b
However, I was not ...
0
votes
1
answer
44
views
Why Pseudo-polynomial time algorithms are required?
One of the problems that has Pseudo-polynomial time algorithm is $0/1$ Knapsack problem.
The $0/1$ Knapsack problem is a follow. Given a set of $n$ elements with weights and prices, and a positive ...
1
vote
0
answers
28
views
Good algorithm to solve a system of "cyclic" banded linear equations
I would like to solve the equation $Ax=b$ where $A$ is an $N\times N$ "cyclic" banded matrix (there might be a better term, but I wasn't able to find it), i.e. a matrix that look like
$$\...
2
votes
0
answers
53
views
Find all non-extendable ranges in an array of real values with a non-positive sum
I have a long array of size $n>10^6$, call it $X$. I would like to find all ranges $[a, b)$ satisfying the following conditions
$\sum_{i=a}^{b-1}X[i] \leq 0$,
$b-a \geq K$,
$\sum_{i=a-1}^{b-1} X[i]...
1
vote
0
answers
46
views
Is there an efficient algorithm to reduce the degree of a multivariate polynomial given a list of monomial substitutions?
The degree of an $n$-variate polynomial is defined as the maximum degree of the monomials that composes it. Now, given a polynomial $P$ (or rather, a list of monomials, since the coefficients don't ...
0
votes
1
answer
52
views
Fast algorithm to find factor of a term that is a power
Let's say we have a term (eg an integer, but interested in symbolic polynomial as well) $t$ that can be factored as $t=p^k \cdot m$.
Note: $p$ need not be necessarily prime or otherwise irreducible ...
0
votes
1
answer
44
views
Best strategy with limited ability of memoization
Background
The algorithm to calculate the n-th Fibonacci number using recursion is as follows:
...
1
vote
0
answers
57
views
A Fast Polynomial Multiplication Using only Integers for AKS Algorithm
I'm getting stuck at choosing a fast polynomial multiplication algorithm for the last step of the AKS primality test:
...
-2
votes
0
answers
27
views
Algorithm Design Binary Tree
I have this request: "Design an algorithm that sums all node values within a tree and compares the result to a target value. If the sum is equal to the target, return 1; otherwise, return 0."...
1
vote
0
answers
62
views
Find the largest subset of chords in which every pair intersects
I have been trying to solve the following problem from ericksons algorithms:
20)c) Let P be a set of n points evenly distributed on the unit circle, and let S be a set of m
line segments with ...
5
votes
2
answers
161
views
How is $\overline{SAT}$ not obviously in NP?
First of all, I do know that it is not known whether or not $\overline{SAT}$ is in NP. But to me, it clearly looks like it is in NP. Given a Boolean formula φ with n variables, we nondeterministically ...
-1
votes
1
answer
42
views
Master Theorem for this equation
$$T(n) = T\big(\frac{ n}{2}\big) + \Theta(1)$$
Hi,
I'm resolving this recurrence relation through Master Theorem.
I would like to know my solution is correct.
$\alpha = 1$
$\beta =2$,
$f(n) = \Theta(...
0
votes
1
answer
115
views
Runtime analysis of Fibonacci series
To compute the $n$th Fibonacci number, a recursive algorithm is as follows:
...
0
votes
1
answer
43
views
Scheduling Training for Two Dogs with Rest Constraints
You are a dog trainer tasked with training two dogs, Peter and Markley, for train1 days and train2 days, respectively. You can ...
1
vote
1
answer
22
views
Optimal in-place suffix sorting algorithm on read-only general alphabets produces wrong results
I am trying to implement the Optimal In-Place Suffix Sorting algorithm (Section 5.5 of “Optimal In-Place Suffix Sorting” by Bingmann, Fischer, and Kurpicz, 2019), specifically the read-only general ...
1
vote
0
answers
23
views
Hypergraph partitioning constrained on partition size
I have a $k-$uniform hypergraph $H=(V,E)$ with $n$ vertices. I need to partition $H$ into two partitions of sizes $r$ and $n-r$. Is there an approximating algorithm that can do this while minimizing ...
2
votes
1
answer
130
views
Standard Books for Backtracking and Branch and Bound Techniques
I want to study advance topics of algorithms such as backtracking and branch and bound algorithms. I tried to find out the content in following books
Dasgupta, S., Papadimitriou, C. H., & ...
1
vote
1
answer
31
views
What does strongly sublinear mean?
I am reading a paper in which it says:
... adhering to the most resricive memory regime, in which the local memory per machine is strongly sublinear in the number of vertices and the total memory is ...
0
votes
0
answers
23
views
Why is the universal hash function defined as Hp,m={ha,b(k)∣a,b∈{0,…,p−1},a=0}?
I understand the basic division hash function h(k)=k mod m, and the use of this function
but I don’t understand why the universal hash function introduces the parameters a and b and uses a prime ...
0
votes
0
answers
37
views
What is the name and theoretical basis for a Treap/RBST variant with a probabilistic, size-based merge?
I'm exploring data structures suitable for persistent applications. A key use case I have is splitting a subsegment from a tree, copying it, and then merging these copies into other data structures.
...
0
votes
0
answers
19
views
Largest Triangle in Convex Polygon Algorithm Help
I am trying to implement the algorithm to find the largest triangle in a convex polygon as described in section 6.1 at the end of ...
4
votes
1
answer
105
views
How to find all maximal rectangles contained in a rectilinear shape on a discrete grid
I would like to find all the maximal rectangles contained in a rectilinear shape on a discrete grid. That is, every rectangle such that, if it were to grow by one cell in any direction, it would no ...
1
vote
1
answer
66
views
Big O and Omega, how can they be different for a specific case(worst/best)
So I understand that O is an upper bound and omega is a lower bound. I also understand that case is different than bounds, i.e worst case can have O/Theta/Omega different from best case.
My question: ...
0
votes
1
answer
82
views
Ordered-Scheduling Approximation Algorithm for Load Balancing and Proof
Given a list of $n$ jobs to be executed on $m$ identical machines, the load balancing problem is to distribute the $n$ jobs over the $m$ machines, such that the makespan is minimised. The makespan is ...
3
votes
1
answer
129
views
Assignment problem with dependencies between assignments
I've been working on a simulator for my grid based game in order to find optimal solutions. One heuristic I'm using to prune the search space is the distance to goals. There are n players and m goals ...
0
votes
0
answers
29
views
Implement bubble sort with limited memory elements
Suppose you have elements (a,b,c,d), and you want to use bubble sort to sort them(either ascending or descending,doesnt really matter), but you can only use a single memory stack (with infinite ...
1
vote
1
answer
109
views
Prove optimality of a sorting algorithm
I'm working on proving a greedy solution to the problem in Codeforces 205B, which states:
Given an array of integers a of length ...
1
vote
2
answers
90
views
Looking for Graphs with Known Chromatic Numbers
I’m working on an algorithm for graph coloring, and I want to test how close its results are to the actual chromatic number. For this, I’m looking for graphs whose chromatic numbers are already known.
...
1
vote
0
answers
22
views
Asymptotically optimal strategy for Las Vegas algorithms with unknown run time distribution if you can suspend and resume later
In the paper "Optimal Speedup of Las Vegas Algorithms" Luby, M., Sinclair, A. and Zuckerman, D. give an asymptotically optimal sequences for how many time to run an Las Vegas algorithm ...
2
votes
1
answer
51
views
Existence of inversion in range
Given segment $\left[L, R\right]$ check if there is an inversion in the segment.
If $a_i > a_j$ and $j> i$ then it is an inversion.
Can this done faster than a linear check given that we can ...
0
votes
0
answers
118
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.
...
1
vote
2
answers
473
views
What is the most efficient algorithm for partitioning a list into roughly equal sections?
I started thinking about this problem while trying to find the best way to divide a book reading into $4$ roughly equal sections. I ended up brute-forcing every possible combination, but now I'm ...
8
votes
1
answer
1k
views
Switching bodies to get everyone back to their correct body?
Yamada-kun can switch bodies with anyone he kisses. So first he kisses A, and switches into their body. Then, as A, he kisses B and switches into their body (and now B is in A's body). Then, as B, he ...
1
vote
0
answers
82
views
What data structure minimizes the amount of combine operation in point updates and range queries (and having the smallest leading constant)?
Suppose you have an array $a$ of $n$ elements in an set $X$, and a associative binary operation $\circ \ \colon X \times X \rightarrow X$, that can be evaluated in constant time, but is costly (e.g. $...
0
votes
1
answer
92
views
Using Binary Indexed Trees to efficiently do range updates and range MINIMUM queries
It is already known that you can use two BITs (aka Fenwick Trees) to do RMQ in $O(logn)$ and point update in amortized $O(logn)$ time (Described in this paper.)
However, I want a step further, doing ...
3
votes
1
answer
101
views
Algorithms for embedding a graph on a 2D grid to minimize Manhattan distance between neighbours
I have an undirected, unweighted graph with N vertices. I want to find a 2D embedding of the vertices on a k × n grid (where <...
0
votes
0
answers
51
views
Can the constants of FNV1A be computed for a specific set of strings to make it a perfect hash function?
I am hashing a bunch of strings made up of a finite number of known keyword strings (n many keyword strings). Here I want to generate a perfect hash s.t. each ...
1
vote
0
answers
41
views
Deterministic Θ(m + n) SSSP for Arbitrary Positive Real Weights via Monotone Buckets
Context
Dijkstra’s algorithm with a comparison-based heap runs in
Θ(m + n log n) time on a directed graph with non-negative real edge
weights. The freshest bound I’m aware of for real weights is
<...
1
vote
1
answer
160
views
How fast can cyclic shift be implemented?
How fast can cyclic shift of size $n$ be implemented? Lets say the input is a string of length $n+ \log_2 n$ where the last $\log_2 n$ tell the function how much to shift the first n digits.
I know ...
1
vote
1
answer
167
views
Space complexity of tournament tree method for second maximum element
Given an array of unique elements of size $n$, the goal is to find the second maximum element using tournament tree method. The model of computation is RAM model.
Algorithm: The idea to pair the ...
1
vote
1
answer
129
views
Runtime for the unordered "Errands" problem
Consider the following problem:
Let $G=(V, E)$ be a weighted undirected graph with nonnegative weights. Let $S_1, S_2, \ldots, S_k\subseteq V$ be disjoint subsets representing vertices where you can ...
0
votes
0
answers
56
views
How to minimize parentheses when stringifying arithmetic AST for right-to-left evaluation languages with different precedence rule?
I'm looking at translations to and from APL, which has right-to-left evaluation and no operator precedence. Is there a known algorithm to minimize parentheses usage when keeping the same operators for ...
0
votes
0
answers
161
views
3-Partitions with same sum problem algorithm
this is the problem statement (3-Partition Problem): Partition a set of integers into three subsets with equal sums.
Input: a sequence of integers $v_1, v_2, ..., v_n$
Output: check if it is possible ...
1
vote
0
answers
32
views
Graph labeling through optimization of a quadratic form
Given a simple unlabeled graph $G = (V,E)$ with vertices $V=\{1,\ldots,n\}$, let $L(G)$ a labeled graph obtained by labeling (with distinct labels) the vertices of $G$ through any $l: V \rightarrow V$ ...
1
vote
0
answers
47
views
Can stochastic optimization algorithms achieve convergence in $\Theta(N^{m^{1/s}} / \log^k N)$ with $m > 1, s > 1, k \gg m$? [closed]
This specific convergence rate with dominant logarithmic factors is indeed highly desirable for large-scale systems. While there's a rich body of work on stochastic approximation and equilibrium ...
0
votes
1
answer
127
views
How to find the shortest path of a perfect square length in O(V+E)?
I'm trying to solve the following graph problem and am struggling to meet the required time complexity.
The Problem:
Given an unweighted, connected, undirected graph G=(V, E) and a source vertex s in ...
0
votes
0
answers
36
views
Shapez2 Shape Crafting Optimization Problem
This is an algorithmic challenge from the factory game Shapez2, essential for building what's known as a TMAM (True Make Anything Machine).
I’ve been researching this problem over the past month. ...
1
vote
0
answers
66
views
How can I optimize the time complexity of a jump-based coin collection algorithm in an array?
I'm working on a problem where I have an array arr of size n, and I need to collect the maximum number of coins by jumping ...