instruction
stringlengths
0
29.8k
βŒ€
I'm new to recurrence relations and master theorem so trying to learn. Say there's an algorithm $A$ whose input is the root of a binary tree $T$. $A$ recurses so that it's called on each and every node in $T$ exactly once. The time complexity of $A$ called on a node $X$ is $O(number\:of\:nodes\:in\:subtree\: rooted\:at...
Time complexity of tree algorithm
|complexity-theory|time-complexity|trees|recurrence-relation|master-theorem|
**Motivation.** This is a variant of the [subset sum problem](https://en.wikipedia.org/wiki/Subset_sum_problem) involving the bitwise ${\tt XOR}$ operation. **Problem.** Given a set $X$ of $n$ bit-strings of length $n$, determine if there is a non-empty subset $S\subseteq X$ such that the the bitwise ${\tt XOR}$ of ...
Subset ${\tt XOR}$ problem
|np-complete|np|
What data structure would be optimal in terms of time and space for the following usecase: Given information about rectangles in the form of- {rectangle_id,left_bottom_corner_x, left_bottom_corner_y, right_top_corner_x, right_top_corner_y}. I need to use a structure which will answer the following querie...
|np-complete|np|subset-sum|xor|
The problem is in $P$. It can be solved in polynomial time with Gaussian elimination. Build a $n\times n$ boolean matrix $M$, whose $i$th row is the $i$th bit-string in $X$. All arithmetic will be modulo 2 (i.e., in $GF(2)$). Solve for a bit-string $v$ such that $Mv=0$ (and $v \ne 0$). Such a bit-string, if it e...
null
I struggle to understand a step in the following solution to a RISC-V exercise. --- **Exercise:** a pipelined RISC-V processor with no data forwarding paths executes the following program. For each instruction and clock cycle, determine the stage of the processor involved. **Solution:** [![enter image descr...
Step in RISC-V program on a Pipelined Processor
|cpu|cpu-pipelines|risc-v|
It's interesting to note that while the protocol is called "reliable" you can't build a system with guaranteed data delivery with it. It looks like it can be said it's _receiver reliable_, since receiver always receives the exact data the sender sent (checked through checksumming) in correct order (achieved through seq...
# The Short Story # A famous computer scientist, [Tarjan][1], wrote a book years ago. It contains absolutely bizarre pseudocode. Would someone please explain it? # The Long Story # [Tarjan][1] is known for many accomplishments, including the fact that he was the coinventor of [splay trees][2]. He published a b...
Note that the complexity of the algorithm depends on the tree $T$. For the maximally imbalanced tree, as you computed the complexity is $O(n^2)$. Another important observation is that the complexity on this particular type of tree is $\Omega(n^2)$. If you take a perfectly balanced complete tree, then then the root n...
# Table of Contents I will divide my explanation of [Tarjan][1]'s pseudocode into the following sections: 1. **Tarjan's If-else Blocks (the `->` & `|` operators)** 2. **Assignment and Equality Tests (`:=` and `=`)** 3. **There is `else if`, but no `else` construct** 4. **Tarjan's Conditiona...
null
I know that there is another topic about this question. But my question is ore specific to a certain algorithm that I wrote and I'd like to know more about it's complexity (since I am not good in this subject). Here is my algorithm with inputs $a$, which is an integer and $n$, which is an odd natural. And right afte...
Time complexity of Jacobi symbol
|complexity-theory|time-complexity|
The assumption that the output is one bit does not actually simplify matters - the proof is easier for machines that can output strings. Let $U_M$ be the machine which simulates the machine $M$ and outputs the protocol of computation of $M$ (the sequence of successive configurations of $M$ until it halts). If $M$ do...
The decision version of the problem [Integar Linear Programming](https://en.wikipedia.org/wiki/Integer_programming) is the following: - Input: two matrices $A\in \mathcal{M}_n(\mathbb{Z})$ and $B\in \mathcal{M}_{n,1}(\mathbb{Z})$. - Question: is there a matrix $X\in \mathcal{M}_{n,1}(\mathbb{Z})$ such that $AX\leqsla...
Why is Integer Linear Programming in NP?
|np|discrete-mathematics|linear-programming|
As pointed out in the comments, your question was already answered in [Arithmetic network to compute floor of binary logarithm](https://cs.stackexchange.com/questions/84496). If you turn that answer into a circuit diagram, it looks like this: [![enter image description here][1]][1] The 32 bit logarithm block show...
The assumption that the output is one bit does not actually simplify matters - the proof is easier for machines that can output strings. Let $U_M$ be the machine which simulates the machine $M$ and outputs the protocol of computation of $M$ (the sequence of successive configurations of $M$ until it halts). If $M$ do...
If I gave you a solution, you would be able to check it in polynomial time. That's what NP means: It is a decision problem, and if the answer is YES, then I can give you information that lets you verify that the answer is YES. Finding that information (in this case: Finding a solution) may be hard. Also, if there i...
The decision version of the problem [Integar Linear Programming](https://en.wikipedia.org/wiki/Integer_programming) is the following: - Input: two matrices $A\in \mathcal{M}_n(\mathbb{Z})$ and $B\in \mathcal{M}_{n,1}(\mathbb{Z})$. - Question: is there a matrix $X\in \mathcal{M}_{n,1}(\mathbb{Z})$ such that $AX\leqsla...
The proof in question is based on a Wikipedia [page][1] at the time of posting. However, the conclusion that the cycle contains edges that do not belong to F is inaccurate, instead the cycle contains edges that do not belong to F + e. The conclusion that f also belongs to T is also unexplained, which is that f belongs ...
The proof in question is based on a Wikipedia [page][1] at the time of posting. However, the conclusion that the cycle contains edges that do not belong to F is inaccurate, instead the cycle contains edges that do not belong to F + e. The conclusion that f also belongs to T is also unexplained, which is that f belongs ...
There indeed aren't a lot of situations where _any_ binary extension field would work but _no other_ finite field would. In fact, I can't think of any off the top of my head. Usually, you either need a _specific_ field (and often a specific representation of that field, as with [AES](https://en.wikipedia.org/wiki/Fin...
The proof in question is based on a Wikipedia [page][1] at the time of posting. However, the conclusion that the cycle contains edges that do not belong to F is inaccurate, instead the cycle contains edges that do not belong to F + e. The conclusion that f also belongs to T is also left unexplained, which is because f ...
As you have seen in other sources, the proof that there exists a witness with polynomial size does not exactly fit inside the margin, so to speak. The proof I know of (from the book I mention below) depends heavily on the mathematics of linear inequalities and polyhedra, and I expect this to be the case for most proofs...
The proof in question is based on a Wikipedia [page][1] at the time of posting. However, the conclusion that the cycle contains edges that do not belong to $F$ is inaccurate, instead the cycle contains edges that do not belong to $F + e$. The conclusion that $f$ also belongs to $T$ is also left unexplained, which is be...
null
The proof in question is based on a Wikipedia [page][1] at the time of posting. However, the conclusion that the cycle contains edges that do not belong to $F$ is inaccurate, instead the cycle contains edges that do not belong to $F + e$. The conclusion that $f$ also belongs to $T$ is also left unexplained, which is be...
As we know, if we want to make a $LR(0)$ (say) parsing table for a context free grammar (CFG), we prepare the $LR(0)$ itemsets with $.$ (dot) in RHS of the CFG production. <P> With this $.$ we keep track of characters that compiler has seen yet, and continue to make states of these itemsets, which ultimately make a de...
What does the language of DFA of LR itemsets represent?
|finite-automata|context-free|compilers|
Given an undirected graph, two vertices s and t, and two integers k,l - what is the complexity of the problem in the title? (Internally disjoint means vertex disjoint except for s and t.) I know that deciding wether there is a certain amount of edge- or vertex disjoint paths can be solved polynomially with max flow al...
Are there l edge-disjoint s-t-paths such that at least k of them are internally disjoint? Complexity
|algorithms|complexity-theory|graphs|np-hard|path|
There are no obvious integers involved in an instance of the $K$-coloring problem (where $K$ is part of the problem and not of the input). The length of the encoding of an instance of $K$-coloring is the length of the encoding of the graph. The [standard reduction from 3-SAT](https://homes.cs.washington.edu/~anuprao...
Given an undirected graph, two vertices s and t, and two integers k,l - what is the complexity of the problem in the title? (Internally disjoint means vertex disjoint except for s and t.) I know that deciding wether there is a certain amount of edge- or vertex disjoint paths can be solved polynomially with max flow al...
null
null
The decision version of the problem [Integar Linear Programming](https://en.wikipedia.org/wiki/Integer_programming) is the following: - Input: two matrices $A\in \mathcal{M}_n(\mathbb{Z})$ and $B\in \mathcal{M}_{n,1}(\mathbb{Z})$. - Question: is there a matrix $X\in \mathcal{M}_{n,1}(\mathbb{Z})$ such that $AX\leqsla...
Given an undirected graph, two vertices $s$ and $t$, and two integers $k$,$l$ - what is the complexity of finding $\ell$ edge-disjoint $s$-$t$-paths such that at least $k$ of them are internally disjoint? Being internally disjoint means that the paths are vertex disjoint except for $s$ and $t$. I know that deciding ...
Are there $\ell$ edge-disjoint $s$-$t$-paths such that at least $k$ of them are internally disjoint? Complexity
null
You have many memory pages - thousands 20 years ago, possibly millions today. When the next instruction is not in RAM, it is loaded for example from disk. Some other page of memory will be thrown out. However it is very, very unlikely that the page with the previous instruction is thrown out, because the OS will th...
When a CPU needs to get more instructions from storage and copies them to RAM, how does the CPU jump to previous instructions that are no longer in the RAM? Would it have to copy the old instructions back into RAM? I feel like that would take a very long time to do. FOR EXAMPLE: this is storage xsxx xxax. Pret...
When a CPU copies instructions from storage into RAM how does it jump to instructions no longer in RAM?
|computer-architecture|cpu|paging|storage|memory-hierarchy|
null
null
null
The binary extension field, usually denoted as $\textsf{GF}(2^n)$ or $\mathbb{F}_{2^n}$, is a finite field of characteristic 2. > **Are there any applications of $\textsf{GF}(2^n)$ (or more broadly, $\textsf{GF}(p^n)$), for $n>1$, in computer science?** My impression is that most applications only require a suf...
null
null
I recently had an interview to identify all of the hazards in the following instruction set. I was told by the interviewer that there was some hazard between instructions i3 and i4 and it's not a RAW hazard on R4 so I'm a little lost. Any insight? Thanks! ``` 1: ADD R1, R2, R3 2: ADD R4, R5, R1 3: LOAD R4, R3(src a...
Load Store Hazard
|computer-architecture|instruction-set|
The decision version of the problem [Integar Linear Programming](https://en.wikipedia.org/wiki/Integer_programming) is the following: - Input: two matrices $A\in \mathcal{M}_n(\mathbb{Z})$ and $B\in \mathcal{M}_{n,1}(\mathbb{Z})$. - Question: is there a matrix $X\in \mathcal{M}_{n,1}(\mathbb{Z})$ such that $AX\leqsla...
null
null
|data-structures|optimization|computational-geometry|trees|
null
Recently, when I self-learnt Discrete Mathematics and Its Applications 8th by Kenneth Rosen, I had some questions about some statements in it. > Fur- thermore, if a polynomial worst-case time complexity algorithm were discovered for the traveling salesperson problem, many other difficult problems would also be solv...
How can the approximation algorithm of one NP-complete problem be used to prove "the class P would be the same as the class NP"?
|complexity-theory|np-complete|np|p-vs-np|
Recently, when I self-learnt Discrete Mathematics and Its Applications 8th by Kenneth Rosen, I had some questions about some statements in it. > Fur- thermore, if a polynomial worst-case time complexity algorithm were discovered for the traveling salesperson problem, many other difficult problems would also be solv...
Recently, when I self-learnt Discrete Mathematics and Its Applications 8th by Kenneth Rosen, I had some questions about some statements in it. > Fur- thermore, if a polynomial worst-case time complexity algorithm were discovered for the traveling salesperson problem, many other difficult problems would also be solv...
null
In the wikipedia page for the NP-intermediate complexity class, the following observation is made: > Under the assumption that P β‰  NP, Ladner explicitly constructs a problem in NPI, although this problem is artificial and otherwise uninteresting. It is an open question whether any "natural" problem has the same prop...
Example of an NP-intermediate problem
|graphs|np-complete|succinct-data-structures|np-intermediate|
Assume that a matrix $M\in [0;1]^{n\times d}$ is given, i.e., all values in the matrix are in the range 0 to 1. I would like to compute the following function for all rows of $M$: $$ f(m_1,m_2,...,m_d)=\frac{1}{n}\sum_{i=1}^{n} \begin{cases}1 \quad \text {if} \quad M[i,j] \le m_j \text{for all} j\\ 0\quad \text{el...
Efficient way of computing average ALL function over matrix rows
|dynamic-programming|
Assume that a matrix $M\in [0;1]^{n\times d}$ is given, i.e., all values in the matrix are in the range 0 to 1. I would like to compute the following function for all rows of $M$: $$ f(m_1,m_2,...,m_d)=\frac{1}{n}\sum_{i=1}^{n} \begin{cases}1 \quad \text {if} \quad M[i,j] \le m_j \text{for all} j\\ 0\quad \text{el...
In the [wikipedia page for the NP-intermediate complexity class][1], the following observation is made: > Under the assumption that P β‰  NP, Ladner explicitly constructs a problem in NPI, although this problem is artificial and otherwise uninteresting. It is an open question whether any "natural" problem has the same...
Is this an example of a natural, strictly NP-intermediate language?
In the [wikipedia page for the NP-intermediate complexity class][1], the following observation is made: > Under the assumption that P β‰  NP, Ladner explicitly constructs a problem in NPI, although this problem is artificial and otherwise uninteresting. It is an open question whether any "natural" problem has the same...
In the [wikipedia page for the NP-intermediate complexity class][1], the following observation is made: > Under the assumption that P β‰  NP, Ladner explicitly constructs a problem in NPI, although this problem is artificial and otherwise uninteresting. It is an open question whether any "natural" problem has the same...
In the [wikipedia page for the NP-intermediate complexity class][1], the following observation is made: > Under the assumption that P β‰  NP, Ladner explicitly constructs a problem in NPI, although this problem is artificial and otherwise uninteresting. It is an open question whether any "natural" problem has the same...
Is this an example of a natural, strictly NP-intermediate language (assuming P β‰  NP)?
null
In the [wikipedia page for the NP-intermediate complexity class][1], the following observation is made: > Under the assumption that P β‰  NP, Ladner explicitly constructs a problem in NPI, although this problem is artificial and otherwise uninteresting. It is an open question whether any "natural" problem has the same...
(Given a graph $G$ with $|V|=n,|E|=m, max(c(a,b))=C$ and with integer capacities) Dinic's algorithm with scaling is defined the following way: 1. set $\Delta$ = C; 2. run Dinic's algorithm, only allowing augmenting $\geq\Delta$ at a time (at any point, if edge we're looking at in the created DAG is $<\Delta$, dele...
Prove that Dinic's algorithm with scaling works in O(nmlogC)
|network-flow|
(Given a graph $G$ with $|V|=n,|E|=m, max(c(a,b))=C$ and with integer capacities) Dinic's algorithm with scaling is defined the following way: 1. set $\Delta = C$; 2. run Dinic's algorithm, only allowing augmenting $\geq\Delta$ at a time (at any point, if edge we're looking at in the created DAG is $<\Delta$, dele...
Prove that Dinic's algorithm with scaling works in $O(nmlog(C))$
null
In the [wikipedia page for the NP-intermediate complexity class][1], the following observation is made: > Under the assumption that P β‰  NP, Ladner explicitly constructs a problem in NPI, although this problem is artificial and otherwise uninteresting. It is an open question whether any "natural" problem has the same...
I have to find 2 efficient ways to sort 1000 exams according to the students' last names. The task has to be divided between m teachers. I think one efficient way is to give each teacher a range of letters, for example one teacher has to sort the exams with the last names from A to D, the other one from E to H and so ...
Sorting exams dividing the task between m teachers
|sorting|