instruction stringlengths 0 29.8k ⌀ |
|---|
This seems like it should be a "textbook"/standard problem but I wasn't able to find anything about it, so I'd like to know if anyone else has seen something like it before or can suggest more keywords I could search for / perspectives I could view it from:
### Informal problem statement
Informally, the situation... |
8. What will be the time complexity of the following code?
```
for(int i=0;i<n;i++){
i*=k;
}
```
IGONRE THIS SECTION <br>
The answer is Log base k times n: O(Log_k * n)<br>
The underscore _ means base.<br>
The answer is read as Big O of Log base k times n<br>
-----------------------------------------------... |
Can you proof that the following code for (int i=0; i<n; i++){ i*=k; } is Big O of Log n based k by hand/tracing the program |
null |
If k=0 then i is set to 0 inside the loop, so it halts instantly if n <= 1 and runs forever otherwise.
If k=1 then the multiplication has no effect. The loop ends instantly if n <= 0 and after n iterations otherwise.
Let m be the number of iterations starting with m = 0. If k >= 2 then i is set to 0 inside the ... |
null |
null |
i'm trying to write an algorithm to reconstruct the original array from the sorted one. considering input value is a string of 1s and 2s which 1 means in merging part of merge sort, element from left subarray is chosen and 2 means element from right subarray is chosen. how can i do it? specially i have problem on that ... |
Restore the original array after merge Sort based on it's steps |
|algorithms|recursion|divide-and-conquer|mergesort| |
This is a self-study inspired by the trivial https://leetcode.com/problems/buy-two-chocolates/. Basically the question is as follows: if you have a value of money `m` and a list of `prices`, imagine you are a hungry child who wants to spend all of their money on two chocolates. Return the two prices that leave the leas... |
Buy two chocolates when want MAXIMUM nonegative spend |
|algorithms|time-complexity|optimization| |
null |
The algorithm developed by [Keith D. Cooper, Timothy J. Harvey, and Ken Kennedy](http://www.hipersoft.rice.edu/grads/publications/dom14.pdf) is widely used in industry for building dominator tree, but I cannot follow the proof in the “Engineering the data structure” section. Specifically, the claim of
```
with this ... |
CHK graph dominance algorithm proof |
|algorithms|graphs|compilers| |
null |
null |
null |
For simplicity I will assume that the number $n$ of elements is a power of $2$. The same idea works in general (by suitably rounding the sub-array sizes according to the implementation of Mergesort at hand).
In the last call of the mergesort algorithm the final sorted array $S$ was constructed my merging two sub-arr... |
For simplicity I will assume that the number $n$ of elements is a power of $2$. The same idea works in general (by suitably rounding the sub-array sizes according to the implementation of Mergesort at hand).
In the last call of the mergesort algorithm the final sorted array $S$ was constructed my merging two sub-arr... |
For simplicity I will assume that the number $n$ of elements is a power of $2$. The same idea works in general (by suitably rounding the sub-array sizes according to the implementation of Mergesort at hand).
Let's pretend that, whenever two arrays of size $x$ are merged in the mergesort algorithm, they contribute ex... |
null |
null |
For simplicity I will assume that the number $n$ of elements is a power of $2$. The same idea works in general (by suitably rounding the sub-array sizes according to the implementation of Mergesort at hand).
Let's pretend that, whenever two arrays of size $x$ are merged in the mergesort algorithm, they contribute ex... |
null |
null |
null |
null |
For simplicity I will assume that the number $n$ of elements is a power of $2$. The same idea works in general (by suitably rounding the sub-array sizes according to the implementation of Mergesort at hand).
Let's pretend that, whenever two arrays of size $x$ are merged in the mergesort algorithm, they contribute ex... |
For simplicity I will assume that the number $n$ of elements is a power of $2$. The same idea works in general (by suitably rounding the sub-array sizes according to the implementation of Mergesort at hand).
Let's pretend that, whenever two arrays of size $x$ are merged in the mergesort algorithm, they contribute ex... |
Linear Search has O(n) T.C and Binary Search have O(logn) T.C. But how come Linear Search generates fewer page faults? Is there another searching technique that causes a lesser number of page faults than linear search? |
Which searching technique will cause lesser number of page fault? |
|operating-systems|paging| |
null |
Your assumption is wrong. If all data is in memory then there are no page faults. Now assume you have 100 pages, none in memory. Linear search will have on average 50 page faults. Binary search will have a fault for page 50, one for page 25 or 75, one for page 12, 37, 62 or 87, and a few more. The total will be the log... |
Your assumption is wrong. If all data is in memory then there are no page faults. Now assume you have 100 pages, none in memory. Linear search will have on average 50 page faults. Binary search will have a fault for page 50, one for page 25 or 75, one for page 12, 37, 62 or 87, and a few more. The total will be the log... |
One approach is Eytzinger layout, which is essentially a breadth-first traversal of the binary search "tree".
[![Eytzinger layout][1]][1]
The idea is that the items that would be visited first in binary search are located next to each other in memory.
Another option is B-trees, which are designed with page eff... |
I think that this reply never consider a fact,which the classical alogorithms and the human thought are constantly evolving with the abstraction and resolve of problem. Basicaly,I think effectively corresponding relationship between the concept of computational complexity and the concept of human cognition will clear... |
The algorithm developed by [Keith D. Cooper, Timothy J. Harvey, and Ken Kennedy](http://www.hipersoft.rice.edu/grads/publications/dom14.pdf) is widely used in industry for building dominator tree, but I cannot follow the proof in the “Engineering the data structure” section. Specifically, the claim of
> with this o... |
null |
null |
null |
Yes. Sort all chocolates by price. For all possibilities for the choice of first chocolate, use [...] to find the best second chocolate to go with it. Keep the best pairing found.
Fill in the [...] with an appropriate algorithm, and you can beat $O(n^2)$.
To improve the running time even further, consider: as ... |
null |
One way to prove that is to reduce complement of A TM to E TM.
For Turing machine M and w as its input. We construct M' as follows:
For input w':
Run M on w:
If M rejected w, reject w'.
Otherwise, accept w'.
It is easy to see that M accepts w if and only if M' belongs to E TM.
From this reduction... |
Suppose $L$ is a regular language. Let $R\subseteq L$ be a language with maximal size such that for each $x,y\in R$ nor $x$ be a substring of $y$ neither $y$ be a substring of $x$. Could we conclude that $R$ is finite?
My thoughts are as follows:
We know our alphabet is finite, also each string on $\Sigma^*$ is f... |
Proving the set $R$ is finite |
|formal-languages|regular-languages| |
The original paper of Bully algorithm [1] does not make any assumption of a synchronous processing. But I see few lectures explicitly call it suitable for synchronous processing. I am not sure why do we need to make an assumption of lock-step global iteration (aka synchronous processing)! First, I see that each ELECTIO... |
Why is Bully algorithm in leader election considered synchronous? |
|distributed-systems|synchronization|consensus| |
Suppose $L$ is a regular language. Let $R\subseteq L$ be a language with maximal size such that for each $x,y\in R$ neither $x$ be a substring of $y$ nor $y$ be a substring of $x$. Could we conclude that $R$ is finite?
My thoughts are as follows:
We know our alphabet is finite, also each string on $\Sigma^*$ is f... |
It could have something to do with the amount of flow you redirect when you perform augmentation $\gamma$ along a positive cycle $\epsilon$.
Since you are assuming the creation of negative cycles, it means that you have created at least one new negative cost arc(the new negative arcs in residual graph $G(x')$ are th... |
To begin with, if I understand correctly, in a simply typed lambda calculus, typing, type checking and type inference are always decidable. In the "full-fledged" polymorphic (terms depend on types) lambda calculus, type inference is undecidable. The same is true for types depending on terms. Now I have 3 questions:
... |
When does type inference become undecidable in typed lambda calculus? |
|complexity-theory|lambda-calculus|type-theory|type-inference| |
There exists an infinite sequence of strings, such that no string is a substring of another. For example $a b^* a$.
If one considers the subsequence ordering instead of the substring ordering, then every infinite set of strings has a pair such that one is a subsequence of the other. This is known as [Higman's Lemma]... |
Suppose $L$ is a regular language. Let $R\subseteq L$ be a language with maximal size such that for each $x,y\in R$ neither $x$ be a substring of $y$ after removing a substring from $y$ nor $y$ become a substring of $x$ after removing a substring from $x$. Could we conclude that $R$ is finite?
My thoughts are as fo... |
null |
The problem with parity checking is: What do you do if it is wrong? Let’s say you stored a byte with value x, a parity bit is added, then you read the value and there is a parity error. You know that one of nine bits is wrong but not which one.
For data transmission there is a very simple rule: if there is any erro... |
null |
While the shortest path can be calculated with $O(V+E)$ time over a weighted directed acyclic graph using topological sort, I wonder about the running time of the following BFS type algorithm I thought of.
```
BFS_requeue(v):
Initialization()
push(s) //push the source node
while the queue contains at least one... |
Running time of modified BFS algorithm to find shortest path in weighted DAG |
|algorithms|graphs|algorithm-analysis|graph-traversal|weighted-graphs| |
You don’t need to restrict n to be less than $2^{64}$. The primes are around $n^{1/k}$. If this is small enough that you can find primes of that size easily enough, then you can find k+1 consecutive primes so that the product of the first k is not obviously greater than n and the product of the last k is not obviously ... |
While the shortest path can be calculated with $O(V+E)$ time over a weighted directed acyclic graph using topological sort, I wonder about the running time of the following BFS type algorithm I thought of.
```
BFS_requeue(v):
Initialization()
push(s) //push the source node
while the queue contains at least one... |
null |
null |
null |
I've been exploring the Least Recently Used (LRU) page replacement strategy, and I've come across a point of confusion that I would appreciate some clarification on.
As I understand it, in LRU, the page with the lowest (oldest) last access time is considered the least recently used and is a candidate for replacement... |
Query about LRU Replacement Strategy - Confusion on Page Selection |
|page-replacement| |
null |
While the shortest path can be calculated with $O(V+E)$ time over a weighted directed acyclic graph using topological sort, I wonder about the running time of the following BFS type algorithm I thought of.
```
BFS_requeue(v):
Initialization()
push(s) //push the source node
while the queue contains at least one... |
Consider the following problem:
> For $k \le n$, what is the smallest number of edges in the graph with $n$ vertices so that the maximum independent set has size at most $k$?
I.e. I want to add the smallest number of edges so that the maximum independent set has size $k$.
Let's denote it as $A(n,k)$.
For exampl... |
Minimum number of edges required to limit the size of the independent set |
|clique|independent-sets| |
Consider the following problem:
> For $k \le n$, what is the smallest number of edges in the graph with $n$ vertices so that the maximum independent set has size at most $k$?
I.e., given an empty graph on $n$ vertices, I want to add the smallest number of edges so that the maximum independent set has size $k$.
L... |
null |
It can take $O(|V| \cdot |E|)$ time.
Here is an explicit counterexample. Suppose you have a dag with $n$ vertices, numbered $1,2,\dots,n$, and there is an edge $i \to j$ for each $i,j$ with $i < j$. Suppose that the for-loop traverses the neighbors from highest-numbered vertex to lowest-number vertex. Then it will... |
{"Voters":[{"Id":755,"DisplayName":"D.W."}],"DeleteType":1} |
While the shortest path can be calculated with $O(V+E)$ time over a weighted directed acyclic graph using topological sort, I wonder about the running time of the following BFS type algorithm I thought of.
```
BFS_requeue(v):
Initialization()
push(s) //push the source node
while the queue contains at least one... |
The running time can be exponential, so it is much worse than $O(|V|+|E|)$ or $O(|V| \cdot |E|)$.
Here is an explicit counterexample. Suppose you have a dag with $n$ vertices, numbered $1,2,\dots,n$, and there is an edge $i \to j$ for each $i,j$ with $i > j$. Suppose that the for-loop traverses the neighbors from l... |
{"Voters":[{"Id":755,"DisplayName":"D.W."}]} |
The running time can be exponential, so it is much worse than $O(|V|+|E|)$ or $O(|V| \cdot |E|)$.
Here is an explicit counterexample. Suppose you have a dag with $n$ vertices, numbered $1,2,\dots,n$, and there is an edge $i \to j$ for each $i,j$ with $i > j$, with weight $2^{i-j}-1$. Suppose that the for-loop trave... |
null |
Suppose f_k, k = 0,1,… is any enumeration of total functions on the natural numbers, n >=0, that is, total functions whose domain and codomain are the natural numbers. Then
g(n) = f_n(n) + 1
is a total function which is not in the enumeration. For if it were, say the mth, then
g(m) = f_m(m) + 1 = g(m) + 1,
a cont... |
null |
yes, you're right about the processes being semantically different. There is a small mistake in your first reduction though, you forgot to remove the c(y) once you substitute y with n':
$(\nu n)\bar{c}\langle n \rangle.0|(\nu n)c(y).(if n=y \text{ then P else Q}) \rightarrow (\nu n')(\nu n)(if n=n' \text{ then P els... |
I'm reading Hopcroft's book about computation theory and wondering about how fast can u find all nullable symbols in CFG. |
what's the time complexity of finding all nullable symbols in context free grammar? |
|context-free| |
null |
You can do it in linear time. For each nonterminal $A$, introduce a boolean variable $x_A$ that identifies whether $A$ is nullable or not. Derive constraints on these boolean variables, following [the relations described by Hopcroft and Ullman](https://en.wikipedia.org/wiki/Chomsky_normal_form#DEL:_Eliminate_%CE%B5-r... |
Given an $n \times n$ grid of integers, I would like to compute the circular area which gives the maximum sum of integers within the area. For example:
[![enter image description here][1]][1]
In this picture, the integers 1, 0, 1, 2, 3, 1, 2, 1, -3, -2, 2, -3, 1, 3, -2, 0, 2, -1 etc are all within the circular ar... |
Maximal circular area sum |
|algorithms| |
Maximum circular area sum |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.