1 / 15

CMSC 203 / 0201 Fall 2002

CMSC 203 / 0201 Fall 2002. Week #4 – 16/18/20 September 2002 Prof. Marie desJardins. TOPICS. Algorithms Algorithmic complexity Integers. MON 9/16 ALGORITHMS (2.1). CONCEPTS / VOCABULARY. Algorithm: “Finite set of precise instructions”

nirav
Download Presentation

CMSC 203 / 0201 Fall 2002

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CMSC 203 / 0201Fall 2002 Week #4 – 16/18/20 September 2002 Prof. Marie desJardins

  2. TOPICS • Algorithms • Algorithmic complexity • Integers

  3. MON 9/16ALGORITHMS (2.1)

  4. CONCEPTS / VOCABULARY • Algorithm: “Finite set of precise instructions” • Properties: Input, output, definiteness (preciseness), correctness, finiteness, effectiveness, generality • Pseudocode • Searching algorithms • Linear (sequential) search • Binary search

  5. Examples • Exercise 2.1.2: Which characteristics of an algorithm does each of these procedures have or not have? • procedure double (n:positive integer)while n > 0 n := 2n • procedure divide (n: positive integer)while n >= 0begin m := 1/n n := n – 1end

  6. Examples II • Exercise 2.1.9: Describe an algorithm that inserts an integer x in the appropriate position into the list a1, a2, …, an of integers that are in increasing order. • Exercise 2.1.13: Describe an algorithm that produces the maximum, median, mean, and minimum of a set of three integers.

  7. WED 9/18ALGORITHM COMPLEXITY (2.2) ** Homework #2 due today! **

  8. CONCEPTS / VOCABULARY • Computational complexity, time complexity, (space complexity) • Worst-case, average-case • Exponential complexity, polynomial complexity, linear complexity, logarithmic complexity • Tractability, intractability, unsolvability (halting problem, Alan Turing), NP vs. P, NP-complete

  9. Examples • Find the worst-case and average-case number of steps and big-O time complexity of the algorithms developed in the last class: • Exercise 2.1.9: Describe an algorithm that inserts an integer x in the appropriate position into the list a1, a2, …, an of integers that are in increasing order. • Exercise 2.1.13: Describe an algorithm that produces the maximum, median, mean, and minimum of a set of three integers.

  10. Examples II • Exercise 2.2.13: Analyze the average-case performance of the linear search algorithm, if exactly half the time element x is not in the list, and if x is in the list, it is equally likely to be in any position.

  11. FRI 9/20INTEGERS AND DIVISION (2.3)

  12. CONCEPTS / VOCABULARY • Fundamental Theorem of Arithmetic • Primes, composite numbers • Factoring • Division (quotient, remainder) • a | b • Greatest common divisor, least common multiple, relative primes • Modular arithmetic, congruence • “The Division Algorithm” • Note: We’ll revisit pp. 120-125 when we get to Section 2.5.

  13. Examples • Example 2.3.2: Let n and d be positive integers. How many positive integers not exceeding n are divisible by d? • Theorem 2.3.3: If n is a composite integer, then n has a prime divisor less than or equal to n. • Example 2.3.5: Show that 101 is prime [using Theorem 2.3.3].

  14. Examples II • Write an algorithm to compute the prime factorization of n using the procedure on p. 115: • Divide n by successive primes, starting with 2. • If no prime factor n is found, then n is prime. • If a prime factor p is found, continue by factoring n/p. • Start with p instead of 2.

  15. Examples III • Exercise 2.3.19: Show that if 2n-1 is prime, then n is prime. [Hint: Use the identity 2ab-1 = (2a-1) (2a(b-1) + 2a(b-2) + … + 2a + 1).]

More Related