Most Popular
1500 questions
74
votes
4 answers
Find median of unsorted array in $O(n)$ time
To find the median of an unsorted array, we can make a min-heap in $O(n\log n)$ time for $n$ elements, and then we can extract one by one $n/2$ elements to get the median. But this approach would take $O(n \log n)$ time.
Can we do the same by some…
Luv
- 861
- 1
- 7
- 5
73
votes
7 answers
Are there minimum criteria for a programming language being Turing complete?
Does there exist a set of programming language constructs in a programming language in order for it to be considered Turing Complete?
From what I can tell from wikipedia, the language needs to support recursion, or, seemingly, must be able to run…
Khanzor
- 1,471
- 1
- 13
- 11
73
votes
4 answers
What is the novelty in MapReduce?
A few years ago, MapReduce was hailed as revolution of distributed programming. There have also been critics but by and large there was an enthusiastic hype. It even got patented! [1]
The name is reminiscent of map and reduce in functional…
Raphael
- 73,212
- 30
- 182
- 400
73
votes
10 answers
Minimum spanning tree vs Shortest path
What is the difference between minimum spanning tree algorithm and a shortest path algorithm?
In my data structures class we covered two minimum spanning tree algorithms (Prim's and Kruskal's) and one shortest path algorithm (Dijkstra's).
Minimum…
flashburn
- 1,233
- 1
- 12
- 22
70
votes
9 answers
Are there any problems that get easier as they increase in size?
This may be a ridiculous question, but is it possible to have a problem that actually gets easier as the inputs grow in size? I doubt any practical problems are like this, but maybe we can invent a degenerate problem that has this property. For…
dsaxton
- 933
- 6
- 9
69
votes
3 answers
Knapsack problem -- NP-complete despite dynamic programming solution?
Knapsack problems are easily solved by dynamic programming. Dynamic programming runs in polynomial time; that is why we do it, right?
I have read it is actually an NP-complete problem, though, which would mean that solving the problem in polynomial…
Strin
- 1,515
- 1
- 11
- 16
69
votes
10 answers
Can a dynamic language like Ruby/Python reach C/C++ like performance?
I wonder if it is possible to build compilers for dynamic languages like Ruby to have similar and comparable performance to C/C++? From what I understand about compilers, take Ruby for instance, compiling Ruby code can't ever be efficient because…
Ichiro
- 815
- 1
- 7
- 5
69
votes
12 answers
Why don't compilers automatically insert deallocations?
In languages like C, the programmer is expected to insert calls to free. Why doesn't the compiler do this automatically? Humans do it in a reasonable amount of time(ignoring bugs), so it is not impossible.
EDIT: For future reference, here is another…
Milton Silva
- 845
- 1
- 7
- 8
69
votes
9 answers
What would be the real-world implications of a constructive $P=NP$ proof?
I have a high-level understanding of the $P=NP$ problem and I understand that if it were absolutely "proven" to be true with a provided solution, it would open the door for solving numerous problems within the realm of computer science.
My question…
RLH
- 869
- 1
- 8
- 10
67
votes
2 answers
Are there subexponential-time algorithms for NP-complete problems?
Are there NP-complete problems which have proven subexponential-time algorithms?
I am asking for the general case inputs, I am not talking about tractable special cases here.
By sub-exponential, I mean an order of growth above polynomials, but…
ksb
- 801
- 1
- 7
- 5
67
votes
14 answers
Is C actually Turing-complete?
I was trying to explain to someone that C is Turing-complete, and realized that I don't actually know if it is, indeed, technically Turing-complete. (C as in the abstract semantics, not as in an actual implementation.)
The "obvious" answer…
TLW
- 1,500
- 1
- 10
- 16
67
votes
2 answers
What happens to the cache contents on a context switch?
In a multicore processor, what happens to the contents of a core's cache (say L1) when a context switch occurs on that cache?
Is the behaviour dependent on the architecture or is it a general behaviour followed by all chip manufacturers?
Ankit
- 1,337
- 2
- 14
- 18
67
votes
7 answers
Is legislation NP-complete?
I would like to know if there has been any work relating legal code to complexity. In particular, suppose we have the decision problem "Given this law book and this particular set of circumstances, is the defendant guilty?" What complexity class…
Gaslight Deceive Subvert
- 1,302
- 1
- 9
- 15
66
votes
3 answers
In-place algorithm for interleaving an array
You are given an array of $2n$ elements
$$a_1, a_2, \dots, a_n, b_1, b_2, \dots b_n$$
The task is to interleave the array, using an in-place algorithm such that the resulting array looks like
$$b_1, a_1, b_2, a_2, \dots , b_n, a_n$$
If the in-place…
Aryabhata
- 6,291
- 2
- 36
- 47
66
votes
8 answers
Distributed vs parallel computing
I often hear people talking about parallel computing and distributed computing, but I'm under the impression that there is no clear boundary between the 2, and people tend to confuse that pretty easily, while I believe it is very…
Charles Menguy
- 1,193
- 1
- 10
- 12