instruction stringlengths 0 29.8k ⌀ |
|---|
null |
null |
null |
is I understand correct if I write in computer code with
1.)
def a(n):
if n == 0:
return 1
return a(n-1)+a(n-1)
2.)
def b(n):
if n == 0:
return 1
return 2 * b(n-1)
Is my understanding correct that the time co... |
T(n) = T(n-1) + T(n-1) vs T(n) = 2*T(n-1) |
|time-complexity| |
is I understand correct if I write in computer code with
1.)
def a(n):
if n == 0:
return 1
return a(n-1)+a(n-1)
2.)
def b(n):
if n == 0:
return 1
return 2 * b(n-1)
Is my understanding correct that the time co... |
is I understand correct if I write in computer code with
1.)
def T(n):
if n == 0:
return 1
return T(n-1)+T(n-1)
2.)
def T(n):
if n == 0:
return 1
return 2 * T(n-1)
Is my understanding correct that the time co... |
is I understand correct if I write in computer code with
1.)
def T(n):
if n == 0:
return 1
return T(n-1)+T(n-1)
2.)
def T(n):
if n == 0:
return 1
return 2 * T(n-1)
Is my understanding correct that the time complexity of the first fun... |
If I have 2 version of code
1.)
def T(n):
if n == 0:
return 1
return T(n-1)+T(n-1)
2.)
def T(n):
if n == 0:
return 1
return 2 * T(n-1)
Is my understanding correct that the time complexity of the first function is O(2^n) and the seco... |
Yes, the running time of the first is $\Theta(2^n)$ unless you have tail-call optimization or you do memoization.
The running time of the first is $\Theta(n)$.
Beware that the _input size_ is actually $\log_2 n$ which would make the latter function actually run in time $O(2^{\left| x \right|})$ where $x$ is the s... |
Taking an example, say we have Page size = 4KB, Page Table Entry = 4B, Physical Address Space requires 36 bits
In 3-level multi-paging, let's say the number of entries in the level 3 page table is 2^9 (so the size of this page table would be 2^9 * 4B = 2^11 B )
In level 2, there are 2^9 entries as well and finally... |
Yes, the running time of the first is $\Theta(2^n)$ unless you have tail-call optimization or you do memoization.
The running time of the second is $\Theta(n)$.
Beware that the _input size_ is actually $\log_2 n$ which would make the latter function actually run in time $O(2^{\left| x \right|})$ where $x$ is the ... |
null |
null |
*Disclaimer: Practical performance questions are highly application-specific and can only be satisfyingly answered by application-specific benchmarks that sufficiently represent field conditions. This answer uses a synthetic benchmark instead, which may not at all be representative of Your specific application.*
A w... |
null |
null |
null |
I was thinking about whether $\{ 0^{a}10^{a}10^{a}|a\in\mathbb{N} \}$ is a context-free language, and I found [this post](https://cstheory.stackexchange.com/questions/42201/for-which-r-is-0a10b10c-mid-ra-b-c-context-free). I am not sure if my understanding is correct or not, but I guess $R = \{ (a,1,a,1,a)|a\in\mathb... |
Is $\{ 0^{a}10^{a}1 0^{a}|a \in \mathbb{N}\}$ a context free language? |
|formal-languages|context-free| |
null |
null |
null |
If I have an undirected graph with more than one connected component, can I apply the Gomory-Hu algorithm directly on the entire graph or do I have to apply it separately to each component? |
Can Gomory-Hu tree algorithm be applied to graphs with more than one connected component? |
|algorithms|graphs|network-flow|minimum-cuts| |
I have this language that I have to prove either regular or irregular.
$$
L_3 = \{mm^rn | m^r \text{ is the reverse of } m,\ m,n \in \{a,b\}^+\}
$$
It's trivial to prove that it is in fact irregular using Myhill-Nerode theorem. We let $S = \{ab,abab,ababab,\ldots\}$, and the suffix for two strings $s_1$ and $s_2$, ... |
How to prove this language is irregular without using Myhill-Nerode? |
|formal-languages|regular-languages| |
I have this language that I have to prove either regular or irregular.
$$
L_3 = \{mm^rn | m^r \text{ is the reverse of } m,\ m,n \in \{a,b\}^+\}
$$
It's trivial to prove that it is in fact irregular using Myhill-Nerode theorem. We let
$$S = \{ab,abab,ababab,\ldots\}$$, and the suffix for two strings $s_1$ and $s_... |
I have this language that I have to prove either regular or irregular.
$$
L_3 = \{mm^rn | m^r \text{ is the reverse of } m,\ m,n \in \{a,b\}^+\}
$$
It's trivial to prove that it is in fact irregular using Myhill-Nerode theorem. We let
$$S = \{ab,abab,ababab,\ldots\}$$, and the suffix for two strings $s_1$ and $s_... |
I was reading a book titled "Essentials of Logic Programming.", most parts of the book are easy to understand. but now having a problem with Theme 45: incremental constructions of the minimal model. The relevant parts are shown below.
Some notations: $P$ is a definite program, $B(P)$ is the Herbrand base of $P$, $G(... |
how to do incremental construction of the minimal model in logic programming? |
|programming-languages|logic|first-order-logic| |
What you present as the Binary GCD algorithm is *not* the Binary GCD algorithm, because it still uses the modulo (remainder) operator $\%$ (in fact it is the standard algorithm with the swap-via-xor trick, which probably makes it slower). This is unfair in the comparison as modulo is a costly operation. The real Binary... |
null |
From what I understand about the Y2K38 problem, unpatched 32 bit systems with signed UTC times will jump back from 19 January 2038 at 03:14:07 UTC to 13 December 1901, at 20:45:52. Calculating the difference between these date-times gives me 4294197095 seconds. That's not the same as 429967294 seconds, off by 770199 se... |
Missing 770199 seconds in Y2K2038 |
|real-time| |
I am presented with the following code segment and asked to find the growth rate, which can be done by finding the number of times the variable sum is incremented:
sum = 0
for i = 1 to 2 * n
for j = 1 to i * i
for k = 1 to j
sum++
I tried making this into a function called def run(n) in python that r... |
Finding growth rate of T(n) of a code segment |
|algorithms|time-complexity|algorithm-analysis| |
I am presented with the following code segment and asked to find the growth rate, which can be done by finding the number of times the variable sum is incremented:
sum = 0
for i = 1 to 2 * n
for j = 1 to i * i
for k = 1 to j
sum++
I tried making this into a function called def run... |
The innermost loop increments `sum` exactly $j$ times. The middle loop runs $i^2$ times with increasing values of $j$ so it increments `sum` $\dfrac{i^2(i^2+1)}2$ times. And finally, the outer loop runs $2n$ times, for a total of $$\sum_{i=1}^{2n}\frac{i^2(i^2+1)}2=\frac{n (1 + 2 n) (1 + 4 n) (2 + 3 n + 6 n^2)}{15}$$ i... |
Prove P ∨ Q, Q ∨ R, P → ¬R |- Q with natural deduction.
1. P ∨ Q, premiss
2. Q ∨ R, premiss
3. P → ¬R, premiss
...
...
Conclusion, Q
I dont know how to properly solve this question?
I know somewhat how to solve similar questions like below, but on this specific question above I dont know where to start.
... |
Prove with natural deduction |
|logic|natural-deduction| |
I am presented with the following code segment and asked to find the growth rate, which can be done by finding the number of times the variable sum is incremented:
sum = 0
for i = 1 to 2 * n
for j = 1 to i * i
for k = 1 to j
sum++
I tried making this into a function called `run(n)... |
Let $I$ be the number of times the `for i` is executed, $J$ the number of times `for j`, and $K$ the number of times `for k` is executed.
1. $I$ is $\Theta(n)$ times
2. $J$ is $\Theta(I \cdot I) = \Theta(n^2)$ times
3. $K$ is $\Theta(J) = \Theta(n^2)$
The correct answer is the product of $I$, $J$ and $K$, i.e.,... |
null |
null |
From what I understand about the Y2K38 problem, unpatched 32 bit systems with signed UTC times will jump back from 19 January 2038 at 03:14:07 UTC to 13 December 1901, at 20:45:52. Calculating the difference between these date-times gives me 4294197095 seconds. That's not the same as 429967294 seconds, off by 770201 se... |
Missing 770201 seconds in Y2K2038 |
I have some problems understanding the following 2 question from an exam last year, which I am preparing for this week in Parallel Programming.
[![DAG][1]][1]
Determine the Work -> $W(n) = 7$ (#vertices)
Determine the Depth -> $D(n) = 4$ (longest path)
Determine average parallelism -> $\frac{W(n)}{D(n)} = ... |
Work and depth of DAG - problem in understanding exam question |
|parallel-computing| |
I think you have an error in your math. 19 January 2038 at 03:14:07 UTC is $t_1 = 2147483647$ seconds after the epoch. 13 December 1901 at 20:45:52 is $t_2 = 2147483648$ seconds before the epoch.
Notice that $t_1 = 2^{31}-1$ and that $ - t_2 = -2^{31}$. That's exactly the minimum and maximum values representable by ... |
I have a function $f(x)$, has been sampled into a sequence
$$
y_0, y_1, ..., y_{n - 1}
$$
at points $x_k = k \Delta x$. $f(x)$ is neither smooth or monotone.
Under this assumption, what is the fastest way of finding
$$
\min_{k=0}^{n - 1}|P - (x_k, y_k)|
$$
where $P$ is an arbitrary point?
I could do a lin... |
An efficient way of finding the closest point of a sampled function to another point |
|computational-geometry| |
You can construct a [Voronoi diagram](https://en.wikipedia.org/wiki/Voronoi_diagram) for your points, and then use a [point location](https://en.wikipedia.org/wiki/Point_location) algorithm. Because you need quadratic work regardless you don't even need an efficient algorithm for the Voronoi diagram. |
null |
If You sample the function once beforehand, the problem breaks down to a simple [Nearest Neighbor Search](https://en.wikipedia.org/wiki/Nearest_neighbor_search). There are many different data structures and algorithms for solving the nearest neighbor problem.
As long as $x_k$ and $y_k$ are fairly low-dimensional, on... |
From what I understand about the Y2K38 problem, unpatched 32 bit systems with signed UTC times will jump back from 19 January 2038 at 03:14:07 UTC to 13 December 1901, at 20:45:52. Calculating the difference between these date-times gives me 4294197095 seconds. That's not the same as 4294967296 seconds, off by 770201 s... |
Set $n=2^m$. The recurrence now writes
$$T(2^m)=3T(2^{m-1})+2^mc+d$$ or
$$S(m)=3S(m-1)+2^mc+d.$$
A solution of the homogeneous recurrence ($S(m)=3S(m-1)$) is $S(m)=3^m$ and this makes us set, by variation of the constant
$$S(m)=3^mR(m),$$ giving
$$R(m)=R(m-1)+\frac{2^mc+d}{3^m}.$$
The solution is easi... |
Say there is someone claiming to have solved P vs NP, by finding a (computationally feasible, i.e. no huge constants) polynomial solution to a problem in NP:
Apart from a formal proof, is there any kind of challenge comparable to the [RSA Numbers][1], which could be used to "prove" (or at least give strong evidence)... |
Is there a challenge with which one could reasonably show to have found a feasible polynomial algorithm for an NP problem? |
|complexity-theory|p-vs-np| |
The answer you are looking for is:
(b|c)((b|c)(b|c))\*a((b|c)(b|c))\* | a(b|c((b|c)(b|c))\*)
Logic behind this is:
If you start with a, you need at least one more b|c and then as many b|c PAIRS as you want.
Otherwise you can start with b|c combinations making sure they are an odd number, add the 'a' later to make... |
null |
null |
null |
Without knowing You and Your personal situation, this question is almost impossible to answer. So all I can try to give is some general-purpose advice which hopefully gets You on the right track.
Get Enough Sleep
----------------
Thanks to modern Hustle Culture, bright white LED-lighting and bright-screened smartp... |
Without knowing You and Your personal situation, this question is almost impossible to answer. So all I can try to give is some general-purpose advice which hopefully gets You on the right track.
Get Enough Sleep
----------------
Thanks to modern Hustle Culture, bright white LED-lighting and bright-screened smartp... |
null |
I am searching for a program to convert 3sat to clique problem.
I tried following links
https://www.geeksforgeeks.org/maximal-clique-problem-recursive-solution/
https://www.geeksforgeeks.org/find-all-cliques-of-size-k-in-an-undirected-graph/
But it is not converting 3sat problem.
Is there any algorithm t... |
3sat to clique reduction program |
|p-vs-np|3-sat|clique|java| |
null |
Let 3-SAT formula $\phi$ be $C_1 \wedge C_2 \wedge \dots \wedge C_m$, where $C_i$ is a clause consisting of the disjunction of three literals: $(\ell_i^1 \vee \ell_i^2 \vee \ell_i^3)$.
We can create an auxiliary graph $G$ as follows:
- For each clause $C_i$ create three vertices $\ell_i^1, \ell_i^2, \ell_i^3$, i.e.... |
The proper search term in scientific journals is *"Rank-Revealing Decomposition"*. If You want some theoretic guarantees on numeric accuracy/stability, the search term would be *"Strong Rank-Revealing Decomposition"*. There seems to exist a (strong) rank-revealing version of almost every type of decomposition:
* R... |
null |
null |
I have been reading Cormen's chapter 11 and I stumbled upon the following statement on page 260 (3rd Edition):
Let xi denote the ith element inserted into the table, for i = 1, 2 ... n, and let ki = xi.key. For keys ki and kj , we define the indicator random variable Xij = I {h(ki) = h(kj)}. Under the assumption of... |
Cormen chapter 11 probability of two keys being assigned the same slot simple uniform hashing |
|probability-theory|hashing| |
null |
Let 3-SAT formula $\phi$ be $C_1 \wedge C_2 \wedge \dots \wedge C_m$, where $C_i$ is a clause consisting of the disjunction of three literals: $(\ell_i^1 \vee \ell_i^2 \vee \ell_i^3)$.
We can create an auxiliary graph $G$ as follows:
- For each clause $C_i$ create three vertices $\ell_i^1, \ell_i^2, \ell_i^3$, i.e.... |
Let 3-SAT formula $\phi$ be $C_1 \wedge C_2 \wedge \dots \wedge C_m$, where $C_i$ is a clause consisting of the disjunction of three literals: $(\ell_i^1 \vee \ell_i^2 \vee \ell_i^3)$.
We can create an auxiliary graph $G$ as follows:
- For each clause $C_i$ create three vertices $\ell_i^1, \ell_i^2, \ell_i^3$, i.e.... |
I wonder why can't I allow an exponential-time reduction from all problems in $\textbf{NEXP}$ to a language $L$ and claim $L$ to be $\text{NEXP-complete}$.
The computational complexity class $\text{NEXPTIME}$ or $\text{NEXP}$ has been defined [here][1]. In the same page, there is a section on $\text{NEXP-complete}$... |
EXP reduction to show NEXP-completeness |
|complexity-theory|reductions|polynomial-time-reductions| |
Let 3-SAT formula $\phi$ be $C_1 \wedge C_2 \wedge \dots \wedge C_m$, where $C_i$ is a clause consisting of the disjunction of three literals: $(\ell_i^1 \vee \ell_i^2 \vee \ell_i^3)$.
We can create an auxiliary graph $G$ as follows:
- For each clause $C_i$ create three vertices $\ell_i^1, \ell_i^2, \ell_i^3$, i.e.... |
Let 3-SAT formula $\phi$ be $C_1 \wedge C_2 \wedge \dots \wedge C_m$, where $C_i$ is a clause consisting of the disjunction of three literals: $(\ell_i^1 \vee \ell_i^2 \vee \ell_i^3)$.
We can create an auxiliary graph $G$ as follows:
- For each clause $C_i$ create three vertices $\ell_i^1, \ell_i^2, \ell_i^3$, i.e.... |
In finding a minimum spanning tree, if we use a BFS and at any node instead of deleting the edge to a repeated node, we can find the most expensive node in that cycle instead and delete it.
In such a case, will the time complexity remain O(E+V)? |
Minimum spanning tree using BFS |
|complexity-theory|graphs|time-complexity|minimum-spanning-tree| |
Ask for the name of the employee.
- If the employee is full time, get his monthly salary rate. Then, display his name and salary.
- If the employee is part time, get his rate per hour and the total number of hours he worked
for the entire month. Then, display his name and wage.
Hello guys, I am freshman... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.