CMSC 203, Section 0401 - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

CMSC 203, Section 0401

Description:

UMBC CMSC 203, Section 0401 -- Fall 2004. 1. CMSC 203, Section ... Tractable/Intractable. Solvable/Unsolvable Halting Problem. Class P, Class NP. NP-Complete ... – PowerPoint PPT presentation

Number of Views:20
Avg rating:3.0/5.0
Slides: 17
Provided by: SusanMi6
Category:
Tags: cmsc | class | section

less

Transcript and Presenter's Notes

Title: CMSC 203, Section 0401


1
  • CMSC 203, Section 0401
  • Discrete Structures
  • Fall 2004
  • Matt Gaston
  • mgasto1_at_cs.umbc.edu
  • http//www.csee.umbc.edu/mgasto1/203

2
Algorithms Ch. 2.1-2.3
3
Definition
  • Book definition
  • Algorithm a finite set of precise instructions
    for performing a computation or for solving a
    problem
  • Better definition (?)
  • Algorithm An algorithm is a finite set of
    unambiguous, executable instructions that directs
    a terminating activity.

4
Algorithm Features
  • Input
  • Output
  • Definiteness
  • Correctness
  • Finiteness
  • Effectiveness
  • Generality

5
Linear Search
procedure linear search (xinteger, a1, a2, . . .
, an distinct integers) i 1 while (i ? n and
x ? ai) i i 1 if i ? n then location i
else location 0
10 13 17 1 4 18 3 5 11 9 8 16 2 7 6
14 15 19 20 18 12
How many steps? Worse case? On average?
6
Binary Search
procedure binary search (xinteger, a1, a2, . . .
, an increasing integers) i 1 j n while (i
? j) begin m ? (i j) / 2 ? if x ? am
then i m 1 else j m end if x ai then
location I else location 0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
16 17 18 19 20
7
Growth of Functions
  • Big-O Notation
  • C and k are called witnesses

Let f and g be functions from the set of integers
to the set of integers or the set of real numbers
to the set of real numbers. We say that f(x) is
O(g(x)) if there are constants C and k such
that f(x) ? C g(x) whenever x gt k.
8
Pictorial Big-O Notation
C g(x)
f(x)
g(x)
k
9
Example
  • 7x2 O(x3)

10
Combinations of Functions
  • f(x) anxn an-1xn-1 . . . a1x a0
  • f(x) O(xn)
  • (f1 f2)(x) O(max( g1(x), g2(x) ))
  • (f1f2)(x) O(g1(x)g2(x))

11
Big-Omega Notation
Let f and g be functions from the set of integers
to the set of integers or the set of real numbers
to the set of real numbers. We say that f(x) is
?(g(x)) if there are constants C and k such
that f(x) ? C g(x) whenever x gt k.
12
Big-Theta Notation
  • f(x) is of order g(x)

Let f and g be functions from the set of integers
to the set of integers or the set of real numbers
to the set of real numbers. We say that f(x) is
?(g(x)) if f(x) is O(g(x)) and f(x) is ?(g(x)).
13
Bubble Sort
procedure bubble sort (a1, a2, . . . , an) for i
1 to n 1 for j 1 to n i if aj gt
aj1 then interchange aj and aj1 a1, a2, . . .
, an is in increasing order
14
Insertion Sort
procedure insertion sort (a1, a2, . . . , an
real numbers with n ? 2) for j 2 to n begin i
1 while aj gt ai i i 1 m aj
for k 0 to j - i 1 aj-k aj-k-1 ai
m end a1, a2, . . . , an are sorted
15
Make Change!
16
Understanding Complexity
  • n!, 2n, n2, n log(n), n, log(n), 1
  • Tractable/Intractable
  • Solvable/Unsolvable Halting Problem
  • Class P, Class NP
  • NP-Complete
Write a Comment
User Comments (0)
About PowerShow.com