Introduction Dr. Ying Lu RAIK 283: Data Structures & Algorithms.

Slides:



Advertisements
Similar presentations
1 Chapter Six Algorithms. 2 Algorithms An algorithm is an abstract strategy for solving a problem and is often expressed in English A function is the.
Advertisements

The Design & Analysis of the algorithms Lecture by me M. Sakalli.
What is an algorithm? Informally: An Algorithm is a step by step method for solving a problem. It’s purpose is to break a larger task down so that each.
Design and Analysis of Algorithms - Chapter 1
Design and Analysis of Algorithms - Chapter 1
What is an algorithm? An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate.
CSC 2300 Data Structures & Algorithms January 30, 2007 Chapter 2. Algorithm Analysis.
The Design and Analysis of Algorithms
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Design and Analysis of Algorithms - Chapter 11 Algorithm An algorithm is a.
TK3043 Analysis and Design of Algorithms Introduction to Algorithms.
Design and Analysis of Algorithms
Design and Analysis of Algorithms Chapter Analysis of Algorithms Dr. Ying Lu August 28, 2012
CSCI 1900 Discrete Structures
Chapter 2 The Fundamentals: Algorithms, the Integers, and Matrices
COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 19 Recursion.
Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.
Extended Euclidean Algorithm Presented by Lidia Abrams Anne Cheng.
Intro to Computer Algorithms Lecture 1 Phillip G. Bradford Computer Science University of Alabama.
Chapter 3 (Part 3): Mathematical Reasoning, Induction & Recursion  Recursive Algorithms (3.5)  Program Correctness (3.6)
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 4 (Part 3): Mathematical Reasoning, Induction.
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
Additional Problems.
The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3.
Introduction to Algorithms By Mr. Venkatadri. M. Two Phases of Programming A typical programming task can be divided into two phases: Problem solving.
Data Structures and Algorithms Introduction to Algorithms M. B. Fayek CUFE 2006.
1 Section 2.1 Algorithms. 2 Algorithm A finite set of precise instructions for performing a computation or for solving a problem.
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. Chapter 1 Introduction.
Design and Analysis of Algorithms - Chapter 11 Algorithm b An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining.
Algorithms 1.Notion of an algorithm 2.Properties of an algorithm 3.The GCD algorithm 4.Correctness of the GCD algorithm 5.Termination of the GCD algorithm.
UNIT-I INTRODUCTION ANALYSIS AND DESIGN OF ALGORITHMS CHAPTER 1:
Analysis of Algorithms COME 355 Introduction. What is an algorithm? An algorithm is a sequence of unambiguous instructions for solving a problem, i.e.,
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3 rd ed., Ch. 1 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part 1. Complexity Bounds.
CS404 Design and Analysis of Algorithms BBy DDr. M V S Peri Sastry BB.E, PhD(BITS-Pilani)
Application: Algorithms Lecture 20 Section 3.8 Wed, Feb 21, 2007.
Introduction to design and analysis algorithm
R. Johnsonbaugh, Discrete Mathematics 5 th edition, 2001 Chapter 3 Algorithms.
Application: Algorithms Lecture 19 Section 3.8 Tue, Feb 20, 2007.
Chapter 4 With Question/Answer Animations 1. Chapter Summary Divisibility and Modular Arithmetic - Sec 4.1 – Lecture 16 Integer Representations and Algorithms.
1 Introduction to design and analysis algorithm. 2.
Fuw-Yi Yang1 Textbook: Introduction to Cryptography 2nd ed. By J.A. Buchmann Chap 1 Integers Department of Computer Science and Information Engineering,
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.
Agenda Review:  Relation Properties Lecture Content:  Divisor and Prime Number  Binary, Octal, Hexadecimal Review & Exercise.
Introduction to Algorithms
Chapter 4 (Part 3): Mathematical Reasoning, Induction & Recursion
TK3043 Analysis and Design of Algorithms
Chapter 1 Introduction Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
The Design and Analysis of Algorithms
Chapter 1 Introduction Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
What is an algorithm? An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate.
What is an algorithm? An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate.
What is an algorithm? An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate.
Introduction to the Design and Analysis of Algorithms
Introduction to The Design & Analysis of Algorithms
What is an algorithm? An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate.
Courtsey & Copyright: DESIGN AND ANALYSIS OF ALGORITHMS Courtsey & Copyright:
Computer Science 101 While Statement.
2008/09/24: Lecture 6b CMSC 104, Section 0101 John Y. Park
What is an algorithm? An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate.
What is an algorithm? An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate.
Discrete Math for CS CMPSC 360 LECTURE 12 Last time: Stable matching
Introduction to Algorithms
Application: Algorithms
Application: Algorithms
Introduction to Algorithms
CSC 380: Design and Analysis of Algorithms
Design and Analysis of Algorithms
Chapter 1 Introduction Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
What is an algorithm? An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate.
Presentation transcript:

Introduction Dr. Ying Lu RAIK 283: Data Structures & Algorithms

Giving credit where credit is due: Giving credit where credit is due: Most of the lecture notes are based on the slides from the Textbook ’ s companion website Most of the lecture notes are based on the slides from the Textbook ’ s companion website Several slides are from Jeff Edmonds of the York University Several slides are from Jeff Edmonds of the York University I have modified them and added new slides I have modified them and added new slides RAIK 283: Data Structures & Algorithms

Algorithm An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate input in a finite amount of time. An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate input in a finite amount of time.

A Problem Find the greatest common divisor of two nonnegative, non-both-zero integers m and n, denoted gcd(m,n) Find the greatest common divisor of two nonnegative, non-both-zero integers m and n, denoted gcd(m,n) gcd(m,n), the largest integer that divides both m and n evenly, i.e., with a remainder of zero gcd(m,n), the largest integer that divides both m and n evenly, i.e., with a remainder of zero

Greatest Common Divisor (GCD) Algorithm 1 Step 1 Assign the value of min{m,n} to t Step 1 Assign the value of min{m,n} to t Step 2 Divide m by t. If the remainder of this division is 0, go to Step 3; otherwise, to Step 4 Step 2 Divide m by t. If the remainder of this division is 0, go to Step 3; otherwise, to Step 4 Step 3 Divide n by t. If the remainder of this division is 0, return the value of t as the answer and stop; otherwise, proceed to Step 4 Step 3 Divide n by t. If the remainder of this division is 0, return the value of t as the answer and stop; otherwise, proceed to Step 4 Step 4 Decrease the value of t by 1. Go to Step 2 Step 4 Decrease the value of t by 1. Go to Step 2 Note: m and n are positive integers Note: m and n are positive integers

GCD Procedure 2 Step 1 Find the prime factors of m Step 1 Find the prime factors of m Step 2 Find the prime factors of n Step 2 Find the prime factors of n Step 3 Identify all the common factors in the two prime expansions found in Steps 1 and 2. If p is a common factor occurring i and j times in m and n, respectively, it should be repeated min{i, j} times Step 3 Identify all the common factors in the two prime expansions found in Steps 1 and 2. If p is a common factor occurring i and j times in m and n, respectively, it should be repeated min{i, j} times Step 4 Compute the product of all the common factors and return it as the GCD of m and n Step 4 Compute the product of all the common factors and return it as the GCD of m and n Note: as written, this procedure requires that m and n be integers greater than 1, since 1 is not a prime Note: as written, this procedure requires that m and n be integers greater than 1, since 1 is not a prime Is this procedure an algorithm? Is this procedure an algorithm?

Algorithm 2? Procedure 2 is not an algorithm unless we can provide an effective way to find prime factors of a number Procedure 2 is not an algorithm unless we can provide an effective way to find prime factors of a number The sieve of Eratosthenes is an algorithm that provides such an effective procedure The sieve of Eratosthenes is an algorithm that provides such an effective procedure

Euclid ’ s Algorithm Idea: Idea: if n  0, gcd(m, n) = gcd(n, m mod n); if n  0, gcd(m, n) = gcd(n, m mod n); if n = 0, gcd(m, n) = m. if n = 0, gcd(m, n) = m. Euclid ’ s algorithm for computing gcd(m, n) Euclid ’ s algorithm for computing gcd(m, n) Step1 If n=0, return the value of m as the answer and stop; otherwise proceed to Step2. Step1 If n=0, return the value of m as the answer and stop; otherwise proceed to Step2. Step2 Divide m by n and assign the value of the remainder to r. Step2 Divide m by n and assign the value of the remainder to r. Step3 Assign the value of n to m and the value of r to n. Go to Step1. Step3 Assign the value of n to m and the value of r to n. Go to Step1.

Exercise Page8 Problem5 Page8 Problem5 a. Find gcd(31415, 14142) by applying Euclid’s algorithm. a. Find gcd(31415, 14142) by applying Euclid’s algorithm. b. Estimate how many times faster it will be to find gcd(31415, 14142) by Euclid’s algorithm compared with the algorithm based on checking consecutive integers from min(m, n) down to gcd(m, n). b. Estimate how many times faster it will be to find gcd(31415, 14142) by Euclid’s algorithm compared with the algorithm based on checking consecutive integers from min(m, n) down to gcd(m, n).

Analysis of Algorithms How good is the algorithm? How good is the algorithm? Correctness Correctness Time efficiency Time efficiency Space efficiency Space efficiency Does there exist a better algorithm? Does there exist a better algorithm? Lower bounds Lower bounds Optimality Optimality

What is an algorithm? Recipe, process, method, technique, procedure, routine, … with following requirements: Recipe, process, method, technique, procedure, routine, … with following requirements: 1. Finiteness b terminates after a finite number of steps 2. Definiteness b rigorously and unambiguously specified 3. Input b valid inputs are clearly specified 4. Output b can be proved to produce the correct output given a valid input 5. Effectiveness b steps are sufficiently simple and basic

Algorithm Design and Analysis Process Understand the problem Decide on : algorithm design techniques etc. Design an algorithm

Algorithm Design and Analysis Process Understand the problem Decide on : algorithm design techniques etc. Design an algorithm Prove correctness Analyze efficiency etc. Decide on : algorithm design techniques etc.

Algorithm Design and Analysis Process Understand the problem Decide on : algorithm design techniques etc. Design an algorithm Prove correctness Analyze efficiency etc Code the algorithm Decide on : algorithm design techniques etc. correctness efficiency

Correctness Termination Termination Well-founded sets: find a quantity that is never negative and that always decreases as the algorithm is executed Well-founded sets: find a quantity that is never negative and that always decreases as the algorithm is executed

Prove the Correctness for Euclid ’ s Algorithm Idea: Idea: if n  0, gcd(m, n) = gcd(n, m mod n); if n  0, gcd(m, n) = gcd(n, m mod n); if n = 0, gcd(m, n) = m. if n = 0, gcd(m, n) = m. Euclid ’ s algorithm for computing gcd(m, n) Euclid ’ s algorithm for computing gcd(m, n) Step1 If n=0, return the value of m as the answer and stop; otherwise proceed to Step2. Step1 If n=0, return the value of m as the answer and stop; otherwise proceed to Step2. Step2 Divide m by n and assign the value of the remainder to r. Step2 Divide m by n and assign the value of the remainder to r. Step3 Assign the value of n to m and the value of r to n. Go to Step1. Step3 Assign the value of n to m and the value of r to n. Go to Step1.

Complexity Space complexity Space complexity Time complexity Time complexity For iterative algorithms: sums For iterative algorithms: sums For recursive algorithms: recurrence relations For recursive algorithms: recurrence relations