Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding assumptions about machine word size in analyzing computer algorithms

I am reading the book Introduction to Algorithms by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein.. In the second chapter under "Analyzing Algorithms" it is mentioned that :

We also assume a limit on the size of each word of data. For example , when working with inputs of size n , we typically assume that integers are represented by c lg n bits for some constant c>=1 . We require c>=1 so that each word can hold the value of n , enabling us to index the individual input elements , and we restrict c to be a constant so that the word size doesn't grow arbitrarily .( If the word size could grow arbitrarily , we could store huge amounts of data in one word and operate on it all in constant time - clearly an unrealistic scenario.)

My questions are why this assumption that each integer should be represented by c lg n bits and also how c>=1 being the case allows us to index the individual input elements ?

like image 615
Geek Avatar asked Jul 21 '12 12:07

Geek


1 Answers

first, by lg they apparently mean log base 2, so lg n is the number of bits in n.

then what they are saying is that if they have an algorithm that takes a list of numbers (i am being more specific in my example to help make it easier to understand) like 1,2,3,...n then they assume that:

  • a "word" in memory is big enough to hold any of those numbers.

  • a "word" in memory is not big enough to hold all the numbers (in one single word, packed in somehow).

  • when calculating the number of "steps" in an algorithm, an operation on one "word" takes one step.

the reason they are doing this is to keep the analysis realistic (you can only store numbers up to some size in "native" types; after that you need to switch to arbitrary precision libraries) without choosing a particular example (like 32 bit integers) that might be inappropriate in some cases, or become outdated.

like image 88
andrew cooke Avatar answered Sep 17 '22 17:09

andrew cooke