CS 415 Algorithm Analysis Instructor: B. (Ravi) Ravikumar

Slides:



Advertisements
Similar presentations
College of Information Technology & Design
Advertisements

MATH 224 – Discrete Mathematics
Section 4.1: Primes, Factorization, and the Euclidean Algorithm Practice HW (not to hand in) From Barr Text p. 160 # 6, 7, 8, 11, 12, 13.
Notation Intro. Number Theory Online Cryptography Course Dan Boneh
CS150 Introduction to Computer Science 1 Professor: Chadd Williams.
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2002 Tuesday, 26 November Number-Theoretic Algorithms Chapter 31.
CSE 830: Design and Theory of Algorithms
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Design and Analysis of Algorithms - Chapter 11 Algorithm An algorithm is a.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 5 Instructor: Paul Beame TA: Gidon Shavit.
TK3043 Analysis and Design of Algorithms Introduction to Algorithms.
Strategies for Math Success Russell Conwell Learning Center Online Workshop.
Section 1.3 Prime numbers and fractions
Polynomial Factorization Olga Sergeeva Ferien-Akademie 2004, September 19 – October 1.
Algorithms. Problems, Algorithms, Programs Problem - a well defined task. –Sort a list of numbers. –Find a particular item in a list. –Find a winning.
Introduction Dr. Ying Lu RAIK 283: Data Structures & Algorithms.
1 L07SoftwareDevelopmentMethod.pptCMSC 104, Version 8/06 Software Development Method Topics l Software Development Life Cycle Reading l Section 1.4 – 1.5.
Piyush Kumar (Lecture 1: Introduction)
Teaching Teaching Discrete Mathematics and Algorithms & Data Structures Online G.MirkowskaPJIIT.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
MATH 224 – Discrete Mathematics
CS223 Algorithms D-Term 2013 Instructor: Mohamed Eltabakh WPI, CS Introduction Slide 1.
1 Chapter 24 Developing Efficient Algorithms. 2 Executing Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
CS Fall 2007 Dr. Barbara Boucher Owens. CS 2 Text –Main, Michael. Data Structures & Other Objects in Java Third Edition Objectives –Master building.
Chapter 3 Sec 3.3 With Question/Answer Animations 1.
Data Structures Chapter 1- Introduction Mohamed Mustaq.A.
CS 140 Computer Programming (I) Second semester (3 credits) Imam Mohammad bin Saud Islamic University College of Computer Science and Information.
1 Analysis of Algorithms CS 105 Introduction to Data Structures and Algorithms.
Major objective of this course is: Design and analysis of modern algorithms Different variants Accuracy Efficiency Comparing efficiencies Motivation thinking.
CSE 2320 Algorithms and Data Structures Dimitrios Kosmopoulos Introduction.
CSC 211 Data Structures Lecture 13
CS Data Structures I Chapter 2 Principles of Programming & Software Engineering.
Chapter Algorithms 3.2 The Growth of Functions 3.3 Complexity of Algorithms 3.4 The Integers and Division 3.5 Primes and Greatest Common Divisors.
Algorithms and their Applications CS2004 ( ) Professor Jasna Kuljis (adapted from Dr Steve Swift) 6.1 Classic Algorithms - Sorting.
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:
CS 206 Introduction to Computer Science II 09 / 18 / 2009 Instructor: Michael Eckmann.
CS404 Design and Analysis of Algorithms BBy DDr. M V S Peri Sastry BB.E, PhD(BITS-Pilani)
CS 206 Introduction to Computer Science II 01 / 30 / 2009 Instructor: Michael Eckmann.
Computer Science/Ch. Algorithmic Foundation of CS 4-1 Chapter 4 Chapter 4 Algorithmic Foundation of Computer Science.
Introduction to design and analysis algorithm
1 Ch. 2: Getting Started. 2 About this lecture Study a few simple algorithms for sorting – Insertion Sort – Selection Sort (Exercise) – Merge Sort Show.
CES 592 Theory of Software Systems B. Ravikumar (Ravi) Office: 124 Darwin Hall.
Lecture # 1 Introduction Analysis of Algorithm by Qamar Abbas Analysis of Algorithms.
Review I. Final exam Date TBD. Don ’ t be late! Open book, open notes No calculators or any electronics Worth 50% of final grade.
Big O David Kauchak cs302 Spring Administrative Assignment 1: how’d it go? Assignment 2: out soon… Lab code.
Lecture #1: Introduction to Algorithms and Problem Solving Dr. Hmood Al-Dossari King Saud University Department of Computer Science 6 February 2012.
Discrete Mathematics Chapter 2 The Fundamentals : Algorithms, the Integers, and Matrices. 大葉大學 資訊工程系 黃鈴玲.
Algorithms.
Introduction to Algorithms
CS 415 Algorithm Analysis Lecture T Th 2 – 3:50 PM, Salazar Hall 2023
Problem Solving & Computer Programming
Algorithms, Part 1 of 3 The First step in the programming process
TK3043 Analysis and Design of Algorithms
Chapter 1 Introduction Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Introduction to the Design and Analysis of Algorithms
Piyush Kumar (Lecture 1: Introduction)
Piyush Kumar (Lecture 1: Introduction)
Algorithms I: An Introduction to Algorithms
Number Theory (Chapter 7)
CS 583 Fall 2006 Analysis of Algorithms
Greedy Algorithms / Interval Scheduling Yin Tat Lee
Recursion "To understand recursion, one must first understand recursion." -Stephen Hawking.
Objective of This Course
Introduction to Algorithms
Lecture 6 Architecture Algorithm Defin ition. Algorithm 1stDefinition: Sequence of steps that can be taken to solve a problem 2ndDefinition: The step.
Piyush Kumar (Lecture 1: Introduction)
Piyush Kumar (Lecture 1: Introduction)
Design and Analysis of Algorithms
Chapter 1 Introduction Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Presentation transcript:

E-mail: cs415spring11@gmail.com CS 415 Algorithm Analysis Instructor: B. (Ravi) Ravikumar Office: 116 I Darwin Hall Phone: 664 3335 E-mail: cs415spring11@gmail.com Course Web site: http://ravi.cs.sonoma.edu/cs415sp11 1

Text book: Published in 2006. Other references: Cormen et al. Introduction to Algorithms Das Gupta, Papadimitriou and Vazirani, Algorithms (free online version) Numerous other sources Please report any errors to Kevin Wayne (wayne@cs.princeton.edu). Thanks!

Course policies, grading etc. Short quizzes and class participation – 5 to 10 points (There will be about 8 quizzes, each roughly 10 minutes long. The quizzes will not require difficult problem solving, but will require a basic understanding of the topic being covered.) Home work assignments - 15 points. Most home work problems will be from the text. They are intended to deepen your understanding of the material presented in class and will play a key role in prepare you for the mid-term and final exams. You can discuss the home work problems with others, but you should write up the solution on your own.  Two mid-semester tests  - 30 points (The mid-semester tests will be open-book/notes, and will be in class.) Project - 15 points. This will be an implementation project. Details will be discussed in class. Final Examination - 25 points. This will be comprehensive and will take place at the pre-specified time slot. You can find the date from the university’s calendar. Maintenance of course folder – 5 points.

Review of CS 242 and CS 315 handout contains questions/problems on CS 242 and CS 315.

What is an algorithm? In fact our field computer science is often described as a study of algorithms. At least, algorithm is the viewed as equivalent to “software”. We all have a good intuitive understanding of what an algorithm is. But what is the precise definition? Algorithms are much older than computers. How old are they? They are the ideas behind software and so don’t need a hardware to run them. (Or, can be run by “human computers”.)

Rhind Mathematical Papyrus An old algorithm – more than 3500 years old Rhind Mathematical Papyrus British Museum, London One of the algorithms presented is for multiplying two numbers: 59 41 _________________ 1 41 x 2 82 x 4 164 8 328 x 16 656 x 32 1312 x _________________ 2419

An algorithm from Al-Khwarizmi’s book (about 1200 years old)

Historically famous algorithms Classical (~ 2000 years) Finding area of triangles and other shapes (Heron’s formula) Finding GCD of integers (Euclid’s algorithm) Solving linear system of equations, quadratic equation etc. Intermediate (~ 500 years old) logarithm tables Roots of polynomials, solution of differential equations etc. Applications? Dividing land (after floods) Calculating trajectories of planets architecture (buildings, dams etc.) navigation (finding direction in deep sea) town planning, governance (tax rate etc.)

Famous modern algorithms (20th century algorithms) quick-sort Dijkstra’s algorithm RSA (for encryption) Fast Fourier Transform Simplex algorithm Huffman coding algorithm, LZW algorithm (both for compression) Hamming code (corrects errors) page-rank algorithm (of Brin and Page) There are probably many other candidates.

Euclid’s algorithm for GCD computation Euclid’s algorithm for finding the GCD of two positive integers. What is the definition of GCD? Algorithm GCD input: x, y – positive integers output: m – GCD of x and y

Euclid’s algorithm for GCD computation To define GCD, we first need the definition of divisor, then common divisor and finally greatest common divisor. p is a divisor of q if p is a multiple of q, or the remainder when q is divided by p is 0. (We write p | q) Example: 4 | 12, 5 | 30, but 12 | 30. p is a common divisor of x and y if p | x and p | y. p is the GCD of x and y if p is the largest among the common divisors of x and y.

Euclid’s algorithm for GCD computation Algorithm GCD input: x, y – positive integers output: m – GCD of x and y Step 1: if y > x, swap x and y. Step 2: if y = 0, set m = x and stop. Step 3: r = remainder when x divided by y x = y y = r Step 4: go to step 2 Exercise: compute the GCD of 948 and 156.

Correctness of the algorithm Does the algorithm stop on all inputs? (i.e., can we show that there is no infinite loop?) if the algorithm has no loops, this is not a problem. But most algorithms do. (Euclid’s does!) Does it output the correct result for all inputs? Work out some small test cases and see if we get the correct result. Even this is tricky. We need to know a different way (than using the present algorithm) to get the answer so that we can cross-check. But proving correctness requires mathematical argument, not just some test cases.

Another algorithm for GCD Find the prime factorization of both numbers. i.e., keep factoring the number until it is written as a product of primes. If a prime appears in both lists, choose it and remove it from both lists and repeat the process until there are no common elements. The product of all the chosen numbers is the GCD. Question: How old is this algorithm? Example: 948 and 156 948 = 2 x 2 x 3 x 79 156 = 2 x 2 x 3 x 13 Common prime factors 2, 2 and 3. GCD = 2 x 2 x 3 = 12

Proving the correctness of Euclid’s algorithm Two steps involved in proving that an algorithm is correct. Show that Euclid’s algorithm always terminates. Will be done in class. Show that Euclid’s algorithm always produces the correct output.

Complexity of the algorithm Time complexity is one of the central issues that we will be discussing. For every algorithm, we want to measure its time complexity. Rough definition of time complexity: The number of operations performed by the algorithm. What operations? we could count every operation, e.g. assignment, comparison, addition etc. but what is an operation? E.g. % or / may require many CPU cycles, or machine instructions. one approach is to fix an instruction set, and architecture and count the number of machine instructions. another approach is to focus on the most expensive operation – e.g. in the case of GCD problem, division is the most expensive operation.

Complexity depends on the size of the input Measured as a function of N, the input size. For the GCD problem, the input is the total number of bits in the inputs. Example: for the input (23, 132), the input size is 5 + 8 since we need 5 bits to represent 23, and 8 bits to represent 132.

Complexity of the algorithm Many ways to measure complexity: best-case: of all the inputs of size N, the input that makes the algorithm perform the fewest number of divisions. What is the best case for Euclid’s algorithm? worst-case: The one of size N for which the algorithm performs the maximum number of operations. average-case: add up the complexity for all inputs of size N, and divide it by the number of such inputs. The most common one used in this course is the worst-case complexity.

Algorithm design techniques At least two approaches: problem-oriented shortest-path sorting linear programming etc. technique-oriented greedy method dynamic programming divide and conquer transformation etc.

Reduction – mapping one problem to another Effectiveness of problem-oriented method is if you know how to solve problem A, then you know how to solve problem B. most problems can be solved by breaking into sub problems each of which is one of the standard problems for which well-crafted solution exists. a powerful way to reduce one problem to another is “problem transformation”.

Transformation consider a two player game in which players alternately choose a number between 1 and 9. (Each number can be chosen at most once.) At any stage, if a player has three numbers that add to 15, he/she has won. What will be your strategy?

Transformation – Another example Weighted Interval Scheduling Input. Set of jobs with start times, finish times, and weights. Goal. Find maximum weight subset of mutually compatible jobs. 23 12 20 26 13 20 11 16 Time 1 2 3 4 5 6 7 8 9 10 11