7

In book Algorithms fourth edition by Robert Sedgewick on page 200, it says "for example, if you have 1GB of memory on your computer (1 billion bytes), you cannot fit more than about 32 million int values."

I got confused after my calculation: 1,000,000,000 bytes/4 bytes = 250 million

How the author got 32 million?

The book describes like below:

enter image description here

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Max
  • 1,012
  • 1
  • 9
  • 15

3 Answers3

7

The author has acknowledged that this is an error in this book website, please refer to the link as follows: http://algs4.cs.princeton.edu/errata/errata-printing3.php

Max
  • 1,012
  • 1
  • 9
  • 15
5

1 gigabit = 1073741824 bit
1 int = 32 bit
calculation = (1073741824/32) = (32 * 10242) = (32 * 220) = 32 million

If author meant gigabytes then answer would be (32 * 8) million = 256 million

shaggy007
  • 69
  • 8
  • 2
    `32 * 2^20 = 33.554.432 != 32000000 = 32*10^6 = 32 millions`. Please use the correct terminology. – Margaret Bloom Feb 22 '16 at 10:44
  • 1
    In binary systems 1k = 1024, 1M = 1024k = 1024 * 1024 = 2^20 so here 32 million or 32 Mega = 32 * 2^20 here only unit is not present , i. e. bit – shaggy007 Feb 22 '16 at 11:02
  • 2
    *M* is a standard [ISU](https://en.wikipedia.org/wiki/International_System_of_Units) suffix that means `10^6`. **For whatever computation you are doing, in any base**. For long time it **had** a special meaning for CS and that gave rise to ambiguities (never have bought an HDD?) , but now the problem has been settled with the binary suffix *Mi* (2^20). Perpetuating an old misleading use is dangerous. So please, use the correct terminology. – Margaret Bloom Feb 22 '16 at 11:18
0

Answer is 268405456 we can fit in 1 gb

How ? Let's find out

Int size is 4 byte

1kb  can conation =1024/4=256 int number.
 1mb can store=256*1024=262144
 1gb can store=262144*1024=268405456  int  value