Questions tagged [knuth]

Donald E. Knuth is a computer scientist, best known as the author of the series of books on algorithms The Art of Computer Programming and the creator of the TeX typesetting system.

80 questions
16
votes
2 answers

WordCount: how inefficient is McIlroy's solution?

Long story short: in 1986 an interviewer asked Donald Knuth to write a program that takes a text and a number N in input, and lists the N most used words sorted by their frequencies. Knuth produced a 10-pages Pascal program, to which Douglas McIlroy…
izabera
  • 609
  • 5
  • 11
14
votes
2 answers

"char*" with an unusual memory word size (Knuth's MIX architecture)

The original MIX architecture features 6-bit bytes and memory is addressed as 31-bit words (5 bytes and a sign bit). As a thought exercise I'm wondering how the C language can function in this environment, given: char has at least 8 bits (annex E…
13
votes
11 answers

C for loop implemented differently than other languages?

I read the following in a review of Knuth's "The Art of Computer Programming": "The very 'practicality' means that the would-be CS major has to learn Kernighan's mistakes in designing C, notably the infamous fact that a for loop evaluates the for…
Tristan Havelick
  • 58,645
  • 19
  • 52
  • 64
12
votes
2 answers

Why does Knuth use this clunky decrement?

I'm looking at some of Prof. Don Knuth's code, written in CWEB that is converted to C. A specific example is dlx1.w, available from Knuth's website At one stage, the .len value of a struct nd[cc] is decremented, and it is done in a clunky way: …
Ed Wynn
  • 253
  • 1
  • 5
9
votes
6 answers

Computing (a*b) mod c quickly for c=2^N +-1

In 32 bit integer math, basic math operations of add and multiply are computed implicitly mod 2^32, meaning your results will be the lowest order bits of the add or multiply. If you want to compute the result with a different modulus, you certainly…
SPWorley
  • 10,852
  • 9
  • 41
  • 61
9
votes
3 answers

The Art of Computer Programming exercise question: Chapter 1, Question 8

I'm doing the exercises to TAOCP Volume 1 Edition 3 and have trouble understanding the syntax used in the answer to the following exercise. Chapter 1 Exercise 8 Computing the greatest common divisor of positive integers m & n by specifying…
Hortitude
  • 12,632
  • 16
  • 54
  • 71
9
votes
3 answers

How do the operations LDA, STA, SUB, ADD, MUL and DIV work in Knuth's machine language MIX?

I have been reading the Art of Computer Programming by Donald Knuth Volume 1. Now I finished the first part where all the mathematics were explained and it was quite a pleasure. Unfortunately, on p. 121 he starts explaining this fictional machine…
Erwin Rooijakkers
  • 8,898
  • 13
  • 60
  • 124
8
votes
0 answers

Is there a reason for which Donald Knuth choose procedural programming instead of functional programming?

Donald Knuth's Art of Computer Programming Series uses his own procedural assembly languaged called MIX. Now, the question becomes: should Knuth have used a functional language to describe his algorihtms? Should TeX have been written in a functional…
7
votes
2 answers

Optimize Leaper Graph algorithm?

During a 45 minute technical interview with Google, I was asked a Leaper Graph problem. I wrote working code, but later was declined the job offer because I lacked Data structure knowledge. I'm wondering what I could have done better. The problem…
Leo Ufimtsev
  • 4,670
  • 4
  • 31
  • 43
6
votes
1 answer

How does division work in MIX?

Can someone explain to me how division in MIX (from TAOCP by Knuth) works on a byte-to-byte basis? rA = |-| . . . .0| rX = |+|1235|0|3|1| The memory location 1000 contains |-|0|0|0|2|0|. When you execute the operation DIV 1000 the registers…
Ruben Steins
  • 2,702
  • 4
  • 27
  • 46
6
votes
1 answer

Knuth the art of computer programming ex 1.1.8

I can't figure out what Knuth meant in his instructions for an exercise 8 from Chapter 1.1. The task is to make an efficient gcd algorithm of two positive integers m and n using his notation theta[j], phi[j], b[j] and a[j] where theta and phi are…
6
votes
3 answers

Sorting 5 elements with minimum element comparison

I have to model the execution plan of sorting a list of 5 elements, in python, using the minimum number of comparisons between elements. Other than that, the complexity is irrelevant. The result is a list of pairs representing the comparisons needed…
slezica
  • 63,258
  • 20
  • 91
  • 152
5
votes
5 answers

generating poisson variables in c++

I implemented this function to generate a poisson random variable typedef long unsigned int luint; luint poisson(luint lambda) { double L = exp(-double(lambda)); luint k = 0; double p = 1; do { k++; p *=…
Bob
  • 9,535
  • 20
  • 81
  • 129
5
votes
2 answers

How is the Knuth Sequence properly implemented for a shellsort in Java?

Can someone please provide a simple working sample of a shellsort in Java that uses the Knuth Sequence? I looked in several places over the internet but can't find an explanation that works well for me. I understand shellsort on a conceptual level -…
Dielan
  • 61
  • 1
  • 2
5
votes
1 answer

What is Knuth's WEB?

I have been trying to figure out what Donald Knuth's WEB is, but it is really conflicting. From what I can glean from the web page is that it's something like doxygen, but all of the sources I am reading insist that it is a programming language.…
HSchmale
  • 1,541
  • 2
  • 17
  • 40
1
2 3 4 5 6