instruction
stringlengths
0
29.8k
⌀
Suppose $l=[a[0],a[1],a[2],,a[n]]$ be a list of numbers. I need to calculate $$ \sum a[j]a[k]a[j']a[k'] $$ such that $j+k=j'+k'$ .Obviously we can implement it in $O(n^4)$ time complexity by the exhaustive search method.Can we do it better?It is pertinent to mention the number of tuples satisfying $j+k=j'+k'$ are ...
It's trivial to do in $O(n^3)$ time, by enumerating all $O(n^3)$ tuples $(j,k,j',k')$ such that $j+k=j'+k'$, computing the appropriate product, and summing those products. I'll let you discover how to enumerate those tuples. I am confident you can figure that out: if you spend a little time thinking about it and/or w...
null
null
Kosolobov [1] solved this exact problem. The first algorithm in the paper supports stack operations on a string while detecting a repeated substring, and each operation takes amortized $O(\log m)$ time where $m$ is the maximum string length so far. The algorithm works for unordered alphabets (only equality compariso...
Newer multiplication algorithms aren't needed to show such a time bound in this model. Given a precomputed multiplication table of size $O(p)$, multiplication $a \times b$ of $a, b \leq p^{O(1)}$ takes a constant number of additions and table accesses. For example, let $p = \Theta(N^{1/3})$ then the pre-computation ...
I agree that there is no recipe and others provided insight on how matters evolved or can evolve. A key aspect hindering the design of your "meta-algorithm" is a lack of "modularity" in Computer Science. The theory of algorithm design (and analysis) is not on par with say civil engineering, for which automation is more...
null
Yes, instead of the shortest path problem, we should consider the all shortest path problem or, more precisely, [single-source shortest-paths (SSSP) problem](https://en.wikipedia.org/wiki/Shortest_path_problem#Algorithms). For SSSP, given node $s$, the objectives are $\min_{S_v} f(S_v)$ for all $v\in V$, where $S_v$ is...
The Coin Change problem is stated as: > Given an integer array coins[ ] of size N representing different > denominations of currency and an integer sum, find the number of ways > you can make sum by using different combinations from coins[ ]. > Note: Assume that you have an infinite supply of each type of coin....
Why do the order of the nested loops matter when solving the Coin Change problem?
|algorithms|dynamic-programming|arrays|coin-change|
A simulating halt decider (SHD) continues to correctly simulate its input until it correctly matches a non-halting behavior pattern then this SHD is necessarily correct when it aborts its simulation and reports non-halting. [**Complete halt deciding system (Visual Studio Project)**](https://liarparadox.org/2022_09_...
In the second solution you are overcounting the number of combinations. In fact you are counting the of ways to choose an **ordered** list of coins that sums to `sum`. For example suppose that you have coins of values $1$ and $2$. - There is only one way to obtain a sum of $0$, namely using no coins and the algo...
Why does the order of the nested loops matter when solving the Coin Change problem?
I have a dataset of billions of points (stars) scattered on a two dimensional plane (sky), each with its corresponding (brightness) value. How can I efficiently find locations for a fixed size rectangle (corresponding to a telescope field of view) for which the point values sum up to a minimum?
Find the darkest region in the sky
|algorithms|optimization|
I am doing some research for a paper that I am writing and one of the papers that I have come across that has some interesting results talks about an "almost tight bound". I am not a computer scientist and I feel like I understand the actual math of the bounding. However, I don't know what it means by "almost tight". I...
What is an "almost tight bound"
|lower-bounds|upper-bound|
#### Why is the working solution correct? First things first. Important things first. Let us understand why the working solution is correct first instead of finding where the wrong solution goes wrong. <!-- For brevity and readability, I will use Python as pseudocode. --> Here is a solution that is easier to u...
#### Why is the working solution correct? First things first. Important things first. Let us understand why the working solution is correct first instead of finding where the wrong solution goes wrong. <!-- For brevity and readability, I will use Python as pseudocode. --> Here is a solution that is easier to u...
The green edges and large green nodes in the following image depict a graph (the grid and small nodes are irrelevant): [![graph 1][1]][1] The graph's properties include: * Connected * Uniformly random (or nearly so) * Multiple leaf nodes Here's another graph, with the same properties, showing a possible c...
Uniformly random connected directed acyclic graph algorithm
|algorithms|graphs|randomness|
null
The green edges and large green nodes in the following image depict a graph (the grid and small nodes are irrelevant): [![graph 1][1]][1] The graph's properties include: * Connected * Uniformly random (or nearly so) * Multiple leaf nodes Here's another graph, with the same properties, showing a possible c...
I'm wondering about the optimal complexity - or at the very least, some way of achieving non-terrible complexity - of a particular stack variant, that I'm calling a 'nonrepetitive stack'. A nonrepetitive stack is like an ordinary stack, except that a push that would result in a repeated subsequence fails, not updati...
Optimal algorithmic complexity of "a nonrepetitive stack"?
public static int countSubstrs (String str, int i, int j, int n) { if (n == 1) { return 1; } if (n <= 0) { return 0; } int res = countSubstrs (str, i + 1, j, n -1) + countSubstrs(str, i, j-1, n-1) - countSu...
The green edges and large green nodes in the following image depict a graph (the grid and small nodes are irrelevant): [![graph 1][1]][1] The graph's properties include: * Connected * Uniformly random (or nearly so) * Multiple leaf nodes Here's another graph, with the same properties, showing a possible c...
The green edges and large green nodes in the following image depict a graph (the grid and small nodes are irrelevant): [![graph 1][1]][1] The graph's properties include: * Connected * Uniformly random (or nearly so) * Multiple leaf nodes Here's another graph, with the same properties, showing a possible c...
# Overview The green edges and large green nodes in the following image depict a graph (the grid and small nodes are irrelevant): [![graph 1][1]][1] The graph's properties include: * Connected * Uniformly random (or nearly so) * Multiple leaf nodes Here's another graph, with the same properties, showin...
Uniformly random connected minimally cyclic graph algorithm
# Background I'm looking to replicate (as closely as possible) the graphs depicted in this question (in [MetaPost](https://www.tug.org/docs/metapost/mpman.pdf)). # Overview The green edges and large green nodes in the following image depict a graph (the grid and small nodes are irrelevant): [![graph 1][1]][...
{"Voters":[{"Id":153410,"DisplayName":"Macosso"}]}
$A$ is a $m*n$ matrix \ $B$ is an $n*n$ matrix I want to return matrix C of size m*n such that: \ $C_{ij} = \sum_{k=1}^{n} max(0, a_{ij} - b_{jk}) $ In pseudocode it could be like below ``` for i = 1 to m: for j = 1 to n: C[i,j] = 0 for k = 1 to n: C[i,j] += max(0, a[i,j]...
|algorithms|time-complexity|
Given the programming language C#, how would I be able to write the BNF and EBNF grammar syntax of its while loop?
BNF and EBNF Syntax for while loops in C#
|formal-grammars|c|
Given the programming language C#, how would I be able to write the BNF and EBNF grammar syntax of its while loop? After trying to search and understand more, I got this as my BNF grammar for while loops <while-statement> :: = while ( <expression> ) <statement> | do <statement> while ( <e...
Given the programming language C#, how would I be able to write the BNF and EBNF grammar syntax of its while loop? After trying to search and understand more, I got this as my BNF grammar for while loops < while-statement > :: = while ( < expression > ) < statement > | do < statement > wh...
We can note that to compute $C_{ij}$, it is enough to know the sum, and the count of $\{b_{jk}\}_{k=1}^n$ such that $b_{jk} < a_{ij}$. This can be done after a simple preprocessing and the final time complexity will be $O(mn\log{n})$
Given the programming language C#, how would I be able to write the BNF and EBNF grammar syntax of its while loop? After trying to search and understand more, I got this as my BNF grammar for while loops < while-statement > :: = < do-statement >< while-statement > | < do-statement > though I don't thin...
I have to find the context-free grammar of this language: $ L={a^nb^m, n≠2m} $<br> So I did: $ S -> a | aYb | epsilon$ $Y -> aSb | X | epsilon$ $X ->bX | epsilon $ is it correct?
Context free grammar of $ L={a^nb^m, n≠2m} $
|context-free|computation-models|
I couldn't search much about a problem I have. There is a 1D array of zeros and ones. The objective is to pack all ones with the least number of containers. Each container is variable in length but has a maximum length limit. Items in array cannot be moved. For example, if the max length limit is 5, I would pack...
Name of a packing problem similar to this?
|algorithms|
I don't know what your greedy solution is, but there is an easy greedy solution (here I denote $L$ the max length of a container): ``` Input: array of length n i ← index of the first 1 while i < n do create a container starting at i of length max(L, n - i) i ← next 1 after index i + max(L, n - i) ``` ...
I have to find the context-free grammar of this language: $ L=\{a^nb^m, n\neq 2m\} $<br> So I did: > $ S \to a \mid aYb \mid \epsilon$ > > $Y \to aSb \mid X \mid \epsilon$ > > $X \to bX \mid \epsilon $ is it correct?
Context free grammar of $ L=\{a^nb^m, n\neq 2m\} $
null
{"OriginalQuestionIds":[11315],"Voters":[{"Id":755,"DisplayName":"D.W."}]}
Is $n=\Theta(n^{1+o(1)})$? To me it appears to be true as $n$ tends to infinity $n^{o(1)} =0$.
Is $n=\Theta(n^{1+o(1)})$?
|asymptotics|landau-notation|
Sure. Pick a [block cipher](https://en.wikipedia.org/wiki/Block_cipher) (i.e., [pseudorandom permutation](https://en.wikipedia.org/wiki/Pseudorandom_permutation)), $E_K$, and a random key for it, $K$. Let $x_i=E_K(i)$. Then this has the properties you are looking for. Short explanation: --- As the block cipher ...
null
These are three paragraphs from the book CLRS: > The rod-cutting problem is the following. Given a rod of length $n$ > inches and a table of prices $p_i$ for $i = 1, 2, ..., n$, determine > the maximum revenue $r_n$ obtainable by cutting up the rod and selling > the pieces. > > In the rod-cutting problem, an o...
null
https://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees says > A complete binary tree is a binary tree in which every level, except > possibly the last, is completely filled, and all nodes in the last > level are as far left as possible. It can have between 1 and 2h nodes > at the last level h.[18] An alt...
Can a complete binary tree have at least two nodes with just one child?
|binary-trees|
null
I found what you copied in the following [text][1] The idea is that users access (querying, updating or etc ..) of the database changes with time. It may be at its peaks in sale seasons for example if the database belongs to a commercial applications. etc .. - if it is always fixed and predicted then it is static. ...
null
The Wikipedia [article][1] mentions non-determinism in the context of dataflow architectures. Arthur Veen's [paper][2] mentions non-determinism when it elaborates on MERGE nodes as conditional constructs. Are dataflow architectures non-deterministic in the sense of Non-Deterministic Turing Machine? For any progra...
null
To the best of my understanding, $m \models p$ asks whether the LTL formula $p$ satisfies the LTL formula $m$. In other words, $m \to p$ is a tautology. Here are some examples of where $m \models p$ holds: Xp |= Fp q |= p U q Gq |= Fq Of course, trying to visualise all this in you head ...
Given LTL formulas $m$ and $p$, is there a tool that can check whether $m \models p$ does hold?
|logic|model-checking|linear-temporal-logic|temporal-logic|
null
Most errors in computer systems are caused by humans directly through design and programming errors. Almost all questions on Stack Overflow concern programming problems and most errors that make it to end users are software bugs (human oversight). Logic errors in hardware design (human oversight) have also caus...
null
What it looks like you are after is the [Block Swap edit distance][1]. Here is a paper outlining a polynomial time solution to this problem, [An Edit Distance Algorithm with Block Swap ][2]. I cant recall the exact time complexity they give in the paper, however it is outlined in there. [1]: https://www.academia...
null
After the build-up phase of the heap, `HeapSort` repeatedly removes the root of the heap. You can find configurations such that every root removal implies the movement of nodes on every level, resulting in a total work proportional to $$\log(n)+\log(n-1)+\dots \log(1) \sim \log(n!)$$
null
After the build-up phase of the heap, HeapSort repeatedly removes the root of the heap. You can find configurations such that every root removal implies the movement of nodes on every level, resulting in a total work proportional to $\log(n)+\log(n-1)+\dots+ \log(1) \sim \log(n!)$.
Are NP-Complete languages closed under any regular operations?
null
Is there a faster than O(n^2) way to compute a vector of length n from another vector and an n by n matrix?
null
Given an undirected graph $G=(V,E)$ where $V$ is a set of vertices, and $E$ is a set of edges and \ given a set $D$ where $D \subseteq V $ and $ \forall v \in V \setminus D \: \mid \: \exists w \in D : \{v,w\} \in E$ **INPUT** an undirected graph $G=(V,E)$ and a number $k \in \mathbb{N}$ \ **PROBLEM $X$ :** Do...
null
Toposort also work as a visited array and prevent from getting into a cycle where every time your distance increases. 0 ---> 2 ---> 0 Now, you are thinking: why don't we use a visited array instead of toposort? You can't use a visited array because you don't know when your distance will increase, but u...
null
Looks like you are a bit confused by the notion of *MDP policy*. There's a detailed discussion with lots of examples in [this question][1]. A policy is any possible strategy in a given environment. Example: "go $East$ in any state" is a valid strategy in your MDP (though maybe not optimal), as well as "go $West$ in ...
null
First, we factorize the integer and then we convert the problem to a multiset partition problem. The multiset partition problem can be solved by a **backtracking** algorithm. Given an integer $n$, let its factorization be $n=p^{a_1}_1\cdot p^{a_2}_2 \cdots p^{a_m}_m$ where $p_1, \cdots, p_m$ are distinc primes. We l...
null
I have implemented in C++ the [Needleman-Wunsch][1] algorithm for pairwise sequence alignment using the following scores: * +1 for match (regardless of base) * -1 gap penalty * -1 for a mismatch. Given two sequences of length $m$ and $n$ the algorithm then generates the $mn$ search space row by row...
null
In standard agnostic learning, we assume that there is a concept class $H\subseteq \{h:\{0,1\}^n\rightarrow \{0,1\}\}$. Given samples from a distribution $D:\{0,1\}^n\times \{0,1\}\rightarrow [0,1]$, the goal is to output the best $h\in H$ for which $err_D(h)\leq C\cdot opt+\varepsilon$, where $opt= \min_{h\in H}err_D(...
null
|operating-systems|virtual-memory|