CSC 282 – Algorithms Daniel Stefankovic – CSB 620 TA: Girts Folkmanis – CSB 614

Slides:



Advertisements
Similar presentations
Introduction to Algorithms 6.046J Lecture 1 Prof. Shafi Goldwasser Prof. Erik Demaine.
Advertisements

UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Midterm Review Fri. Oct 26.
CSC401 – Analysis of Algorithms Lecture Notes 1 Introduction
Administrative Sep. 20 (today) – HW1 due Sep. 21 8am – problem session Sep. 25 – HW3 (=QUIZ #1) due Sep. 27 – HW4 due Sep. 28 8am – problem session Oct.
CSC 282 – Algorithms Daniel Stefankovic – CSB 620 TA: Girts Folkmanis – CSB 614
CS421 - Course Information Website Syllabus Schedule The Book:
Text Chapters 1, 2. Sorting ä Sorting Problem: ä Input: A sequence of n numbers ä Output: A permutation (reordering) of the input sequence such that:
CSE 830: Design and Theory of Algorithms
Lecture 3 Aug 31, 2011 Goals: Chapter 2 (algorithm analysis) Examples: Selection sorting rules for algorithm analysis discussion of lab – permutation generation.
2 -1 Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
CS Main Questions Given that the computer is the Great Symbol Manipulator, there are three main questions in the field of computer science: What kinds.
The Complexity of Algorithms and the Lower Bounds of Problems
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Instructor: Paul Beame TA: Gidon Shavit.
Text Chapters 1, 2. Sorting ä Sorting Problem: ä Input: A sequence of n numbers ä Output: A permutation (reordering) of the input sequence such that:
CSE 5311 DESIGN AND ANALYSIS OF ALGORITHMS. Definitions of Algorithm A mathematical relation between an observed quantity and a variable used in a step-by-step.
Lecture 2 MAS 714 Hartmut Klauck
Algorithm analysis and design Introduction to Algorithms week1
Instructor Neelima Gupta
Asymptotic Growth Rates Themes –Analyzing the cost of programs –Ignoring constants and Big-Oh –Recurrence Relations & Sums –Divide and Conquer Examples.
2 -1 Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
1 Computer Algorithms Lecture 3 Asymptotic Notation Some of these slides are courtesy of D. Plaisted, UNC and M. Nicolescu, UNR.
DISCRETE MATHEMATICS I CHAPTER 11 Dr. Adam Anthony Spring 2011 Some material adapted from lecture notes provided by Dr. Chungsim Han and Dr. Sam Lomonaco.
Algorithm Analysis An algorithm is a clearly specified set of simple instructions to be followed to solve a problem. Three questions for algorithm analysis.
10/13/20151 CS 3343: Analysis of Algorithms Lecture 9: Review for midterm 1 Analysis of quick sort.
Lecture 2 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
CS 221 Analysis of Algorithms Instructor: Don McLaughlin.
1 COMP3040 Tutorial 1 Analysis of algorithms. 2 Outline Motivation Analysis of algorithms Examples Practice questions.
Analysis of Algorithms These slides are a modified version of the slides used by Prof. Eltabakh in his offering of CS2223 in D term 2013.
Analyzing algorithms & Asymptotic Notation BIO/CS 471 – Algorithms for Bioinformatics.
CMPT 438 Algorithms. Why Study Algorithms? Necessary in any computer programming problem ▫Improve algorithm efficiency: run faster, process more data,
CMPT 438 Algorithms Chapter 3 Asymptotic Notations.
Divide & Conquer  Themes  Reasoning about code (correctness and cost)  recursion, induction, and recurrence relations  Divide and Conquer  Examples.
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =
September 17, 2001 Algorithms and Data Structures Lecture II Simonas Šaltenis Nykredit Center for Database Research Aalborg University
September 9, Algorithms and Data Structures Lecture II Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part 1. Complexity Bounds.
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
Asymptotics and Recurrence Equations Prepared by John Reif, Ph.D. Analysis of Algorithms.
ADVANCED ALGORITHMS REVIEW OF ANALYSIS TECHNIQUES (UNIT-1)
Introduction to Algorithms (2 nd edition) by Cormen, Leiserson, Rivest & Stein Chapter 2: Getting Started.
Text Chapters 2 Analyzing Algorithms.  goal: predicting resources that an algorithm requires memory, communication bandwidth, hardware, memory, communication.
1 Ch. 2: Getting Started. 2 About this lecture Study a few simple algorithms for sorting – Insertion Sort – Selection Sort (Exercise) – Merge Sort Show.
2IL50 Data Structures Spring 2016 Lecture 2: Analysis of Algorithms.
R. Johnsonbaugh, Discrete Mathematics 5 th edition, 2001 Chapter 3 Algorithms.
Computability Sort homework. Formal definitions of time complexity. Big 0. Homework: Exercises. Searching. Shuffling.
September 10, 2001 Algorithms and Data Structures Simonas Šaltenis Nykredit Center for Database Research Aalborg University
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
Complexity of Algorithms Fundamental Data Structures and Algorithms Ananda Guna January 13, 2005.
September 18, Algorithms and Data Structures Lecture II Simonas Šaltenis Aalborg University
CMPT 438 Algorithms.
CS 3343: Analysis of Algorithms
DATA STRUCTURES Introduction: Basic Concepts and Notations
CS 213: Data Structures and Algorithms
CS 3343: Analysis of Algorithms
Asymptotic Notations Algorithms Lecture 9.
Foundations II: Data Structures and Algorithms
CSCI 2670 Introduction to Theory of Computing
CS200: Algorithms Analysis
The Lower Bounds of Problems
CSE 2010: Algorithms and Data Structures
Divide and Conquer Algorithms Part I
Time Complexity Lecture 14 Sec 10.4 Thu, Feb 22, 2007.
Ch. 2: Getting Started.
Introduction To Algorithms
David Kauchak cs161 Summer 2009
Divide and Conquer Merge sort and quick sort Binary search
September 10, 2001 Algorithms and Data Structures Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Algorithms and Data Structures Lecture II
Algorithms and Data Structures
Presentation transcript:

CSC 282 – Algorithms Daniel Stefankovic – CSB 620 TA: Girts Folkmanis – CSB 614

Grading formula 25% - homework 30% - quizzes 25% - midterm (Tu, Oct. 24) 30% - final (Th, Dec. 21)

25% - homework turn in before class on the due date no late homework accepted two lowest homework scores dropped 30% - quizzes 1 each week 10 min closed book no make-up quizzes two lowest quiz grades dropped

What is an algorithm? algorithm = problem-solving procedure Algoritmi de numero Indorum (Al-Khwarizmi Concerning the Hindu Art of Reckoning) CORRECTNESS EFFICIENCY

Problem: is n a prime? P RIMALITY : INSTANCE: a natural number n QUESTION: is n a prime? Is a prime?

Problem: is n a prime? Is a prime? Algorithm 1: 1 for k from 2 to n-1 do 2 if k divides n then RETURN “composite” 3 RETURN “prime”

Problem: is n a prime? Algorithm 1: 1 for k from 2 to n-1 do 2 if k divides n then RETURN “composite” 3 RETURN “prime” Algorithm 2: 1 for k from 2 to √ n do 2 if k divides n then RETURN “composite” 3 RETURN “prime”

Problem: is n a prime? CORRECT? Algorithm 2: 1 for k from 2 to √ n do 2 if k divides n then RETURN “composite” 3 RETURN “prime”

Problem: is n a prime? RSA cryptosystem needs primes with bits. Running time of our algorithms: Algorithm 1: – Algorithm 2:

Problem: is n a prime? RSA cryptosystem needs primes with bits. Running time of our algorithms: Algorithm 1: – Algorithm 2: – NOT EFFICIENT

What means efficient? running time is bounded by a polynomial in the input size “efficient program using other efficient as subroutines is efficient”

Input size How many bits needed to represent n?

Input size How many bits needed to represent n? √n  polynomial(log n) ??? Algorithm 2: 1 for k from 2 to √ n do 2 if k divides n then RETURN “composite” 3 RETURN “prime” log n

What means efficient? running time is bounded by a polynomial in the input size More refined classification asymptotic notation

Asymptotic notation DEF: Let f,g: N  R +. We say f(n) = O(g(n)) if (  C) (  n) f(n)  C. g(n)

Asymptotic notation DEF: Let f,g: N  R +. We say f(n) = O(g(n)) if (  C) (  n) f(n)  C. g(n) 1 n 2 + n 3 = O(n 4 ) 2 n 2 / log(n) = O(n. log n) 3 5n + log(n) = O(n) 4 n log n = O(n 100 ) 5 3 n = O(2 n. n 100 )

Asymptotic notation 1 n 2 + n 3 = O(n 4 ) 2 n 2 / log(n)  O(n. log n) 3 5n + log(n) = O(n) 4 n log n  O(n 100 ) 5 3 n  O(2 n. n 100 )

Asymptotic notation 1 n! = O(3 n ) 2 n +1 = O(n) 3 2 n+1 = O(2 n ) 4 (n+1)! = O(n!) 5 1+c+c 2 +…+c n = O(c n ) 6 1+c+c 2 +…+c n = O(1) n!= n.(n-1).(n-2) … 3.2.1

Asymptotic notation 1 n!  O(3 n ) 2 n+1 = O(n) 3 2 n+1 = O(2 n ) 4 (n+1)!  O(n!) 5 1+c+c 2 +…+c n = O(c n ) for c>1 6 1+c+c 2 +…+c n = O(1) for c<1

Asymptotic notation DEF: Let f,g: N  R +. We say f(n) =  (g(n)) if f(n)=O(g(n)) and g(n)=O(f(n))

What means efficient? polynomial-time = running time is bounded by a polynomial in the input size, i.e., (  k) T(n) = O(n k ) More refined analysis = asymptotics for the running time (as a function of input-size) ideally we would like f(n) such that T(n) =  (f(n))

An applied problem INSTANCE: n points in the plane SOLUTION: a tour connecting the points MEASURE: the length of the tour

An applied problem INSTANCE: n points in the plane SOLUTION: a tour connecting the points MEASURE: the length of the tour

An applied problem INSTANCE: n points in the plane SOLUTION: a tour connecting the points MEASURE: the length of the tour

An efficient algorithm?

A correct algorithm best  (1 2 3 … n) for each permutation   if cost(  )<cost(best) then  best  EFFICIENCY?

Sorting S ORTING : INSTANCE: a sequence of n numbers a 1,a 2, …, a n SOLUTION: reordering b i of the input such that b 1  b 2  …  b n

Insertion sort i  1 while i  n do j  i while j  2 and a[ j-1] > a[ j ] do swap a[ j ],a[ j-1] j  j - 1 i  i + 1

Insertion sort – correctness? i  1 while i  n do j  i while j  2 and a[ j-1] > a[ j ] do swap a[ j ],a[ j-1] j  j - 1 i  i + 1

Insertion sort – running time?

The worst-case running time of insertion sort is  (n 2 ).

Merge 2 sorted lists M ERGE INSTANCE: 2 lists x i, y i such that x 1  x 2  …  x n y 1  y 2  …  y m SOLUTION: ordered merge

1 i  1, j  1 2 while i  n and j  n do 3 if x i  y j then 4 output x i, i  i else 6 output y j, j  j output remaining elements Merge 2 sorted lists

M ERGE -S ORT (a,l,r) if l < r then m   (l+r)/2  M ERGE -S ORT (a,I,m) M ERGE -S ORT (a,m+1,r) M ERGE (a,l,m,r) Mergesort

Running time? Mergesort

Running time? Mergesort [ … n/2 … ] [... n … ] [ … n/4 … ] Depth ?

Running time? Mergesort [ … n/2 … ] [... n … ] [ … n/4 … ] Depth = log n

Time spent on merge? Mergesort [ … n/2 … ] [... n … ] [ … n/4 … ] Depth = log n

Time spent on merge? Mergesort [ … n/2 … ] [... n … ] [ … n/4 … ] Depth = log n O(n) O(n.logn)

recurrence T(n)= T(n/2) +  (n) if n>1 T(1)=  (1) Mergesort

RAM model Program r0r0 r1r1 r2r2 r3r3 r4r4 r5r5 memory... Each register holds an integer Operations: simple arithmetic if-then, goto, etc.