|
Algorithms and Data Structures in C++
by Alan Parker CRC Press, CRC Press LLC ISBN: 0849371716 Pub Date: 08/01/93 |
| Previous | Table of Contents | Next |
This chapter
N
denotes the set of natural
Definition 2.1
A sequence, x , over the real numbers is a function from the natural numbers into the real numbers:
x 1 is used to denote the first element of the sequence, x (1) In general,
and will be written as
Unless
then
For example,
Definition 2.2
If x and y are sequences, then x is of order at most y , written x ∈ O ( y ), if there exists a positive integer N and a positive number k such that
Definition 2.3
If x and y are sequences then x is of order exactly y , written, x ∈ Θ ( y ), if x ∈ Θ ( y ) and y ∈ O ( x ).
Definition 2.4
If x and y are sequences then x is of order at least y , written, x ∈ Ω ( y ), if y ∈ O ( x ).
Definition 2.5
The time complexity of an algorithm is the sequence
where
t
k
is the number of time steps required for solution of a problem of
Example 2.1
Time Complexity
The calculation of the time complexity for addition is illustrated in Example 2.1. A comparison of the order of several classical functions is shown in Table 2.1. The time required for a variety of operations on a 100 Megaflop machine is
| Function | n=1 | n=10 | n=100 | n=1000 | n=10000 |
|---|---|---|---|---|---|
| log( n ) | 3.32 | 6.64 | 9.97 | 13.3 | |
| n log ( n ) | 33.2 | 664 | 9.97×10 3 | 1.33×10 5 | |
| n 2 | 1 | 100 | 10000 | 1×10 6 | 1×10 8 |
| n 5 | 1 | 1×10 5 | 1×10 10 | 1×10 15 | 1×10 20 |
| e n | 2.72 | 2.2×10 4 | 2.69×10 43 | 1.97×10 434 | 8.81×10 4342 |
| n ! | 1 | 3.63×10 6 | 9.33×10 157 | 4.02×10 2567 | 2.85×10 35659 |
| Time | # of Operations |
|---|---|
| 1 second | 10 8 |
| 1 minute | 6 × 10 9 |
|
1
|
3.6 × 10 11 |
| 1 day | 8.64 × 10 12 |
| 1 year | 3.1536 × 10 15 |
| 1 century | 3.1536 × 10 17 |
|
100 trillion
|
3.1536 × 10 29 |
One of the major motivations for using Order as a complexity measure is to get a handle on the inductive growth of an algorithm. One must be extremely careful however to understand that the definition of Order is “in the limit.” For example, consider the time complexity functions
f
1
and
f
2
defined in Example 2.6. For these functions the
Example 2.2
Order
Example 2.3
Order
| Previous | Table of Contents | Next |
Copyright CRC Press LLC

Computer Organization and Design, Fourth Edition: The Hardware/Software Interface (The Morgan Kaufmann Series in Computer Architecture and Design)

C Programming Language (2nd Edition)

Operating Systems: Internals and Design Principles (7th Edition)

Computer Networking: A Top-Down Approach (5th Edition)