instruction
stringlengths
0
29.8k
⌀
|graphs|time-complexity|
I'm referencing this Leetcode question: https://leetcode.com/problems/cheapest-flights-within-k-stops/solution/, which asks you to find the length of the shortest path from source to dest using less than or equal to K intermediate nodes. Since the solution is behind a paywall, I've taken screenshots of the solution...
**Definitions**: Let $n \in \mathbb{N}$. If $\alpha$ and $\beta$ are propositional formulas, then we'll call $\alpha$ and $\beta$ *independent* if neither implies the other, or more formally, if $\lnot (\alpha \rightarrow \beta)$ and $\lnot(\beta \rightarrow \alpha)$. The notation $|\phi|$ refers to the length o...
null
**Definitions**: Let $n \in \mathbb{N}$. If $\alpha$ and $\beta$ are propositional formulas, then we'll call $\alpha$ and $\beta$ *independent* if neither implies the other, or more formally, if $\lnot (\alpha \rightarrow \beta)$ and $\lnot(\beta \rightarrow \alpha)$ are each satisfiable, perhaps under different...
Zero in 1's complement is the same as zero in normal binary `0000 00000` but there's a weird quirk of 1's complement. In 1's complement you can get the negative version a number by flipping all of its bits so that means you can flip all the bits in zero to get `1111 1111` which has a value of -0. 2's complement avo...
I try to find the time complexity of following recurrence: $$T(n) = 3T(n-2) + n$$ After subtitution,I get: $$T(n)=3^{\frac{n}{2}}T(0)+\sum_{i=0}^{\frac{n}{2}-1}3^i(n-2i)$$ I wonder if the ans is $\Theta(3^{\frac{n}{2}})$ or $\Theta(3^{\frac{n}{2}} n)$, can someone give a help to determine the ans and give a proo...
Find time complexity of $T(n)=3T(n-2)+n$
|time-complexity|asymptotics|recurrence-relation|
I try to find the time complexity of following recurrence relation: $$T(n) = 3T(n-2) + O(n)$$ After subtitution,I get: $$T(n)=3^{\frac{n}{2}}T(0)+\sum_{i=0}^{\frac{n}{2}-1}3^iO(n-2i)$$ I wonder if the ans is $O(3^{\frac{n}{2}})$ or $O(3^{\frac{n}{2}} n)$, can someone give a help to determine the ans and give a p...
Find time complexity of $T(n)=3T(n-2)+O(n)$
I am having trouble answering the question below: "Explain why the statement, “The running time of algorithm A is at least O(n^2)”, is content-free." The statement apparently does not give any information on the running time of A but if A = T(n), then T(n) >= O(n^2). Doesn't this at the very least tell us that A ...
Time complexity and content free evaluation
|time-complexity|
null
Recurrence relations do not have time complexities, algorithms do. That said, assuming $T(1)=O(1)$ and $T(2)=O(1)$, both $T(n)=O(3^{n/2})$ and $T(n)=O(3^{n/2} n)$ are true. Indeed: $$ T(n) = 3T(n-2)+O(n) =3^i T(n-2i) + \sum_{j=0}^{i-1} 3^j O(n-2j) \quad \text{for }i<n/2, $$ choosing $i=\lfloor n/2 \rfloor - 1 ...
As suggested by [Steven](https://cs.stackexchange.com/users/6759/steven), I turned my comment into a full answer. I think the question aims to point out that for a constant running time $c$ you have $c \in \mathcal{O}(1) \subseteq \mathcal{O}(n^2)$. So you might interpret the statement in your exercise as *"Ther...
So I was reading the use complement operation in the digital logic and found, it is used to give additive inverse of the number and subtracting a number (like we do) is difficult for computer. So it adds the negative representation of the number, which is $a - b = a + (-b)$. Now both complement's used to represent t...
Why is 2's complement used for representing negative numbers?
|binary|digital-circuits|bit-manipulation|
As you said, one's complement wastes one configuration of bits. Moreover, it requires additional logic to handle the two representations of zero. It also requires a more complex (hardware) implementation of addition when the operands have different signs (in two's complement the addition implementation is exactly th...
**TL;DR: I'm looking for the fastest known algorithm to perform optimal register allocation (optimal in the sense of minimizing the number of spills and reloads) for straight-line programs.** ### Context I am working on an optimized implementation of certain computational kernels. I have a code generator which ou...
State of the art in register allocation for straight-line programs
|algorithms|optimization|compilers|program-optimization|resource-allocation|
This question considers the design of a deterministic self-stabilizing algorithm for vertex coloring in uniform anonymous networks. Uniform anonymous networks do not have distinguished nodes and all nodes run identical programs without access to globally unique node identifiers. The problem vertex coloring requires the...
Why is there no self-stabilizing determinsitic algorithm for vertex coloring in general graphs?
|algorithms|graphs|distributed-systems|colorings|
I am looking for an algorithm similar to the [unweighted maximum coverage](https://www.geeksforgeeks.org/maximum-coverage-problem/). However, I have been unable to find a similar algorithm for the weighted version. How should I modify the algorithm above to take into account the weighted version whereby each element...
Maximum Weighted coverage approximation algorithm?
|complexity-theory|np-complete|combinatorics|set-cover|
Microsoft COM, in its object RPC part, had a peculiar mechanism that could be used to prohibit concurrent calls to the same object (or another object serviced by the same event loop) but permit callbacks. When a COM call first crosses an process boundary, it is assigned a unique identifier called a *causality ID* or...
Prior or subsequent art for Microsoft COM’s “causality IDs”
|reference-request|distributed-systems|concurrency|object-oriented|
null
I read [here](https://stackoverflow.com/a/53380316/16217248) that the reason that `intptr_t` and `uintptr_t` are optional in C is because there might be a platform where pointers are much bigger than any built-in integer type. They specifically cite some platforms with 128-bit pointers. However a 128-bit pointer see...
What is the reason or motivation for having 128-bit pointers?
|virtual-memory|
Given an $m\times n$ matrix $M_{ij}$ where $M_{ij}\in\{0,1\}$, find the minimal range $[a,b]$ for $1 \leq a \leq b \leq n$ such that each column has at least one value set to $1$ within that window, i.e. $\sum_{i=a}^bM_{ij} \geq 1$ for each $j \in \{1\dots n\}$. I have come across this real-world problem that I have...
Yes, it can be done in polynomial time, but the proof is quite subtle. It's not simply $\mathcal{O}(n^3)$ time, because Gaussian elimination involves multiplying and adding numbers, and the time to perform each of those arithmetic operations is dependent on how large they are. For some matrices, the intermediate value...
null
Questions about changing input graphs or finding efficient algorithms and data structures to answer a certain query about the graph each time the input graph is modified
null
I am writing this CFG to solve the problem: $S \to ASBSC$ $A \to aAe ~|~ ε$ $B \to aBd ~|~ ε$ $C \to bcC ~|~ ε$ Is this correct or not?
CFG for the given language $L = \{~ a^\ell a^n b^m c^m d^n e^\ell ~|~ \ell,n,m \geq 0 \}$
null
|formal-grammars|compilers|
null
Is this a minimal overfitting or like unpresensitive train dataset? However, I read it on the net but still have a problem with the graph! And then I read the following text on the net and again I asked myself is it an unpresensitive validation dataset isn't it? "An unrepresentative validation dataset means that t...
null
Intuitively, you can think of a binary indexed tree as a compressed representation of a binary tree that is itself an optimization of a standard array representation. This answer goes into one possible derivation. Let's suppose, for example, that you want to store cumulative frequencies for a total of 7 different e...
null
I have recently implemented the Paull's algorithm for removing left-recursion from context-free grammars: > Assign an ordering $A_1, \dots, A_n$ to the nonterminals of the grammar. > > for $i := 1$ to $n$ do begin > $\quad$ for $j:=1$ to $i-1$ do begin > $\quad\quad$ for each production of the form $A_i \to...
null
FPGA code is just another kind of code, and it's convertible. I guess if you're making a real machine, it could be written in C, but I'm doing one now and I'm just using **sub-procedures in place of the electric modules**, and it seems to be like it could work, and you can even do it on the GPU to get that awesome s...
null
I found this: [Sung Eun Bae, Sequential and Parallel Algorithms for the Generalized Maximum Subarray Problem][1]. Read pages 18-30, where it says that there are just cubic $O(nm^2)$ and sub-cubic algorithms for this problem (in general case), for example [Tadao Takaoka][2]'s $O\left(n^3 \sqrt{\frac{\log\log n }{\log n ...
null
I'm referencing this Leetcode question: https://leetcode.com/problems/cheapest-flights-within-k-stops/solution/, which asks you to find the length of the shortest path from source to dest using less than or equal to K intermediate nodes. Since the solution is behind a paywall, I've taken screenshots of the solution...
My question relates to the conclusions drawn from the Halting Problem. I understand that the Halting Problem proves that no program H(P,i) exists that determines if P(i) halts or not for P in *general*. However, I think that this does not show that there is no program H<sub>N</sub>(P,i) that computes the Halting proble...
What is the strength of the claim proved by the Halting Problem?
|turing-machines|undecidability|halting-problem|decidability|
A program that solves the Halting Problem for programs with N states
My question relates to the conclusions drawn from the Halting Problem. I understand that the Halting Problem proves that no program H(P,i) exists that determines if P(i) halts or not for P in *general*. However, I think that this does not show that there is no program H<sub>N</sub>(P,i) that computes the Halting proble...
The main reason is that there needs to be no special handling to perform arithmetic with negative numbers. The hardware does not need to check the sign bit and inverse the operation (add becomes subtract and subtract becomes add) if the sign bit is set as would be necessary with Sign & Magnitude. So **why** does Two...
Given an $m\times n$ matrix $M_{ij}$ where $M_{ij}\in\{0,1\}$, find the minimal range $[a,b]$ for $1 \leq a \leq b \leq m$ such that each column has at least one value set to $1$ within that window, i.e. $\sum_{i=a}^bM_{ij} \geq 1$ for each $j \in \{1\dots n\}$. I have come across this real-world problem that I have...
{"OriginalQuestionIds":[118770],"Voters":[{"Id":-1,"DisplayName":"Community","BindingReason":{"DuplicateApprovedByAsker":""}}]}
> We have recurrence $T(n)=2T(\dfrac{n}{2})+\mathcal{O}(n\log{n})$ and > assume $T(1)$ is a constant. Find asymptotically tight bounds > $\Theta(f(n))$ for $T(n)$. There's something that confuses me. We know $\{n\log{n}, n, \sqrt{n}\}\subset \mathcal{O}(n\log{n})$. So with Master Theorem applied: * if $T(n)=2T(\d...
find $f(n)$ for recurrence $T(n)=2T(\dfrac{n}{2})+\mathcal{O}(n\log{n})=\Theta(f(n))$
|time-complexity|algorithm-analysis|asymptotics|recurrence-relation|master-theorem|
null
Say you have a segment defined by 2 points $a,b$ and a third point $p$. You want to know the distance from $p$ to the midpoint of the edge. This is very straightforward: $$d = \|\frac{a - b}{2} - p\|$$ I am wondering if it is possible to do this faster. Asymptotically you cannot do better than $O(n)$ but I won...
Fast measurement of distance from point to mid segment?
|computational-geometry|discrete-mathematics|triangulation|
null
You are right, you can't find a tight bound with those hypotheses. I think you should interpret the question as: > find $f(n)$ for recurrence $T(n)=2T(\dfrac{n}{2})+\Theta(n\log{n})=\Theta(f(n))$ In this case, your first relation gives the right answer ($f(n) = n(\log n)^2$). Also, as noted in the comment, yo...
Evaluate WP(a = i + 2; i=i+1, ((a=6)^(i=5)) WP(x=x+1,y=y-1. (xxy>0)) wp(if x > 2 then y = 1 else y = -1,(x > 0)) wp(while n <> 0 do n:=n-1; n = 10) wp(while n = 0 do n:=n-1; n=-10) wp(while n <> 0 do n:=n-1; n=-10)
Evaluate under Hoare logic
|formal-methods|software-engineering|hoare-logic|
What is the difference between [abstract machines][1] and [automata][2]? Looking at the respective Wikipedia pages, only automata has a rigorous (mathematical) definition – abstract machines does not. And I can't find any source that clearly distinguishes the two; many sources leave it unclear as to whether there are a...
What is the difference between abstract machines and automata?
|automata|
What is the difference between [abstract machines][1] and [automata][2]? Looking at the respective Wikipedia pages, only automata has a rigorous (mathematical) definition – abstract machines does not. And I can't find any source that clearly distinguishes the two; many sources leave it unclear as to whether there are a...
What is the difference between [abstract machines][1] and [automata][2]? Looking at the respective Wikipedia pages, only automata has a rigorous (mathematical) definition – abstract machines does not. And I can't find any source that clearly distinguishes the two; many sources leave it unclear as to whether there are a...
Pointers don't have to be just memory addresses. Pointers with extra information are known as "fat pointers" and have various uses. A bounds-checked C implementation may use pointers that contain the start and end addresses of the array into which they point. Judging by [this comment](https://news.ycombinator.com/it...
I'll solve a simpler recurrence, $$T(n) = 4T(n/2) + n,$$ but the point is the same, namely that your _induction hypothesis is too weak_. We show something stronger: $T(n) \leq c \cdot n^2 - dn$ for some $d$. (!!) So, by induction, we want to show that $T(n) \leq cn^2 - dn$, and we'll set $d$ at the end. **Ind...
null
null
null
Your string has k bit changes where bit i and bit i+1 are different. You reduce the number of bit changes by 1 by inverting the first I+1 bits. So that gives you a way to make all bits equal. Then you need to prove that as long as you don’t invert the first I+1 bits the bit change from but I to I+1 will remain, so ...
null
A very simple and straightforward mechanism is to have the PC update automatically in a combinatory fashion, as soon as the cycle of the instructrion start: we design the system to pass the content of the PC to the memory address register and simultaneously to an adder, the output of wich is forward in input to the PC...
A very simple and straightforward mechanism is to have the PC update automatically in a combinatory fashion, as soon as the cycle of the instructrion start: we design the system to pass the content of the PC to the memory address register and simultaneously to an adder, the output of wich is forward in input to the PC...
You can not store something inside the OS. The OS is a program, or better a set of programs designed to manage a machine. Same as any other program, the data used during execution are stored inside the RAM, at least during their use. The OS interacts in a special way with a computer memory, having at his disposale...
A very simple and straightforward mechanism is to have the PC update automatically in a combinatory fashion, as soon as the cycle of the instructrion start: we design the system to pass the content of the PC to the memory address register and simultaneously to an adder, the output of wich is forward in input to the PC...
I've been experimenting with making a binary calculator lately, and I've got the addition and subtraction working. I now want to start making a multiplier, but I have no idea where to even start. I know how to multiply two binary numbers. After all, it's the same as how we used to learn how to multiply. Observe this `-...
How do I multiply 2 signed 4 bit numbers in a logic circuit?
|arithmetic|binary|multiplication|
null
Say you have a segment defined by 2 points $a,b$ and a third point $p$. You want to know the distance from $p$ to the midpoint of the edge. This is very straightforward: $$d = \|\frac{a + b}{2} - p\|$$ I am wondering if it is possible to do this faster. Asymptotically you cannot do better than $O(n)$ but I won...
I'm intending on writing a program to let my friends make pairwise comparisons of computer generated images, ranking them. I'm mostly doing this for fun and to do some learning and I picked computer generated images because they are easy to come by. And also as I came a cross a thought experiment/problem I funny how go...