instruction stringlengths 0 29.8k ⌀ |
|---|
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**)... |
There are numerous containments known. Let $\subseteq$ denote containment and $\subset$ proper containment. Let $\times$ denote incomparability.
Let $LL = \bigcup_k LL(k)$, $LR = \bigcup_k LR(k)$.
Grammar level:
For LL:
* $LL(0) \subset LL(1) \subset LL(2) \subset LL(2) \subset \cdots \subset LL(k) \subset ... |
There are numerous containments known. Let $\subseteq$ denote containment and $\subset$ proper containment. Let $\times$ denote incomparability.
Let $LL = \bigcup_k LL(k)$, $LR = \bigcup_k LR(k)$.
Grammar level:
For LL:
* $LL(0) \subset LL(1) \subset LL(2) \subset LL(2) \subset \cdots \subset LL(k) \subset ... |
Many textbooks cover intersection types in the lambda-calculus. The typing rules for intersection can be defined as follows (on top of the simply typed lambda-calculus with subtyping):
$$
\dfrac{\Gamma \vdash M : T_1 \quad \Gamma \vdash M : T_2}
{\Gamma \vdash M : T_1 \wedge T_2}
(\wedge I)
\qquad\qq... |
null |
There are numerous containments known. Let $\subseteq$ denote containment and $\subset$ proper containment. Let $\times$ denote incomparability.
Let $LL = \bigcup_k LL(k)$, $LR = \bigcup_k LR(k)$.
Grammar level:
For LL:
* $LL(0) \subset LL(1) \subset LL(2) \subset LL(2) \subset \cdots \subset LL(k) \subset ... |
There are numerous containments known. Let $\subseteq$ denote containment and $\subset$ proper containment. Let $\times$ denote incomparability.
Let $LL = \bigcup_k LL(k)$, $LR = \bigcup_k LR(k)$.
##Grammar level##
###For LL###
* $LL(0) \subset LL(1) \subset LL(2) \subset LL(2) \subset \cdots \subset LL(k) ... |
null |
I just want to explain why intersection types are well-suited to characterize classes of normalization (strong, head or weak), whereas other type systems can not. (simply-typed or system F).
The key difference is that you have to say: "if I can type $M_2$ and $M_1→M_2$ then I can type $M_1$". This is often not true ... |
There are numerous containments known. Let $\subseteq$ denote containment and $\subset$ proper containment. Let $\times$ denote incomparability.
Let $LL = \bigcup_k LL(k)$, $LR = \bigcup_k LR(k)$.
##Grammar level##
###For LL###
* $LL(0) \subset LL(1) \subset LL(2) \subset LL(2) \subset \cdots \subset LL(k) ... |
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... |
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... |
There are numerous containments known. Let $\subseteq$ denote containment and $\subset$ proper containment. Let $\times$ denote incomparability.
Let $LL = \bigcup_k LL(k)$, $LR = \bigcup_k LR(k)$.
##Grammar level##
###For LL###
* $LL(0) \subset LL(1) \subset LL(2) \subset LL(2) \subset \cdots \subset LL(k) ... |
null |
There are numerous containments known. Let $\subseteq$ denote containment and $\subset$ proper containment. Let $\times$ denote incomparability.
Let $LL = \bigcup_k LL(k)$, $LR = \bigcup_k LR(k)$.
##Grammar level##
###For LL###
* $LL(0) \subset LL(1) \subset LL(2) \subset LL(2) \subset \cdots \subset LL(k) ... |
You can solve it iteratively. Suppose you have all solutions $S_n$ for the range $[0,n)$. Then you can easily construct the solutions $S_{n+2}$ from $S_n$. The size grows extremely quickly with $n$, so it may be good to write a generator rather than to hold all the sets in memory, see Python example below.
def p... |
Assuming $P \ne NP$, NPI is the class of NP problems without any polynomial time algorithms and not known to be NP-hard. I'm interested in problems such that a candidate problem in NPI is reducible to it but there is no known reduction from it to the NPI problem and it is not known to be NP-hard.
>Are there any know... |
Short Answer
======
The cache efficiency argument has already been explained in detail. In addition, there is an intrinsic argument, why Quicksort is fast. If implemented like with two “crossing pointers”, [e.g. here](http://algs4.cs.princeton.edu/23quicksort/Quick.java.html), the inner loops have a very small body. ... |
|algorithms| |
You can solve it iteratively. Suppose you have all solutions $S_n$ for the range $[0,n)$. Then you can easily construct the solutions $S_{n+2}$ from $S_n$. The size grows extremely quickly with $n$, so it may be good to write a generator rather than to hold all the sets in memory, see Python example below.
def p... |
While there are already many lovely ansewers to the question, I think it would be nice to point out the basic, general, trick behind them.
**It is much easier to generate unique combinations if you can have a total ordering of the elements to be combined**. This way, uniqueness is guaranteed if we only allow sorted ... |
Seeing that in the [Chomsky Hierarchy][1] Type 3 languages can be recognised by a state machine with no external memory (i.e., a finite automaton), Type 2 by a state machine with a *single* stack (i.e. a push-down automaton) and Type 0 by a state machine with *two* stacks (or, equivalently, a tape, as is the case for T... |
null |
Is Smoothed Analysis used outside academia? |
null |
The science and art of determining algorithm properties of algorithms, in particular runtime and space usage. |
null |
Theoretical results and techniques applied in practical settings. |
null |
I could be wrong, but I view smoothed analysis as a way to *explain* the in-practice behaviour of algorithms that have bad theoretical guarantees (simplex, k-means, and so on). I'm not sure what it would mean to *use* smoothed analysis in practice, except to justify the use of a particular heuristic with bad worst-case... |
Closure Properties
----
Of all language classes from the Chomsky hierarchy, only regular and context-sensitive languages are closed under **complementation**. Hence this is a sort of unique feature of context-sensitive languages.
In contrast to context-free languages, CS are also closed under intersection and [s... |
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... |
EPAL, the language of even palindromes, is defined as the language generated by the following unambiguous context-free grammar:
> $S \rightarrow a a$
> $S \rightarrow b b$
> $S \rightarrow a S a$
> $S \rightarrow b S b$
EPAL is the 'bane' of many parsing algorithms: I have yet to encounter any parsin... |
Is there any nongeneral CFG parsing algorithm that recognises EPAL? |
|formal-languages|formal-grammars|parsers| |
Assume a computer has a precise clock which is not initialized. That is, the time on the computer's clock is the real time plus some constant offset. The computer has a network connection and we want to use that connection to determine the constant offset $B$.
The simple method is that the computer sends a query to ... |
Clock synchronization in a network with asymmetric delays |
|clocks| |
Consider an inductive type which has some recursive occurrences in a nested, but strictly positive location. For example, trees with finite branching with nodes using a generic list data structure to store the children.
Inductive LTree : Set := Node : list LTree -> LTree.
The naive way of defining a recursive... |
Recursive definitions over an inductive type with nested components |
|coq|recursion| |
In context-free languages, at any point of the input parsing, the automaton is in a state defined by its 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 generates a sub-language of the one generated by th... |
null |
Considering this pseudo-code of a 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
... |
Evaluating the average time complexity of a given bubblesort algorithm. |
null |
Complexity theory classifies problems with respect to their computational hardness, i.e. which machine models can solve them under which restricitons. |
null |
Undecidability is the defining property of those formal languages which cannot be decided by any Turing machine. In other words, for any undecidable language, there exists no Turing machine which can, in a finite number of moves, both explicitly accept every string in the language and explicitly reject every string not... |
null |
I have an assignment for my data structures class. I need to create an algorithm to see if a binary tree is a binary search tree as well as count how many complete branches are there (a parent node with both left and right children nodes) with an assumed global counting variable.
So far I have
void BST(tree T... |
Help with a BST algorithm |
|algorithms| |
I have an assignment for my data structures class. I need to create a recursive algorithm to see if a binary tree is a binary search tree as well as count how many complete branches are there (a parent node with both left and right children nodes) with an assumed global counting variable.
So far I have
void B... |
My three comments above are three hints to problems with your code.
1. Unless you have already specifically defined how a compare operator should handle the node data type, most likely comparing two nodes directly won't do what you want. What you probably meant was to compare the fields stored in the nodes, for exa... |
|clocks|distributed-systems|computer-networks| |
|type-theory|logic|coq|recursion| |
It's a known fact that every LTL formula can be expressed by a Buchi $\omega$-automata. But, apparently, Buchi automata is a more powerful, expressive model. I've heard somewhere that Buchi automata are equivalent to linear-time $\mu$-calculus (that is, $\mu$-calculus with usual fixpoints and only one temporal operator... |
Equivalence of Buchi automata and linear $\mu$-calculus |
|logic|automata|reference-request| |
Let us call a context-free language deterministic if and only if it can be accepted by a deterministic push-down automaton, and nondeterministic otherwise.
Let us call a context-free language inherently ambiguous if and only if all context-free grammars which generate the language are ambiguous, and unambiguous othe... |
Are there inherently ambiguous and deterministic context-free languages? |
|formal-languages|formal-grammars|automata| |
One can imagine using a variety of data structures for storing information for use by state machines. For instance, push-down automata store information in a stack, and Turing machines use a tape. State machines using queues, and ones using two multiple stacks or tapes, have been shown to be equivalent in power to Turi... |
Determining capabilities of a min-heap (or other exotic) state machines |
|formal-languages|automata| |
If a language $L$ is deterministic, it is accepted by some deterministic push-down automaton, which in turn means there is some LR(1) grammar describing the language, and as every LR(1) grammar is unambiguous, this means that $L$ cannot be inherently ambiguous. Knuth proved this in his paper in which he introduced LR(1... |
|automata|logic|reference-request|formal-methods|model-checking| |
One can imagine using a variety of data structures for storing information for use by state machines. For instance, push-down automata store information in a stack, and Turing machines use a tape. State machines using queues, and ones using two multiple stacks or tapes, have been shown to be equivalent in power to Turi... |
null |
One can imagine using a variety of data structures for storing information for use by state machines. For instance, push-down automata store information in a stack, and Turing machines use a tape. State machines using queues, and ones using two multiple stacks or tapes, have been shown to be equivalent in power to Turi... |
In things like this, it's often easier to think backwards, so first consider what you need. From your description, let's list them:
- Recursion
- Validity
- Count of complete nodes
OK, that's a fairly short list, this should be manageable. Let's start with an empty method and I'll add description of what should... |
As others have already indicated in comments, you really have two unrelated functions here: testing whether the tree is a search tree, and counting the complete branches. Unless the assignment specifically calls for it, I would write two separate functions.
Let's see abount counting the complete branches first. That... |
I need to create a recursive algorithm to see if a binary tree is a binary search tree as well as count how many complete branches are there (a parent node with both left and right children nodes) with an assumed global counting variable. This is an assignment for my data structures class.
So far I have
void... |
Algorithm to test whether a binary tree is a search tree and count complete branches |
|algorithms|recursion|trees| |
null |
I need to create a recursive algorithm to see if a binary tree is a binary search tree as well as count how many complete branches are there (a parent node with both left and right children nodes) with an assumed global counting variable. This is an assignment for my data structures class.
So far I have
void... |
You can recognize the canonical non-context-free (but context-sensitive) language $\{ a^n b^n c^n\ |\ n \geq 1 \}$ with this type of state machine. The crux is that you add tokens to the heap for every $a$ character, and while parsing the $b$ characters, you add 'larger' tokens to the heap, so they only end up at the b... |
I claim that a min-heap automaton (HA) with finite heap alphabet can accept $L = \{ a^nb^nc^n \mid n \in \mathbb{N} \} \in \mathrm{CSL} \setminus \mathrm{CFL}$.
Assumptions: Similar to PDA, our transition function consumes the top most heap symbol and writes back an arbitrary number of heap symbols. The heap initial... |
I claim that a min-heap automaton (HA) with finite, totally ordered heap alphabet can accept $L = \{ a^nb^nc^n \mid n \in \mathbb{N} \} \in \mathrm{CSL} \setminus \mathrm{CFL}$.
Assumptions: Similar to PDA, our transition function consumes the top most heap symbol and writes back an arbitrary number of heap symbols.... |
**Claim:** $\mathrm{HAL}$ (the class of languages accepted by min-heap automata) and $\mathrm{CFL}$ are incomparable.
###$\mathrm{HAL} \setminus \mathrm{CFL} \neq \emptyset$###
A min-heap automaton (HA) with finite, totally ordered heap alphabet accepts $L = \{ a^nb^nc^n \mid n \in \mathbb{N} \} \in \mathrm{CSL} ... |
In the first system what you call subtyping are these two rules:
$$\dfrac{Γ \vdash M:T_1 ∧ T_2}{Γ \vdash M:T_1}(∧E_1)\quad\dfrac{Γ \vdash M:T_1 ∧ T_2}{Γ \vdash M:T_2}(∧E_2)$$
They are elimination rules for $∧$; without them the connective $∧$ is more or less useless.
In the second system (with connectives $∨$ ... |
One can imagine using a variety of data structures for storing information for use by state machines. For instance, push-down automata store information in a stack, and Turing machines use a tape. State machines using queues, and ones using two multiple stacks or tapes, have been shown to be equivalent in power to Turi... |
In the first system what you call subtyping are these two rules:
$$\dfrac{Γ, x:T_1 \vdash S}{Γ, x:T_1 ∧ T_2 \vdash S}(∧E_1)\quad\dfrac{Γ, x:T_2 \vdash S}{Γ, x:T_1 ∧ T_2 \vdash S}(∧E_2)$$
They correspond to elimination rules for $∧$; without them the connective $∧$ is more or less useless.
In the second system ... |
This is obviously a problem specific to Coq since I believe there are nicer ways to get around it with some other proof assistants (I'm looking at Agda)
At first I thought <code>r</code> was not recognized as structurally smaller because the structure is only about the inductive definition currently handled by <code... |
In her 1987 seminal paper Dana Angluin presents a polynomial time algorithm for learning a DFA from membership queries and theory queries (counterexamples to a proposed DFA).
She shows that if you are trying to learn a minimal DFA with $n$ states, and your largest countexample is of length $m$, then you need to make... |
Are there improvements on Dana Angluin's algorithm for learning regular sets |
|algorithms|learning-theory|machine-learning| |
Initially, [Matroids][1] were introduced to generalize the notions of linear independence of a collection of subsets $E$ over some ground set $I$. Certain problems that contain this structure permit greedy algorithms to find optimal solutions. The concept of [Greedoids][2] was later introduced to generalize this struct... |
How fundamental are matroids and greedoids in algorithm design? |
|algorithms|combinatorics|optimization| |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.