instruction stringlengths 0 29.8k ⌀ |
|---|
|time-complexity|runtime-analysis|landau-notation| |
You have 1 coin. You may flip it as many times as you want.
You want to generate random number r such that $a \leq r \leq b$ where r,a,b $\in \mathbb{Z}^+$.
Distribution of the numbers should be uniform.
Its easy if $b -a = 2^n$.
r = a + binary2dec(flip n times write 0 for heads and 1 for tails)
Wha... |
Generating uniformly distributed random numbers using a coin |
|random| |
1. [MIT OCW Introduction to algorithms video lectures][1]
2. [Design and analysis of algorithms stanford class][2]
[1]: http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-046j-introduction-to-algorithms-sma-5503-fall-2005/video-lectures/
[2]: https://www.coursera.org/algo/auth/welcome |
Have you watched a child learning to navigate a room? You have to tell them, "Go around the table. *AROUND*".
Human path planning is a grab bag of heuristics, some innate and some learned. Lookahead is probably fixed to a small number, certainly not a general recursion like A*. |
The simple answer?
If $b-a$ is not a power of 2, then after generating $r$, check whether it is in-range, and if not, generate it again.
The most likely time you will have to re-generate $r$ is when $b - a = 2^n + 1$ for some integer $n$, but even then it will have a greater than 50% chance of falling within rang... |
Choose a number in the next larger power of 2 range, and discard answers greater than b-a.
n = b-a;
N = round_to_next_larger_power_of_2(n)
while (1) {
x = random(0 to N);
if (x < n) break;
}
r = a + x;
|
Since you are allowed to flip it as many times as you wish, you can get your probability as-close-as-you-wish by picking a fraction $r\in [0,1]$ (using binary radix: you flip the coin for each digit after the point) and multiply $r$ by $b-a$ to get your number (completing to the nearest integer). |
Suppose I have two strings. Call them A and B. Neither string has any repeated characters.
How can I find the shortest sequence of insert, move, and delete operation that turns A into B, where:
- `insert(char, offset)` inserts `char` at the given `offset` in the string
- `move(from_offset, to_offset)` moves th... |
Expressing an arbitrary permutation as a sequence of (insert, move, delete) operations |
|algorithms|combinatorics|efficiency|dynamic-programming| |
|randomness| |
Since you are allowed to flip your coin as many times as you wish, you can get your probability as-close-as-you-wish to uniform by picking a fraction $r\in [0,1]$ (using binary radix: you flip the coin for each digit after the point) and multiply $r$ by $b-a$ to get your number (completing to the nearest integer).
I... |
*(technicalities: the answer fits selection of number $a \le x < b$)*
Since you are allowed to flip your coin as many times as you wish, you can get your probability as-close-as-you-wish to uniform by picking a fraction $r\in [0,1]$ (using binary radix: you flip the coin for each digit after the point) and multiply ... |
null |
I suggest taking a look at the [edit distance algorithm][1]. Instead of just calculating the distance, you'll want to record your minimum weight path through the array and return that.
[1]: http://en.wikipedia.org/wiki/Levenshtein_distance |
Suppose we have a balanced binary tree, which represents a recursive partitioning of a set of $N$ points into nested subsets. Each node of the tree represents a subset, with the following properties: subsets represented by two children nodes of the same parent are disjoint, and their union is equal to the subset repre... |
What is the complexity of these tree-based algorithms? |
|time-complexity| |
|time-complexity|binary-trees| |
The first algorithm takes $O(N^2)$ time because your underlying recurrence is
\\[ T(n) = 2T(N/2) + N^2 \\]
The second algorithm takes $N\log^2N$ time as you mention. If your work per node is as indicated (and is tight) then this bound is tight as well. |
I understand the theory behind Bayesian networks, and am wondering what it takes to build one in practice. Let's say for this example, that I have a Bayesian (directed) network of 100 discrete random variables; each variable can take one of up to 10 values.
Do I store all the nodes in a DAG, and for each node store ... |
What combination of data structures efficiently stores discrete Bayesian networks? |
|graphs| |
|time-complexity|runtime-analysis|landau-notation|education| |
|graphs|machine-learning| |
I believe I have a reasonable grasp of complexities like `O(1)`, `O(n)` and `O(n2)`.
In terms of a list, `O(1)` is a constant lookup, so it's just getting the head of the list.
`O(n)` is where I'd walk the entire list, and `O(n2)` is walking the list once for each element in the list.
Is there a similar intuitiv... |
Intuition into log n complexity |
|time-complexity| |
The `O(log n)` complexity is usually connected with subdivision. When using lists as an example, imagine a list whose elements are sorted. You can search in this list in `O(log n)` time - you do not actually need to look at each element because of the sorted nature of the list.
If you look at the element in the mid... |
In terms of (balanced) trees (say, binary tree, so all $\log$'s are base 2):
- $O(1)$ is getting the root of the tree
- $O(\log n)$ is a walk from root to leaf
- $O(n)$ is going over all the node of the tree |
Suppose we have a balanced binary tree, which represents a recursive partitioning of a set of $N$ points into nested subsets. Each node of the tree represents a subset, with the following properties: subsets represented by two children nodes of the same parent are disjoint, and their union is equal to the subset repre... |
null |
[Formal methods](http://en.wikipedia.org/wiki/Formal_methods) are mathematical techniques for specifying and verifying computing systems.
See also [tag:proof-techniques].
|
null |
techniques for formal modeling of computing systems and proving properties about the models |
null |
Use this tag for questions about programming language design and implementation and about theoretical concepts underlying existing programming languages. Questions about concrete features of existing programming languages belongs on [Stack Overflow](http://stackoverflow.com/).
### Related tags
* Program analysis... |
null |
Design, implementation and analysis of programming languages |
null |
[Type checking](http://en.wikipedia.org/wiki/Type_checking#Type_checking) is the process of verifying that a program fragment has a particular type. It may be performed statically (at compile time) or dynamically (at run time).
For more general questions about types in programming languages, see [tag:typing].
|
null |
verifying that a variable, expression or value has the declared type |
null |
[Type theory](http://en.wikipedia.org/wiki/Type_theory) is the study of formal systems that classify objects into categories. It was historically introduced in logic, to provide a foundational set theory, and is now widely used in programming language design. Use this tag if your question touches on theoretical aspects... |
null |
formal systems to specify properties of objects |
null |
[Type systems](http://en.wikipedia.org/wiki/Type_system) specify properties of program fragments such as values, expressions and variables. Use this tag for questions about the type systems of programming languages and theoretical frameworks intended to apply to programming languages.
### Related tags
* [tag:typ... |
null |
type systems of programming languages |
null |
|algorithms|time-complexity|binary-trees| |
For $O(\log n)$ to be possible, the key is the ability to cut down the problem size proportionally with a constant time operation.
For example, in the case of binary search, you can cut down the problem size by a half with each comparison operation.
Now, do you have to cut down the problem size by half, actually ... |
I recommend you to check Scott Aaronson's [blog post][1] on a proof of the Incompleteness Theorem via Turing machines and Rosser's Theorem. His proof of the incompleteness theorem is extremely simple and easy to follow.
[1]: http://www.scottaaronson.com/blog/?p=710 |
For $O(\log n)$ to be possible, you need to be able to cut down the problem size proportionally with a constant time operation.
For example, in the case of binary search, you can cut down the problem size by a half with each comparison operation.
Now, do you have to cut down the problem size by half, actually no.... |
Simply put, if one were to build a quantum computing device with the power of, say, 20 qubits, could the processing power by said computer be used to make any kind of modern hashing algorithm useless?
Would it even be possible to harness the power of quantum computing in a traditional computing application? |
Could quantum computing eventually be used to make modern day hashing trivial to break? |
|quantum-computing| |
The "best" data structure probably depends on what particular problem you're trying to solve with it.
Here's one approach that I've seen (and have used myself), which simply stores all the information. First you index the nodes by unique integers, 0 through n-1. Then you simply store, for each node, the list of its ... |
Can every linear grammar be converted to a form in which all productions look like $A \rightarrow ax$ where $a \in T$ and $x \in V \cup \{\lambda\}$? |
Can every linear grammar be converted to Greibach form? |
|finite-automata|normal-grammar|linear| |
The "best" data structure probably depends on what particular problem you're trying to solve with it. Here's one approach that I've seen (and have used myself), which simply stores all the information and leaved it up to the algorithm what to do with it.
1) First you index the nodes by unique integers, 0 through n-1... |
Yes, log(n) is between 1 and n, but it is very close to 1 rather than n. What is log(n)? The log function is the inverse function of exponentation. Let me start with exponentation and you should get a better idea of what logarithm is.
Consider two numbers, 100 and 2^100. 2^100 is 2 multiplied 100 times. You can with... |
Yes, log(n) is between 1 and n, but it is very close to 1 rather than n. What is log(n)? The log function is the inverse function of exponentation. Let me start with exponentation and you should get a better idea of what logarithm is.
Consider two numbers, 100 and 2^100. 2^100 is 2 multiplied 100 times. You can with... |
For $O(\log n)$ to be possible, you need to be able to cut down the problem size proportionally by some arbitrary amount with respect to $n$ with a constant time operation.
For example, in the case of binary search, you can cut down the problem size by a half with each comparison operation.
Now, do you have to cu... |
Yes, log(n) is between 1 and n, but it is very close to 1 rather than n. What is log(n)? The log function is the inverse function of exponentation. Let me start with exponentation and you should get a better idea of what logarithm is.
Consider two numbers, 100 and 2^100. 2^100 is 2 multiplied 100 times. You can with... |
Yes, log(n) is between 1 and n, but it is very close to 1 rather than n. What is log(n)? The log function is the inverse function of exponentation. Let me start with exponentation and you should get a better idea of what logarithm is.
Consider two numbers, 100 and 2^100. 2^100 is 2 multiplied 100 times. You can with... |
The more general answer is:
[Blum and Koch](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.47.460) showed a polynomial time transformation such that any context-free grammar can be converted to [Greibach form](https://en.wikipedia.org/wiki/Greibach_normal_form).
Since a [linear grammar](https://en.wikipe... |
Yes, log(n) is between 1 and n, but it is very close to 1 than n. What is log(n)? The log function is the inverse function of exponentation. Let me start with exponentation and you should get a better idea of what logarithm is.
Consider two numbers, 100 and 2^100. 2^100 is 2 multiplied 100 times. You can with some e... |
What you're looking for is based on [Rejection sampling][1] or the accept-reject method (note that the Wiki page is a bit technical).
This method is useful in these kinds of situations: you want to pick some random object from a set (a random integer in the set $[a,b]$ in your case), but you don't know how to do tha... |
|randomness|probability-theory| |
I believe I have a reasonable grasp of complexities like $O(1)$, $O(n)$ and $O(n^2)$.
In terms of a list, $O(1)$ is a constant lookup, so it's just getting the head of the list.
$O(n)$ is where I'd walk the entire list, and $O(n^2)$ is walking the list once for each element in the list.
Is there a similar intuit... |
null |
Choose a number in the next larger power of 2 range, and discard answers greater than $b-a$.
n = b-a;
N = round_to_next_larger_power_of_2(n)
while (1) {
x = random(0 included to N excluded);
if (x < n) break;
}
r = a + x;
|
You have 1 coin. You may flip it as many times as you want.
You want to generate a random number $r$ such that $a \leq r < b$ where r,a,b $\in \mathbb{Z}^+$.
Distribution of the numbers should be uniform.
Its easy if $b -a = 2^n$:
r = a + binary2dec(flip n times write 0 for heads and 1 for tails)
... |
|random|probability-theory| |
What you're looking for is based on [Rejection sampling][1] or the accept-reject method (note that the Wiki page is a bit technical).
This method is useful in these kinds of situations: you want to pick some random object from a set (a random integer in the set $[a,b[$ in your case), but you don't know how to do tha... |
|algorithms|combinatorics|dynamic-programming|lists| |
I know that since ~2004, Moore's law stopped working for CPU clock speed.
I'm looking for a graph showing this, but am unable to find it: most charts out there show the transistor count or the capacity per year.
Where can I find some data showing the CPU frequency of computers (anything is fine, personal computers,... |
CPU frequency per year |
|computer-architecture|clocks| |
Think about algorithm to convert decimal number $n$ to binary
while n != 0:
print n%2,
n = n/2
This `while` loop runs $\log(n)$ times.
|
The graphs you want are printed in the book “[CMOS VLSI Design](http://www3.hmc.edu/~harris/cmosvlsi/4e/index.html)” Weste/Harris (2005), on [page 5](http://www3.hmc.edu/~harris/cmosvlsi/4e/cmosvlsidesign_4e_ch1.pdf) of the freely available introduction. |
From what I understand, quantum computing does have the power to easily break today's hashing algorithms. However, in the long run we will also be able to use more complex hashing algorithms, and generally it is easier to encrypt than decrypt something. I think the biggest issues to consider are when quantum computing ... |
Say I have a string $a \in \Sigma^+$ and some CFG $G$ such that $x a y \in \mathcal{L}(G)$ where $x,y\in \Sigma^*$.
Given the CFG, I'd like to determine a set of characters $C = \{ b \mid xaby \in \mathcal{S}(G)\}$, where $\mathcal{S}(G)$ are the sentential forms of $G$.
In this case, $x,a,y,b$ are non-terminals.... |
null |
Using as few resources (e.g. time, space) as possible while solving a problem. Use this tag if your question is specifically about resource usage, not for generic algorithm questions that happen to mention running times. |
null |
tldr: There is no silver bullet language.
I hope they won't sue me, but here is a pic from one of the Stanford presentations.
![enter image description here][1]
When you decide to pick a language, you can pick **only 2 of these 3 features**.
And that is why people are sad and want to invent a superlanguage... |
If b-a is not a power of 2 then you may have to flip many coins in order to get a result. You may even never get a result, but that is unlikely in the extreme.
**Methods**
The simplest method is to generate a number in [a, a+2^n), where 2^n >= b-a, until one happens to land in [a, b). You throw away a lot of entr... |
"While there is nothing wrong with visual programming, it may be the case that it's simply not a good approach for most tasks."
Perhaps, the visual programming languages to date have just been too immature? The notion that advanced visualizations cannot be applied to software artifacts and that they are left comple... |
|cryptography|quantum-computing|hash| |
From what I understand, quantum computing does have the power to easily break today's hashing algorithms. However, in the long run we will also be able to use more complex hashing algorithms, and generally it is easier to encrypt than decrypt something. I think the biggest issues to consider are when quantum computing ... |
Can every [linear grammar](http://en.wikipedia.org/wiki/Linear_grammar) be converted to a linear [Greibach normal form](http://en.wikipedia.org/wiki/Greibach_normal_form), a form in which all productions look like $A \rightarrow ax$ where $a \in T$ and $x \in V \cup \{\lambda\}$?
($T$ is the set of terminals, $V$ is... |
|formal-grammars| |
null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.