instruction stringlengths 0 29.8k ⌀ |
|---|
Difference operation is one of the many fundamental operations of relational algebra. However, there are namely, some databases that do not support difference operation directly, but it does support left join, and in practice this can be used in place of a subtraction operation.
Does that mean that the expressive po... |
Can an expressive power of the query language maintained through left join if difference operation is missing |
|database-theory| |
In a standard algorithms course we are taught that Quicksort is $O(n \log n)$ on average and $O(n^2)$ in the worst case. At the same time, other sorting algorithms are studied which are $O(n \log n)$ in the worst case, and even linear time but with some additional needs of memory.
After a quick glance at those runni... |
Why is quicksort better than other sorting algorithms in practice? |
|algorithms| |
Many operating systems references say that with cooperative (as opposed to preemptive) multitasking, a process keeps the CPU until it explicitly voluntarily suspends itself. If a running process blocks on i/o (e.g., requests a key stroke that is not yet available), does the scheduler suspend it, or does it really keep... |
Does cooperative scheduling suspend processes blocked on i/o? |
|scheduling| |
In comparison to other comparison-based sorting algorithms with $O(n \lg n)$ time complexity, quick-sort is often considered to better than other algorithms like merge-sort because it is an in-place sorting algorithm. In other words, we don't need (much more) memory to store the members of the array.
ps: to be preci... |
|algorithms|sorting| |
|scheduling|operating-systems| |
When storing geometric objects in a quadtree (or octree), you can store objects that belong in more than one node in a few ways:
1. Placing the object in every leaf for which it is contained
2. Placing the object in the deepest node for which it is fully contained
3. Both #1 and #2
For example:
![enter im... |
Which method is preferred for storing large geometric objects in a quadtree? |
|graphics|data-structures| |
|graphics|data-structures|computational-geometry| |
Assuming you are storing a reference, not the object itself, it may make sense to do this differently depending on your application.
For instance, if you were computing collisions with this (solid) circle and the collision was occurring in the lower left hand corner, it'd be easier if you had access to all geometry ... |
When placing geometric objects in a quadtree (or octree), you can place objects that are larger than a single node in a few ways:
1. Placing the object's reference in every leaf for which it is contained
2. Placing the object's reference in the deepest node for which it is fully contained
3. Both #1 and #2
F... |
I think one of the main reasons why QuickSort is so fast compared with other sorting algorithms is because it's cache-friendly. When QS processes a segment of an array, it accesses elements at the beginning and end of the segment, and moves towards the center of the segment.
So, when you start, you access the first ... |
I have a set of pairs. Each pair is of the form (x,y) such that x,y belong to integers from the range `[0,n)`.
So, if the n is 4, then I have the following pairs:
(0,1) (0,2) (0,3)
(1,2) (1,3)
(2,3)
I already have the pairs. Now, I have to build a combination using `n/2` pairs such that none of... |
Generating Cobinations from a set of pairs without repetition of elements |
|algorithms|recursion| |
In a truly "cooperative" setting, and if there was no hardware protection, a process could certainly block on I/O and not relinquish control until the I/O was done (or never relinquish control at all). For example, Windows 3.1 was this way: if a single user process wanted to take over the entire computer, and prevent a... |
> If a running process blocks on i/o
Blocking on IO is pretty much equivalent to suspending your process. In the context of the linux kernel, executing some IO system call such as `read()` will cause a `sysenter` or interrupt handler to trigger to look after that IO, calling `do_sys_read()` ultimately. Here, if the ... |
Seeing that Type 3 languages can be recognised by a DFA (which has no stacks), Type 2 by a DFA with *one* stack (i.e. a push-down automaton) and Type 0 by a DFA with *two* stacks (i.e. with one queue, i.e. with a tape, i.e. by a Turing Machine), how do Type 1 languages fit into this picture? And what advantages does it... |
What is the significance of context-sensitive (Type 1) languages? |
|formal-languages|applied-theory| |
Even though quick-sort has a worst case run time of $\Theta(n^2)$, quicksort is considered the best sorting because it is VERY efficient on the average: its expected running time is $\Theta(n\log n)$ where the constants are VERY SMALL compared to other sorting algorithms. This is the main reason for using quick sort ov... |
In the cooperative scheduling (preferably `cooperative multitasking`) model, there is no concept of a scheduler in a sense that the operating system does not have any control of how long the process runs.
An application programmed correctly would voluntarily give up the CPU on I/O. But, badly written applications m... |
One of the advantages of a Quadtree is that you don't have to split a node into its child nodes if all of the child nodes would contain the same information. This can save you a lot of memory and can make processing faster.
Following this principle, I think it makes more sense to store it only in the root node (meth... |
Generating Combinations from a set of pairs without repetition of elements |
null |
|algorithms|recursion|combinations|permutations| |
|algorithms|combinations|permutations| |
Many operating systems references say that with cooperative (as opposed to preemptive) multitasking, a process keeps the CPU until it explicitly voluntarily suspends itself. If a running process performs an I/O (e.g., requests a key stroke that is not yet available), does the scheduler suspend it, or does it really ke... |
Does cooperative scheduling suspend processes when they perform an I/O operation? |
null |
Many operating systems references say that with cooperative (as opposed to preemptive) multitasking, a process keeps the CPU until it explicitly voluntarily suspends itself. If a running process performs an I/O request that cannot be immediately satisfied (e.g., requests a key stroke that is not yet available), does t... |
One direct way is a recursive procedure that does the following on each invocation. The input to the procedure is a list of pairs that have already been chosen and a list of all the pairs.
1. Compute the smallest number not already covered by the input list. For the first invocation, this will be 0 of course, beca... |
Does the 'difference' operation add expressiveness to a query language that already includes 'join'? |
null |
Considering this pseudo-code of an bubblesort:
FOR i := 0 TO arraylength(list) STEP 1
switched := false
FOR x := 0 TO arraylength(list)-(i+1) STEP 1
IF list[x] > list[x + 1] THEN
switch(list,x,x+1)
switched := true
ENDIF
NEXT
IF switched = false THEN
... |
evaluating the average time complexity of a given bubblesort algorithm |
|time-complexity| |
|algorithms|time-complexity| |
|algorithms|time-complexity|average-case| |
|database-theory|relational-algebra|finite-model-theory| |
Note that what you're asking to do is enumerate all possible perfect matchings on a bipartite graph. There are many different algorithms for doing this, and in particular one of the more recent ones is from [ISAAC 2001][1].
The basic idea is to find one perfect matching by using network flows, and then repeatedly m... |
Generally speaking, you usually want to know the smaller class to which a given language $L$ belongs. This is because smaller classes can be recognized/accepted/generated by simpler mechanisms (automata, grammars, regular expressions, etc.), which is desirable.
For example, the class of regular languages has *good* ... |
In the cooperative scheduling (preferably `cooperative multitasking`) model, there is no concept of a scheduler in a sense that the operating system does not have any control of how long the process runs.
An application programmed correctly would voluntarily give up the CPU on I/O. But, badly written applications m... |
Any language that is type 1 can be recognized by a Turing machine that only uses linear space (so-called linear bounded automata). |
Type 1 languages can be decided by [linear bounded automata](http://en.wikipedia.org/wiki/Linear_bounded_automaton), which are non-deterministic Turing machines that may only use a portion of the tape whose size is linear to the input size. |
Considering this pseudo-code of an bubblesort:
FOR i := 0 TO arraylength(list) STEP 1
switched := false
FOR x := 0 TO arraylength(list)-(i+1) STEP 1
IF list[x] > list[x + 1] THEN
switch(list,x,x+1)
switched := true
ENDIF
NEXT
IF switched = false THEN
... |
The Chomsky hierarchy classifies grammars more than languages. However it was not designed to have something to do with the number of tapes a automaton should have to recognize it, as you suggested for Type 2 and 3, even if there is a kind of Turing machine that does that for Type-1 grammars.
You should also note th... |
Considering this pseudo-code of an bubblesort:
FOR i := 0 TO arraylength(list) STEP 1
switched := false
FOR x := 0 TO arraylength(list)-(i+1) STEP 1
IF list[x] > list[x + 1] THEN
switch(list,x,x+1)
switched := true
ENDIF
NEXT
IF switched = false THEN
... |
Considering this pseudo-code of an bubblesort:
FOR i := 0 TO arraylength(list) STEP 1
switched := false
FOR x := 0 TO arraylength(list)-(i+1) STEP 1
IF list[x] > list[x + 1] THEN
switch(list,x,x+1)
switched := true
ENDIF
NEXT
IF switched = false THEN
... |
For lists of length $n$, average usually means that you have to start with a uniform distribution on all $n!$ permutations of [$1$, .., $n$]: that will be all the lists you have to consider.
Your average complexity would then be the sum of the number of step for all lists divided by $n!$.
For a given list $(x_i)_... |
In a standard algorithms course we are taught that **quicksort** is $O(n \log n)$ on average and $O(n^2)$ in the worst case. At the same time, other sorting algorithms are studied which are $O(n \log n)$ in the worst case (like **mergesort** and **heapsort**), and even linear time in the best case (like **bubblesort**)... |
Let's consider a memory segment (whose size can grow or shrink, like a file, when needed) on which you can perform two basic memory allocation operations involving fixed size blocks:
* allocation of one block
* freeing a previously allocated block which is not used anymore.
Also, as a requirement, the memor... |
Clever memory management with constant time operations? |
|time-complexity|memory-allocation| |
In relational algebra, we shall first provide an informal definition of left (outer) join, and proceed to prove that it, renaming, selection, join and projection can construct difference, as well as that difference, selection and union can be used to construct left (outer) join. Actually, we'll end up doing it in the r... |
Let's consider a memory segment (whose size can grow or shrink, like a file, when needed) on which you can perform two basic memory allocation operations involving fixed size blocks:
* allocation of one block
* freeing a previously allocated block which is not used anymore.
Also, as a requirement, the memor... |
For lists of length $n$, average usually means that you have to start with a uniform distribution on all $n!$ permutations of [$1$, .., $n$]: that will be all the lists you have to consider.
Your average complexity would then be the sum of the number of step for all lists divided by $n!$.
For a given list $(x_i)_... |
Recall that a pair A[i] A[j] is inverted if i < j and A[i] > A[j].
Assuming your algorithm performs one swap for each inversion, the running time of your algorithm will depend on the number of inversions.
Calculating the expected number of inversions in a uniform random permutation is easy:
Let P be a permutat... |
You may want to have a look at [amortized analysis][1] and in particular dynamic arrays. Even if the operations are not really done in constant time at every step, in the long run it looks like it is the case.
[1]: https://en.wikipedia.org/wiki/Amortized_analysis |
Even though quick-sort has a worst case run time of $\Theta(n^2)$, quicksort is considered the best sorting because it is VERY efficient on the average: its expected running time is $\Theta(n\log n)$ where the constants are VERY SMALL compared to other sorting algorithms. This is the main reason for using quick sort ov... |
In comparison to other comparison-based sorting algorithms with $O(n \lg n)$ time complexity, quick-sort is often considered to better than other algorithms like merge-sort because it is an in-place sorting algorithm. In other words, we don't need (much more) memory to store the members of the array.
ps: to be preci... |
{"Voters":[{"Id":45,"DisplayName":"Suresh"}]} |
Difference operation is one of the many fundamental operations of relational algebra. However, there are some databases that do not support difference operation directly, but support LEFT JOIN, and in practice this can be used instead of a subtraction operation.
Does that mean that the expressive power of the query ... |
null |
The context-sensitive languages are exactly the languages that can be recognized by a Turing machine using linear space and non-determinism. You can simulate such a Turing machine using exponential time, so you can recognize any such language in exponential time. Do note that the problem of recognizing some context-sen... |
The basic strategies you should know are first-fit, next-fit, best-fit, and the [buddy system][1]. I wrote [a short summary][2] once for a course I taught, I hope it's readable.
In practice you'll see various modifications of these basic strategies. But none of these is really constant time! I don't think that's pos... |
Considering this pseudo-code of an bubblesort:
FOR i := 0 TO arraylength(list) STEP 1
switched := false
FOR j := 0 TO arraylength(list)-(i+1) STEP 1
IF list[j] > list[j + 1] THEN
switch(list,j,j+1)
switched := true
ENDIF
NEXT
IF switched = false THEN
... |
null |
[Rice's theorem][1] tell us that the only *semantic* properties of [Turing Machines][2] (i.e. the properties of the function computed by the machine) that we can decide are the two trivial properties (i.e. always true and always false).
But there are other properties of Turing Machines that are not decidable. For ex... |
Rice's theorem for non-semantic properties |
|computability|undecidability| |
The basic strategies you should know are first-fit, next-fit, best-fit, and the [buddy system][1]. I wrote [a short summary][2] once for a course I taught, I hope it's readable. I point there to [a fairly exhaustive survey][3].
In practice you'll see various modifications of these basic strategies. But none of these... |
|time-complexity|memory-allocation|operating-systems| |
Modern programming language use context-sensitive features all the time; they fall into a subset that can efficiently be decided.
Examples are name and type analysis and type inference. |
In context-free languages, at any point of the input parsing, the automaton is in a state defined by it's stack. Each production has the same behaviour in consuming the input regardless of where it is used.
This leads to the interesting property that each production generate a sublanguage of the one generated by the... |
Others have already said that the asymptotic *average* runtime of Quicksort is better (in the constant) than that of other sorting algorithms (in certain settings).
What does that mean? Assume any permutation is chosen at random (assuming uniform distribution). In this case, typical pivot selection methods provide p... |
In context-free languages, at any point of the input parsing, the automaton is in a state defined by it's stack. Each production has the same behaviour in consuming the input regardless of where it is used.
This leads to the interesting property that each production generate a sublanguage of the one generated by the... |
*This answer is about generic memory management techniques. I missed that the question asks about the case where all blocks have the same size (and are aligned).*
<hr/>
The basic strategies you should know are first-fit, next-fit, best-fit, and the [buddy system][1]. I wrote [a short summary][2] once for a course I... |
In relational algebra, we shall first provide an informal definition of left (outer) join, and proceed to prove that it, renaming, selection, join and projection can construct difference, as well as that difference, selection and union can be used to construct left (outer) join. Actually, we'll end up doing it in the r... |
A general theorem that partially covers the example given is that any $\Sigma^0_1$-hard property of the machine will be undecidable. The halting problem is $m$-reducible to the state-reachability problem, so that shows the state reducibility problem is $\Sigma^0_1$-hard.
However, this is not an "if and only if" the... |
{"Voters":[{"Id":45,"DisplayName":"Suresh"}]} |
**Update**: my earlier answer dealt with bipartite graphs, which the OP was NOT asking about. I'm leaving it in for now, as related info. but the more pertinent information relates to perfect matchings in nonbipartite graphs.
In this regard, [there's a nice survey by Propp][1] that outlines progress (till 1999). So... |
In relational algebra, we shall first provide an informal definition of left (outer) join, and proceed to prove that it, renaming, selection, join and projection can construct difference, as well as that difference, selection and union can be used to construct left (outer) join. Actually, we'll end up doing it in the r... |
Every pair you pick eliminates two rows from which you can not pick anymore. This idea can be used to setup a recursive algorithm (in Scala):
def combine(pairs : Seq[(Int,Int)]) : Seq[Seq[(Int, Int)]] = pairs match {
case Seq() => Seq()
case Seq(p) => Seq(Seq(p))
case _ => {
val com... |
There are multiple points that can be made regarding this question.
**Quicksort is usually fast**
Although Quicksort has worst-case $O(n^2)$ behaviour, it is usually fast: assuming random pivot selection, there's a very large chance we pick some number that separates the input into two similarly sized subsets, wh... |
I am not sure if this is what you are asking but as I understand, you have all $n \choose 2$ unordered pairs of $[n] = \{1, \cdots, n\}$ and want to count the list of all pairs that cover the set $[n]$. We can think of this as [edge-coverings][1] of $K_n$, the complete graph on $n$ vertices.
Moreover the question s... |
I am not sure if this is what you are asking but as I understand, you have all $n \choose 2$ unordered pairs of $[n] = \{1, \cdots, n\}$ and want to count the list of all pairs that cover the set $[n]$ where $n$ is an even number. We can think of this as [edge-coverings][1] of $K_n$, the complete graph on $n$ vertices.... |
I am not sure if this is what you are asking but as I understand, you have all $n \choose 2$ unordered pairs of $[n] = \{1, \cdots, n\}$ and want to count the list of all pairs that cover the set $[n]$ where $n$ is an even number. We can think of this as [edge-coverings][1] of $K_n$, the complete graph on $n$ vertices.... |
People often say that [LR(k)](https://en.wikipedia.org/wiki/LR_parser) parsers are more powerful than [LL(k)](https://en.wikipedia.org/wiki/LL_parser) parsers. These statements are vague most of the time; in particular, should we compare the classes for a fixed $k$ or the union over all $k$? So how is the situation rea... |
Language theoretic comparison of LL and LR grammars |
|formal-languages|formal-grammars|parsers| |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.