Chapter 2 The Fundamentals: Algorithms, the Integers, and Matrices - PowerPoint PPT Presentation

About This Presentation
Title:

Chapter 2 The Fundamentals: Algorithms, the Integers, and Matrices

Description:

Chapter 2 The Fundamentals: Algorithms, the Integers, and Matrices Algorithm: specifying a sequence of steps used to solve a problem. Computational complexity of an ... – PowerPoint PPT presentation

Number of Views:179
Avg rating:3.0/5.0
Slides: 33
Provided by: chen272
Learn more at: https://www.tnstate.edu
Category:

less

Transcript and Presenter's Notes

Title: Chapter 2 The Fundamentals: Algorithms, the Integers, and Matrices


1
Chapter 2 The Fundamentals Algorithms, the
Integers, and Matrices
  • Algorithm specifying a sequence of steps used
    to solve a problem.
  • Computational complexity of an algorithm what
    are the computer resources needed to use this
    algorithm to solve a problem of a specified size?
  • Integers properties of integers, division of
    integers, algorithms involving integers.
  • Matrices basic material about matrices, matrix
    arithmetic.

2
2.1 Algorithms
Definition 1. An algorithm is a finite sequence
of precise instructions for performing a
computation or for solving a problem.
  • Solution
  • Set the temporary maximum equal to the first
    integer in the sequence.
  • Compare the next integer in the sequence to the
    temporary maximum, and set the larger one to be
    temporary maximum.
  • Repeat the previous step if there are more
    integers in the sequence.
  • Stop when there are no integers left in the
    sequence. The temporary maximum at this point is
    the maximum in the sequence.

3
  • The properties of algorithms
  • Input
  • Output
  • Definiteness
  • Correctness
  • Finiteness
  • Effectiveness
  • Generality

4
Example 2 Describe an algorithm for finding an
element x in a list of distinct elements
5
(No Transcript)
6
2.2 Complexity of Algorithms
Assume that both algorithms A and B solve the
problem P. Which one is better?
  • Time complexity the time required to solve a
    problem of a specified size.
  • Space complexity the computer memory required
    to solve a problem of a specified size.

The time complexity is expressed in terms of the
number of operations used by the algorithm.
  • Worst case analysis the largest number of
    operations needed to solve the given problem
    using this algorithm.
  • Average case analysis the average number of
    operations used to solve the problem over all
    inputs.

7
Number of operations
8
(No Transcript)
9
(No Transcript)
10
Orders of Growth
Running Time necessary operations
Operation Per second
instant 1 second 11.5 days Never end days
instant Instant 1 second Never end days
Using silicon computer, no matter how fast CPU
will be you can never solve the problem whose
running time is exponential !!!
11
Asymptotic Notations O-notation
12
Example 3 Prove 2n1O(n)
13
2.2 The Integers and Division
  • We discuss the properties of integers which
    belongs to
  • the branch of Mathematics called number theory.

14
  • Basic properties of divisibility of integers
  • Theorem 1. Let a, b, and c be integers. Then
  • If ab and ac, then a(bc).
  • If ab, then abc for all integers c.
  • If ab and bc, then ac.

Proof
  1. There are s and t such that bas and cat.
    Therefore, bca(st).
  2. There is s such that bas. Therefore, bca(sc)
  3. There are s and t such that bas and cbt,
    therefore, ca(st)

15
Definition 2. A positive integer p greater than
1 is called prime if the only positive factors of
p are 1 and p. A positive integer that is greater
than 1 and is not prime is called composite.
  • The primes less than 100 are 2, 3, 5, 7, 11, 13,
    17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61,
    67, 71, 73, 79, 83, 89 and 97.

Theorem 2. Every positive integer can be written
uniquely as the uniquely as the product of primes
in order of increasing size.
16
(No Transcript)
17
Definition 3. Let a and b be integers. The
largest integer d such that da and db is called
the greatest common divisor of a and b, denoted
by gcd(a,b).
Definition 4. The integers a and b are relatively
prime if gcd(a,b)1.
Definition 5. The least common multiple of the
positive integers a and b is the smallest
positive integer that is divisible by both a and
b, denoted by lcm(a,b).
18
Definition 6. Let a be an integer and m be a
positive integer. We denoted by a mod m the
remainder when a is divided by m.
19
2.4 Integers and Algorithms
  • The Euclidean Algorithm Find the greatest
    common divisor of two positive integers

Lemma 1 Let abqr, where a,b,q, and r are
integers. Then gcd(a,b)gcd(b,r).
20
Solution
Hence, gcd(414,662)2, since 2 is the last
nonzero remainder.
21
  • Representation of integers

22
(No Transcript)
23
  • Algorithm for integer operations

Addition of a and b
24
Multiplication of a and b
a
1 1 0 1 0 1 1 1
1 0 1 1 0 0 0 0 1 1 0 1 0 0 0
0 1 0
b
a shifts 0 place
a shifts 1 place
a shifts 3 places
25
2.6 Matrices
26
(No Transcript)
27
  • Algorithms for matrix multiplication

28
  • Transposes and powers of matrices

29
  • Zero-One Matrices

A matrix with entries that are either 0 or 1 is
called a zero-one matrix.
30
(No Transcript)
31
(No Transcript)
32
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com