instruction stringlengths 0 29.8k ⌀ |
|---|
|correctness-proof|loop-invariants| |
null |
My (attempt at a) proof is as follows:
$f\in o(g)$ means that $\forall c>0 \exists n_0 \forall n\geq n_0: f(n) \leq cg(n)\$
Now taking the complement we get: $\exists c>0 \forall n_0 \exists n\geq n_0: f(n) > cg(n)\$
Fixing some $c'$ satisfying the above and $n_0=0$ we get some $n_1 \geq 0$ where $f(n_1) > cg(... |
Is it true that: $f\notin o(g)$ implies $\exists c>0: f\geq cg$ infinitely often |
|algorithm-analysis|asymptotics| |
Is it true that: $f\notin o(g)$ implies $\exists c>0: f > cg$ infinitely often |
It is not true. The [state monad](https://wiki.haskell.org/State_Monad) expresses mutable state that can be used in a computation, and that is just one example.
A second example is [Frank Oles's PhD thesis](https://www.cs.cmu.edu/afs/cs.cmu.edu/project/fox-19/member/jcr/www/FrankOlesThesis.pdf), supervised by John R... |
null |
My (attempt at a) proof is as follows:
$f\in o(g)$ means that $\forall c>0 \exists n_0 \forall n\geq n_0: f(n) \leq cg(n)\$.
Now taking the complement we get: $\exists c>0 \forall n_0 \exists n\geq n_0: f(n) > cg(n)\$.
Fixing some $c'$ satisfying the above and $n_0=0$ we get some $n_1 \geq 0$ where $f(n_1) > c... |
|algorithms|algorithm-analysis|asymptotics| |
My (attempt at a) proof is as follows:
$f\in o(g)$ means that $\forall c>0 \exists n_0 \forall n\geq n_0: f(n) \leq cg(n)$.
Now taking the complement we get: $\exists c>0 \forall n_0 \exists n\geq n_0: f(n) > cg(n)$.
Fixing some $c'$ satisfying the above and $n_0=0$ we get some $n_1 \geq 0$ where $f(n_1) > cg(... |
I'm trying to read chapter one of the famous book : Structure and Interpretation of computer programs.
The chapter one starts with a mysterious paragraph:
> We are about to study the idea of a **computational process**.
> Computational processes are abstract beings that inhabit computers. **As
> they evolve... |
What is the meaning of the term "computational process" in the book SICP? |
|complexity-theory|computability| |
|algorithms|complexity-theory|computability| |
Computer programs are generally written to do something i.e. transform some input to some usually different output. That is the computational process that they are implementing. |
null |
Is it possible to prove the total number of parenthesizations of n matrices is Ω(4^n/n^3/2) ****using the Induction Method**?**
Recurrence formula from CLRS book
1) When n = 1, the sequence consists of just one matrix, and therefore there is only one way to fully parenthesize the matrix product.
2) When n ≥ 2, a f... |
Prove that the total number of parenthesizations of n matrices is Ω(4^n/n^3/2) |
|algorithms|dynamic-programming|recurrence-relation|matrices|induction| |
Is it possible to prove the total number of parenthesizations of n matrices is Ω(4^n/n^3/2) ****using the Induction Method**?**
Recurrence formula from CLRS book
1) When n = 1, the sequence consists of just one matrix, and therefore there is only one way to fully parenthesize the matrix product.
2) When n ≥ 2, a f... |
null |
I am struggling to find a good loop invariant for the following function, which returns a^b where a is a real number and b is a natural number:
power <- function(a, b){
c <- 1
while(b > 0){
if(b %% 2 == 1){
c <- c * a
}
b <- flo... |
It may clarify things to use different variable names. Let's call $x$ the desired result of $a^b$ where $a$ and $b$ are the inputs. With variables $c', a', b'$ initialized to $c' = 1, a'=a, b'=b$, you are basically maintaining that $x = c'(a')^{b'}$. At the end you have $x = c'$ because $b' = 0$. Each step "transfers" ... |
A question I was given
$T(0) = 1,$ $T(1)=0,$ $T(n)= 2T(n-2)$
I think the possible solution is $T(n)=2^n$
Proof: by induction. Base Case:
$n=0$ $T(0)=2^0=1$
Inductive Hypothesis: Assume for some $n$. $T(n)=2^n$
Show for $n+1$
$T(n+1)= 2(T(n-1))$
$=2(2^{n-1})$
$=2^n$
which is what I proposed. Is ... |
Recurrence Relation Proof check |
|recurrence-relation|check-my-answer| |
{"Voters":[{"Id":-1,"DisplayName":"Community"}]} |
null |
So I recently came across a question in my Algorithms class.
Given a binary matrix of **N X N**.
we can do following operation any number of times
- we can take a square of size M X M (1 <= M <= N) and convert all 1's to 0's in this submatrix this operation costs M coins
we have to convert all 1's to 0's i... |
These instructions aren't too bad:
https://www.howtogeek.com/830179/how-to-run-stable-diffusion-on-your-pc-to-generate-ai-images/
...but you'll do better by googling for install instructions specific to your OS. Stable Diffusion has different installer packages for Windows, OSX, and Linux, and getting instructions ... |
This can be verified using the [Master Theorem for decreasing functions][1]
The recurrence relation can be written as $T(n)=2T(n-2)+O(1)$.
Comparing with the general recurrence here $a=2$, $b=2, k=0$
Using Case 2 of the theorem we get $T(n)= O(2^{\frac{n}{2}}*n^0) = O(2^{\frac{n}{2}})$
Even if you don't k... |
The idea for this problem comes from [GATE CS 2014 Set-3 Q13][1].
Given a graph, are there any heuristics to figure out a DFS traversal which has minimum/maximum recursion depth.
Consider the graph from the question, labelled
[![Labelled graph][2]][2]
Consider the DFS traversal **a-b-c-f-e-d-g-h-i-j-k-l-m-... |
Minimizing/Maximizing recursion depth for DFS |
|graphs|data-structures|recursion|graph-traversal|depth-first-search| |
Computer programs are generally written to do something i.e. transform some input to some usually different output. That is the computational process that they are implementing.
Let's look at a concrete example. On unix there's a program named sort, the computational process it implements is sorting. There are vario... |
Unfortunately, I think that that there is a reduction from the [longest path problem](https://en.wikipedia.org/wiki/Longest_path_problem), which have $\mathsf{NP}$-complete decision version (finding the maximum depth is equivalent to finding the longest path between two vertices).
A possible approximation heuristic ... |
Unfortunately, I think that that there is a reduction from the [longest path problem](https://en.wikipedia.org/wiki/Longest_path_problem), which have a $\mathsf{NP}$-complete decision version (finding the maximum depth is equivalent to finding the longest path between two vertices).
A possible approximation heuristi... |
null |
Since your pivot value is 5, the comparison with A[7] and A[8], which are both 5, will be `=pval`.
While you didn't share the pseudocode you used, I believe you used a while loop for incrementing/decrementing the pointers. This means the pointers will just be stuck at A[7] and A[8] as they do not satisfy the expres... |
null |
null |
Define $M = \max(|a_0|/a_m, |a_1|/a_m, \ldots, |a_{m-1}|/a_m)$, and take $c = a_m/2$ and $n_0 = 2mM$. Then for $n \geq n_0$,
$$
\begin{align*}
f(n) &= a_m n^m \left(1 + \frac{a_{m-1}}{a_m} \cdot \frac{1}{n} + \cdots + \frac{a_1}{a_m} \cdot \frac{1}{n^{m-1}} + \frac{a_0}{a_m} \cdot \frac{1}{n^m}\right) \\ &\geq
a_m ... |
null |
Define $M = \max(|a_0|/a_m, |a_1|/a_m, \ldots, |a_{m-1}|/a_m)$, and take $c = a_m/2$ and $n_0 = 2mM$.
Then for $n \geq n_0$,
$$
\begin{align*}
f(n) &= a_m n^m \left(1 + \frac{a_{m-1}}{a_m} \cdot \frac{1}{n} + \cdots + \frac{a_1}{a_m} \cdot \frac{1}{n^{m-1}} + \frac{a_0}{a_m} \cdot \frac{1}{n^m}\right) \\ &\geq
a_m... |
I think your question is better written as follows (to avoid ambiguity):
Find an order $\mathbf{s}=(s_1,s_2,...s_n)$ (that is, a permutation of $(1,...,n)$) such that
$$
E_{\mathbf{s}}(\mathbf{v},\mathbf{p})=p_{s_1}w_1v_{s_1}+(1-p_{s_1})p_{s_2}w_2v_{s_2}+\cdots+\left[\prod_{j=1}^{n-1}(1-p_{s_j})\right]p_{s_n}w_nv_{s... |
null |
Consider a DFA $A$ and $k\geq 0$. For states $q$ and $p$ of $A$, we say that $p\equiv_k q$ when $p$ and $q$ agree on all words of length at most $k$; that is, $p\equiv_k q$ when for all words $w$ of length at most $k$, it holds that $p$ has an accepting run on $w$ iff $q$ has an accepting run on $w$.
Then, we say that... |
|formal-languages|regular-languages|automata|finite-automata| |
null |
Consider a DFA $A$ and $k\geq 0$. For states $q$ and $p$ of $A$, we say that $p\equiv_k q$ when $p$ and $q$ agree on all words of length at most $k$; that is, $p\equiv_k q$ when for all words $w$ of length at most $k$, it holds that $p$ has an accepting run on $w$ iff $q$ has an accepting run on $w$.
Then, we say that... |
I can't seem to get a straight answer as to what a [CPU][1] clock is.
I know there are quartz crystal clocks that work by the bending of quartz that happens as an electrical current is passed through it. Do modern CPUs also use a crystal with the same property?
[1]: https://en.wikipedia.org/wiki/Central_proce... |
What is a CPU clock physically? |
null |
**Summary**:
A task for picking certain objects is given in the form of an ordered sequence (eg. to pick apple, banana, apple, apple, orange, order matters). The objects have to be preassigned to certain physical locations with all the pairwise distance being known and fixed. The question is how to efficiently find t... |
null |
Efficient sampling from all positive integers to find the largest integer below a transition for f(n) |
null |
We know
logical address contains: page number and page offset (page size)
physical address contains : number of frames and frame size
---
Logical address space contains 32 pages and to represent 32 pages we need 5 bits $2^5=32$.
Each page contains 2048 words therefore the offset or "d" parameter can be re... |
null |
null |
CLRS pseudocode:
begin
for each vertex u in G.V - {s}, do
u.color := white
u.d := infinity
u.p := NIL
done
s.color := green
s.d := 0
s.p := NIL
Q := NULL
insert s into Q
while Q is not null, do
u = d... |
Why is the complexity of BFS O(V+E) instead of O(V*E)? |
|complexity-theory|graphs|time-complexity|graph-traversal|big-o-notation| |
CLRS pseudocode:
begin
for each vertex u in G.V - {s}, do
u.color := white
u.d := infinity
u.p := NIL
done
s.color := green
s.d := 0
s.p := NIL
Q := NULL
insert s into Q
while Q is not null, do
u = d... |
The idea for this problem comes from [GATE CS 2014 Set-3 Q13][1].
Given a graph, are there any heuristics to figure out a DFS traversal which has minimum/maximum recursion depth?
Consider the graph from the question, labelled
[![Labelled graph][2]][2]
Consider the DFS traversal **a-b-c-f-e-d-g-h-i-j-k-l-m-... |
null |
Good question.
Suppose we have a positive function $T(n)$ such that
$$T(n) = a \cdot T\left(\frac{n}{b}\right) + f(n)$$
with $a \geq 1, b > 1$. You are referring to case $1$ of [the master theorem](https://en.wikipedia.org/wiki/Master_theorem_(analysis_of_algorithms)):
$\qquad$ If $f \in O( n^{\log_b (a) -... |
Show that the language $\{0^n1^m0^n| m,n\in \mathbb{N}\}$ is not regular using closure properties.
I tried showing this using pumping lemma but I am stuck when it comes to closure properties. Please help me out! |
Show non regularity of a language using closure property |
|regular-languages|pumping-lemma| |
I will suppose here that the graph is undirected, but the same reasonning can be done with a digraph.
Using an implemention of a graph as an array of adjacency lists, the adjacency list of any vertex $v$ is its number of neighbors, $\deg(v)$.
The BFS inspect each adjacency list at most once during the graph trave... |
I will suppose here that the graph is undirected, but the same reasonning can be done with a digraph.
Using an implemention of a graph as an array of adjacency lists, the adjacency list of any vertex $v$ is its number of neighbors, $\deg(v)$.
The BFS inspects each adjacency list at most once during the graph trav... |
Consider a data structure that has only two functions. extract_lowerthan_median() and insert(). How can we design it in a way that the amortized cost for both the operation is O(1)?
Using a 2 tree, a min heap and max heap will ensure that the root of min heap is always the median and allow us to extract an element s... |
Designing a Data Structure that allows both insertion and extracting a number lower than median in amoritzed O(1) cost? |
|algorithms|data-structures|amortized-analysis| |
null |
null |
null |
I am trying to understand what an algebraic decision tree is but wikipedia lacks a formal definition, just an intuition. So I need to check if my understanding is correct.
From what I have read it seems that an algebraic decision tree is:
* A tree where each node has exactly 2 children.
* Each node in the tre... |
Definition of an algebraic decision tree |
|complexity-theory|lower-bounds|decision-tree| |
**Spatial histogram.** A simple histogram is obtained by taking a region of an image, assigning a label to each pixel (somehow; via some mapping function), and then computing a histogram of the labels. The histogram counts, for each possible label, how many pixels received that label. You obtain a feature vector: a ... |
Honestly, the best and maybe simplest way to think about how to model data structures in proper mathematical form is to simply attempt to implement them in a functional language for which the resulting map from some space to another space may result in something familiar; whether it be groupoid, group, ring, monoid, ve... |
if we define halting problem as follows
$
\begin{align*}
h(m,n) &=
\begin{cases}
1 & if\;program\;m\;halts\;on\;input\;n \\
0 & otherwise \\
\end{cases}
\end{align*}
$
and we have two different sometimes correct solution $f$ and $g$ for $h$
then we can compute $h$ as follows
$
\... |
Let $v_1,…,v_n$ be a finite list of vectors in $ℝ^k$ (with $k ≪ n$, in my case $k≈10$ and $n≈4~000$). I would like to know if I can precompute something so that given a linear form $f : ℝ^k→ℝ$, I can quickly get the $i$ maximizing $f(v_i)$. If $k=2$, I can do that with a convex envelope and a binary search. But even fo... |
A data structure to quickly maximize a linear function on a fixed set of $k$-dimensional vectors |
|algorithms|computational-geometry| |
Let $v_1,…,v_n$ be a finite list of vectors in $ℝ^k$ (with $k ≪ n$, in my case $k≈10$ and $n≈4~000$). I would like to know if I can precompute something so that given a linear form $f : ℝ^k→ℝ$, I can quickly get the $i$ maximizing $f(v_i)$. If $k=2$, I can do that with a convex envelope and a binary search. But even fo... |
null |
I have seen many posts which were related to algorithms for solving an **N⨯N puzzle**, but I could not figure out the **time complexity** or **memory complexity** in these algorithms, especially when we want to apply `DFS` and `BFS`.
I will be grateful for a more detailed explanation of these algorithms when they a... |
How to determine the time and memory complexity for solving a sliding-tile puzzle? |
|artificial-intelligence|depth-first-search|breadth-first-search| |
I have seen many posts which were related to algorithms for solving an **N⨯N puzzle**, but I could not figure out the **time complexity** or **memory complexity** in these algorithms, especially when we want to apply `DFS` and `BFS` for solving our puzzle.
For example, if we assume that at first, the elements are no... |
I have seen many posts which were related to algorithms for solving an **N⨯N puzzle**, but I could not figure out the **time complexity** or **memory complexity** in these algorithms, especially when we want to apply `DFS` and `BFS` for solving our puzzle.
For example, if we assume that at first, the elements are no... |
I have seen many posts which were related to algorithms for solving an **N⨯N puzzle**, but I could not figure out the **time complexity** or **memory complexity** in these algorithms, especially when we want to apply `DFS` and `BFS` for solving our puzzle.
For example, if we assume that at first, the elements are no... |
if we define halting problem as follows
$
\begin{align*}
h(m,n) &=
\begin{cases}
1 & \text{if program $m$ halts on input $n$} \\
0 & \text{otherwise} \\
\end{cases}
\end{align*}
$
and we have two different sometimes correct solution $f$ and $g$ for $h$
then we can compute $h$ as fol... |
null |
The complexity of the BFS and DFS algorithms depend heavily on the graph being analyzed, and the search strategy being used. If we have a method to consistently get "closer" to a solution, then the search can be much more efficient than if we blindly stumble everywhere hoping to find what we need. In this case, I'm goi... |
The complexity of the BFS and DFS algorithms depend heavily on the graph being analyzed, and the search strategy being used. If we have a method to consistently get "closer" to a solution, then the search can be much more efficient than if we blindly stumble everywhere hoping to find what we need. In this case, I'm goi... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.