instruction stringlengths 0 29.8k ⌀ |
|---|
Quicksort vs. insertion sort on linked list: performance |
What does the notation `co-` mean when prefixing `co-NP`, `co-RE` (recursively enumerable), or `co-CE` (computably enumerable) ? |
What is co-something? |
|untagged| |
|complexity-theory|computability| |
I am not a data structures expert, but the usual theoretical approach to hashing is that one defines a *family* of functions (e.g., $h_{a,b}(x) = ax + b \mod p$) and then considers the behavior on a *worst case* input on a *randomly chosen* member of the family, where the adversary *doesn't know the random choice* in a... |
I'm really struggling with this property:
Let $X,Y$ be coherence spaces and $f: Cl(X) \rightarrow Cl(Y)$ be a monotone function.
$f$ is continuous if and only if $f(\bigcup_{x\in D} x)=\bigcup_{x \in D}f(x)$
$\forall D \subseteq Cl(X) $ such D is direct.
Many books give that as a definition of Scott-cont... |
Scott-continuous function: alternatives definitions |
|homework|semantics|computation-models|type-theory| |
I'm really struggling with this property:
> Let $X,Y$ be [coherence spaces](http://en.wikipedia.org/wiki/Coherent_space) and $f: Cl(X) \rightarrow Cl(Y)$ be a monotone function. $f$ is continuous if and only if $f(\bigcup_{x\in D} x)=\bigcup_{x \in D}f(x)$, for all $D \subseteq Cl(X)$ such that $D$ is direct.
> *... |
Scott-continuous functions: an alternative definition |
|semantics|type-theory| |
Often, in mathematical terminology, the prefix *co-* refers to a [dual](http://en.wikipedia.org/wiki/Duality_%28mathematics%29) in some sense. For complexity and computability classes, the prefix *co-* has a fixed meaning: if *X* is a class of decision problems, then *co-X* is the class of problems whose [complement](h... |
null |
See the graphical loveliness of this [little demo][1].
![quicksort][2].
[1]: http://people.bath.ac.uk/mir20/research_quicksort.html
[2]: https://i.stack.imgur.com/Cfgb2.gif |
See: [Mini ML][01] Specifically the Type Inference section.
[01]: http://v2matveev.blogspot.com/2010/05/f-parsing-simple-language.html |
|programming-languages|homework|semantics| |
null |
Why do you think it is that most C++ instructors teaching college level computer sciences discourage or even forbid using strings for text, instead requiring students to use character arrays?
I am assuming this methodology is somehow intended to teach good programming habits, but in my experience I don't see anythin... |
C++ Strings vs. Character Arrays |
|arrays|strings| |
|education|arrays|strings| |
How could I find the lower bound for finding kth smallest element using adversary argument.
Could someone explain how it is found. In many texts it is explained making use of arguments using medians. |
Finding kth smallest element using adversary arguments |
|algorithms|algorithm-analysis| |
How could I find the lower bound for finding kth smallest element using adversary argument.
Could someone explain how it is found. In many texts it is explained making use of arguments using medians.
[Wikipedia][1] says that tournament algorithm runs in O(n+klog n). And lower bound is given by [here][2]
[1... |
null |
How could I find the lower bound for finding $k$th smallest element using adversary argument.
Could someone explain how it is found. In many texts it is explained making use of arguments using medians.
[Wikipedia][1] says that tournament algorithm runs in $ O(n+k\log n) $. And lower bound is given by [here][2]
... |
null |
You may want to read the following, excellent, Jeff Erikson [notes][1].
[1]: http://compgeom.cs.uiuc.edu/~jeffe/teaching/497/02-selection.pdf |
As Ryan wrote, proving that a problem is not hard is not easy.
Let $Q$ be a problem in a complexity class $X$ and $S$ is closed w.r.t. $\leq$ reductions.
Proving that $Q$ is not $X$-hard w.r.t. $\leq$ is equivalent to separating the complexity class obtained by taking closure of $Q$ w.r.t. $\leq$. Now, if $Q$ is h... |
As Ryan wrote, proving that a problem is not hard is not easy.
Let $Q$ be a problem in a complexity class $X$ and $S$ is closed w.r.t. $\leq$ reductions.
Proving that $Q$ is not $X$-hard w.r.t. $\leq$ is equivalent to separating the complexity class obtained by taking closure of $Q$ w.r.t. $\leq$. Now, if $Q$ is h... |
Koenig and Moe's _Accelerated C++_ and Stroustrup's _Programming: Principles and Practice Using C++_ are using std::string and other components from the standard library from the start. If I remember correctly, they don't even present C arrays for Koenig and Moe and Stroustrup does it quite late in the book (perhaps ev... |
I have written a program to sort Linked Lists and I noticed that my insertion sort works much better than my quicksort algorithm.
Does anyone have any idea why this is?
Insertion sort has a complexity of $\Theta(n^2)$ and quicksort $O(n\log n)$ so therefore quicksort should be faster. I tried for random input size a... |
In many texts a lower bound for finding $k$th smallest element is derived making use of arguments using medians. How can I find one using an adversary argument?
[Wikipedia][1] says that tournament algorithm runs in $O(n+k\log n)$, and $n - k + \sum_{j = n+2-k}^{n} \lceil{\operatorname{lg}\, j}\rceil$ is [given][2] a... |
Lower bound for finding kth smallest element using adversary arguments |
I am not a data structures expert, but the usual theoretical approach to hashing is that one defines a *family* of functions (e.g., $h_{a,b}(x) = ax + b \mod p$) and then considers the behavior on a *worst case* input on a *randomly chosen* member of the family, where the adversary *doesn't know the random choice* in a... |
In the more algebraic side of theoretical computer science, co- means dual, as in [Gilles' answer][1], but it has a very precise interpretation. If the concept of interest (let's say *a product*) is formalised in Category Theory, then the dual (a *coproduct*) is the same concepts with the arrows going in the opposite d... |
|homework| |
null |
First, from a mathematical point of view, ∀x:T.P(x) does not imply ∃x:T.P(x). The implication holds if and only T is not empty. However, in programming languages, it is uncommon to deal with empty types (though it happens).
Still from a mathematical point of view, even when (∀x:T.P(x)) ⇒ (∃x:T.P(x)), the two are not... |
I would like to know whether a universally-quantified type Tₐ:
Tₐ = ∀X.{a:X,f:X→boolean}
is a sub-type, or special case, of an existentially-quantified type Tₑ with the same signature:
Tₑ = ∃X.{a:X, f:X→boolean}
I'd say "yes": If something is true "for all X" (∀X), then it must also be true "for som... |
Are universal types a sub-type, or special case, of existential types? |
|logic| |
The problem is that the analysis of Quicksort, as you have implemented it, assumes that accessing any element can be done at a constant cost, i.e. in $\mathcal O(1)$. This is not the case with linked lists.
Note that at the top of the `while (right > left) {` loop in your code, you cycle through all the elements unt... |
See: [Mini ML][01] Specifically the Type Inference section.
This contains sample code in F# for a complete parser of a simple functional language. More importantly the Type Inference section implements the Hindley-Milner algorithm which is what is found in most type inference system. The author also provides links t... |
I would like to know whether a universally-quantified type $T_a$: $$T_a = \forall X: \left\{ a\in X,f:X→\{T, F\} \right\}$$ is a sub-type, or special case, of an existentially-quantified type $T_e$ with the same signature: $$T_e = \exists X: \left\{ a\in X,f:X→\{T, F\} \right\}$$
I'd say "yes": If something is true ... |
null |
|complexity-theory|computability|terminology| |
I would like to know whether a universally-quantified type $T_a$: $$T_a = \forall X: \left\{ a\in X,f:X→\{T, F\} \right\}$$ is a sub-type, or special case, of an existentially-quantified type $T_e$ with the same signature: $$T_e = \exists X: \left\{ a\in X,f:X→\{T, F\} \right\}$$
I'd say "yes": If something is true ... |
|logic|type-theory|typing| |
Pedro's answer covers what is going wrong with your first attempt. But I want to talk about a few things when it comes to analyzing algorithms that may be a bit subtle.
**What is your algorithm?**
Before you can start analyzing an algorithm, you need to say exactly what you're doing. "Quicksort", for example, ... |
I can't say anything about "most" versus "some" programming instructors, but I can say that in a CS curriculum, the early programming courses have two goals:
* Prepare students for software engineering-type topics
* Get students used to what the basic operations a computer does are and how different implementation... |
null |
Which search/optimization problems can be reduced to the famous "Travel Salesman Problem"? For instance, I have a collection of N particles, in 3D, and there is a function which depends on their coordinates. I want to find which configuration of the system minimizes the value of the function. Can this problem or type o... |
Problems that can be reduced to the Travel Salesman Problem |
|optimization|search-problem| |
Pedro's answer covers what is going wrong with your first attempt. But I want to talk about a few things when it comes to analyzing algorithms that may be a bit subtle.
**What is your algorithm?**
Before you can start analyzing an algorithm, you need to say exactly what you're doing. "Quicksort", for example, ... |
Since TSP is NP-complete, most problems you'll encounter in practice can be. (NP is a pretty general class.) |
I guess it depends on what you're trying to teach in that course... "Computer Science" is a somewhat vague definition.
If the course is on Algorithms and Data Structures, then teaching students about `std::string` has absolutely no didactic value. Using `char` arrays as an introduction to arrays and operations there... |
null |
First, from a mathematical point of view, $\forall x:T, P(x)$ does not imply $\exists x:T,P(x)$. The implication holds if and only if $T$ is not empty. However, in programming languages, it is uncommon to deal with empty types (though it happens).
Still from a mathematical point of view, even when $(\forall x:T, P(x... |
|semantics| |
How about this?
[Computer Science Unplugged - Sorting Algorithms][1]
It doesn't quite cover all your questions, but it's a good start.
More resources on this topic are linked [here][2].
[1]: http://csunplugged.org/sites/default/files/activity_pdfs_full/unplugged-07-sorting_algorithms.pdf
[2]: http:/... |
I am going to briefly outline a sketch of an adversary argument.
Consider your selection algorithm playing against an opponent that we will call the adversary.The aim of the adversary is to provide an input $X$ for your algorithm that maximizes the number of comparison operations done by your algorithm. Indeed, your... |
null |
I am going to briefly outline a sketch of an adversary argument.
Consider your selection algorithm playing against an opponent that we will call the adversary.The aim of the adversary is to provide an input $X$ for your algorithm that maximizes the number of comparison operations done by your algorithm. Indeed, your... |
Suppose that we have a black-box $f$ which we can query and reset. When we reset $f$, the state $f_S$ of $f$ is set to an element chosen uniformly at random from the set $$\{0, 1, ..., n - 1\}$$ where $n$ is fixed and known for given $f$. To query $f$, an element $x$ (the guess) from $$\{0, 1, ..., n - 1\}$$ is provide... |
Algorithm to chase a moving target |
|algorithms|randomized-algorithms| |
How about this?
[Computer Science Unplugged - Sorting Algorithms][1]
It doesn't quite cover all your questions, but it's a good start.
More resources on this topic are linked [here][2].
They also made a video available that explains sorting algorithms (quicksort included) [here](https://www.youtube.com/wat... |
null |
|programming-languages|semantics| |
|complexity-theory|optimization|search-problem| |
Since TSP is [NP-complete][1], most problems you'll encounter in practice can be. (NP is a pretty general class.)
[1]: http://en.wikipedia.org/wiki/NP-complete |
I am given an exercise unfortunately by myself I didn't success.
>There is a set of rectangles $R_{1}..R_{n}$ and a rectangle $R_{0}$. Using plane sweeping algorithm determine if $R_{0}$ is completely covered by the set of $R_{1}..R_{n}$.
For more details about [Sweep line algorithm](http://en.wikipedia.org/wiki/... |
Rectangle Coverage by Sweep Line |
|algorithms|computational-geometry| |
Since TSP is [NP-complete][1], most problems you'll encounter in practice can be. (NP is a pretty general class.) A [classic paper of Karp][2] gives a large number of other NP-complete problems that, by definition, can be reduced to TSP.
[1]: http://en.wikipedia.org/wiki/NP-complete
[2]: http://www.cs.berke... |
I'm really struggling with this property:
> Let $X,Y$ be [coherence spaces](http://en.wikipedia.org/wiki/Coherent_space) and $f: Cl(X) \rightarrow Cl(Y)$ be a monotone function. $f$ is continuous if and only if $f(\bigcup_{x\in D} x)=\bigcup_{x \in D}f(x)$, for all $D \subseteq Cl(X)$ such that $D$ is direct.
> *... |
null |
I'm really struggling with this property:
> Let $X,Y$ be [coherence spaces](http://en.wikipedia.org/wiki/Coherent_space) and $f: Cl(X) \rightarrow Cl(Y)$ be a monotone function. $f$ is continuous if and only if $f(\bigcup_{x\in D} x)=\bigcup_{x \in D}f(x)$, for all $D \subseteq Cl(X)$ such that $D$ is direct.
> *... |
I'm trying to figure out a way I could represent a Facebook user as a vector. I decided to go with stacking the different attributes/parameters of the user into one big vector (i.e. age is a vector of size 100, where 100 is the maximum age you can have, if you are lets say 50, the first 50 values of the vector would be... |
Machine learning how to use the Facebook interest of a users to give a decision |
|machine-learning| |
The interests are [categorical data](http://en.wikipedia.org/wiki/Categorical_data) and may be modeled as binary variables (a user either likes them or he does not). |
The interests are [categorical data](http://en.wikipedia.org/wiki/Categorical_data) and may be modeled as binary variables (a user either likes them or he does not).
For what you can do with the data see [A Review on Data Clustering Algorithms for Mixed Data](http://computerresearch.org/stpr/index.php/gjcst/article... |
I am going to briefly outline a sketch of an adversary argument.
Consider your selection algorithm playing against an opponent that we will call the adversary.The aim of the adversary is to provide an input $X$ for your algorithm that maximizes the number of comparison operations done by your algorithm. Indeed, your... |
Let's start with $n$ axis-aligned rectangles, since there is a kind of easy direct argument. We'll sweep a vertical line. The events are the endpoints of horizontal edges of the rectangles. As we sweep we maintain a set of intervals on the sweep line that are "uncovered" by $R_i$, $i\ge 1$:
* Add the vertical int... |
A decision variant of the problem might be:
> Does there exist a configuration of the system such that the objective function assumes a value less than or equal to $y_0$?
It depends entirely upon the form of the objective function. Suppose that the objective function is constant, i.e., $f(x) = c$. Then a constant... |
A decision variant of the problem might be:
> Does there exist a configuration of the system such that the objective function assumes a value less than or equal to $y_0$?
It depends entirely upon the form of the objective function. Suppose that the objective function is constant, i.e., $f(x) = c$. Then a constant... |
There are some documents to be indexed, that means I need to read the docs and extract the words and index them by storing at which document they appear and at which position.
For each word initially I am creating a separate file. Consider 2 documents:
document 1
The Problem of Programming Communication with... |
Save binary tree in a file to store sets of data |
|binary-trees| |
The interests are [categorical data](http://en.wikipedia.org/wiki/Categorical_data) and may be modeled as binary variables (a user either likes them or he does not). You can subsume little-used categories under broader categories. For example, a user who likes a little-known horror movie can simply be marked as liking ... |
null |
I'm trying to use a color camera to track multiple objects in space. Each object will have a different color and in order to be able to distinguish well between each objects I'm trying to make sure that each color assigned to an object is as different from any color on any other object as possible.
In RGB space, we ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.