Most Popular

1500 questions
42
votes
9 answers

Algorithm to find diameter of a tree using BFS/DFS. Why does it work?

This link provides an algorithm for finding the diameter of an undirected tree using BFS/DFS. Summarizing: Run BFS on any node s in the graph, remembering the node u discovered last. Run BFS from u remembering the node v discovered last. d(u,v) is…
curryage
  • 531
  • 2
  • 7
  • 8
42
votes
2 answers

What can Idris not do by giving up Turing completeness?

I know that Idris has dependent types but isn't turing complete. What can it not do by giving up Turing completeness, and is this related to having dependent types? I guess this is quite a specific question, but I don't know a huge amount about…
Squidly
  • 531
  • 5
  • 8
41
votes
6 answers

Sorting functions by asymptotic growth

Assume I have a list of functions, for example $\qquad n^{\log \log(n)}, 2^n, n!, n^3, n \ln n, \dots$ How do I sort them asymptotically, i.e. after the relation defined by $\qquad f \leq_O g \iff f \in O(g)$, assuming they are indeed pairwise…
JAN
  • 619
  • 1
  • 6
  • 10
41
votes
4 answers

What is the name the class of functions described by O(n log n)?

In "Big O", common notations have common names (instead of saying, "Oh of some constant factor"): O(1) is "Constant" O(log n) is "Logarithmic" O(n) is "Linear" O(n^2) is "Quadratic" O(n * log n) is ??? Is it just "n log n" or does it have a special…
GlenPeterson
  • 545
  • 1
  • 4
  • 10
41
votes
2 answers

Difference Between Small and Big-step Operational Semantics

What's the fundamental difference(s) between small and big-step operational semantics? I'm having a hard time grasping what it is and the motivation for having the two.
Simon Morgan
  • 513
  • 1
  • 4
  • 7
41
votes
8 answers

What determines the "speed" of a programming language?

Suppose a program was written in two distinct languages, let them be language X and language Y, if their compilers generate the same byte code, why I should use language X instead of the language Y? What defines that one language is faster than…
Rodrigo Valente
  • 549
  • 1
  • 4
  • 7
41
votes
6 answers

How does a computer work?

I have been a computer nerd for many many years. I can program in quite a few languages, and I can even build them. I sat down with a buddy the other day and asked how a computer actually takes electricity and does something with it, and we just…
Christian
  • 519
  • 5
  • 6
41
votes
7 answers

What is the definition of Computer Science, and what is the Science within Computer Science?

I am pursuing a BS in Computer Science, but I am at an early point of it, and I am pretty sure I will be happy with my choice given that it seems like an academically and career flexible education to pursue. Having said that, there seems to be a…
user10744
41
votes
2 answers

How does Tarjan's pseudocode work (explained to someone familiar with C or Java)?

The Short Story A famous computer scientist, Tarjan, wrote a book years ago. It contains absolutely bizarre pseudocode. Would someone please explain it? The Long Story Tarjan is known for many accomplishments, including the fact that he was the…
41
votes
6 answers

Clock synchronization in a network with asymmetric delays

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…
Gilles 'SO- stop being evil'
  • 43,613
  • 8
  • 118
  • 182
40
votes
7 answers

How does the computer determine whether a number is smaller or greater than another?

It might sound like a stupid question but I'm really curious to know how a computer knows that $1<2$? Also, how does a computer know that the order of integer is $1,2,3,4,5,\ldots$ and alphabet is A,B,C,D,...? Is it somewhere stored in the hardware…
Ricky Stam
  • 501
  • 1
  • 5
  • 7
40
votes
3 answers

Decision problems vs "real" problems that aren't yes-or-no

I read in many places that some problems are difficult to approximate (it is NP-hard to approximate them). But approximation is not a decision problem: the answer is a real number and not Yes or No. Also for each desired approximation factor,…
Ran G.
  • 20,684
  • 3
  • 60
  • 115
40
votes
4 answers

Why is linear programming in P but integer programming NP-hard?

Linear programming (LP) is in P and integer programming (IP) is NP-hard. But since computers can only manipulate numbers with finite precision, in practice a computer is using integers for linear programming. Because of this, shouldn't LP and IP be…
Sasha the Noob
  • 613
  • 1
  • 7
  • 9
40
votes
7 answers

Explaining the relevance of asymptotic complexity of algorithms to practice of designing algorithms

In algorithms and complexity we focus on the asymptotic complexity of algorithms, i.e. the amount of resources an algorithm uses as the size of the input goes to infinity. In practice, what is needed is an algorithm that would work fast on a finite…
Kaveh
  • 22,231
  • 4
  • 51
  • 111
40
votes
7 answers

Can PRNGs be used to magically compress stuff?

This idea occurred to me as a kid learning to program and on first encountering PRNG's. I still don't know how realistic it is, but now there's stack exchange. Here's a 14 year-old's scheme for an amazing compression algorithm: Take a PRNG and seed…
user15782