3101 3.0A Lecture 1 - 1 10/24/2015 COSC3101A: Design and Analysis of Algorithms Tianying Ji Lecture 1.

Slides:



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

Analysis of Algorithms
5/1/20151 Analysis of Algorithms Introduction. 5/1/20152 Are you want to be a computer scientist?
Razdan with contribution from others 1 Algorithm Analysis What is the Big ‘O Bout? Anshuman Razdan Div of Computing.
Chapter 2. Getting Started. Outline Familiarize you with the to think about the design and analysis of algorithms Familiarize you with the framework to.
What is an Algorithm? (And how do we analyze one?)
CS421 - Course Information Website Syllabus Schedule The Book:
Analysis of Algorithms1 Estimate the running time Estimate the memory space required. Time and space depend on the input size.
Analysis of Algorithms
1 Data Structures A program solves a problem. A program solves a problem. A solution consists of: A solution consists of:  a way to organize the data.
CSE 830: Design and Theory of Algorithms Dr. Eric Torng.
CS3381 Des & Anal of Alg ( SemA) City Univ of HK / Dept of CS / Helena Wong 2. Analysis of Algorithms - 1 Analysis.
25 June 2015Comp 122, Spring 2004 Asymptotic Notation, Review of Functions & Summations.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 2 Elements of complexity analysis Performance and efficiency Motivation: analysis.
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.
Algorithms. Introduction The methods of algorithm design form one of the core practical technologies of computer science. The main aim of this lecture.
Introduction to Algorithm design and analysis
David Luebke 1 8/17/2015 CS 332: Algorithms Asymptotic Performance.
Instructor Neelima Gupta
Analysis of Algorithms Algorithm Input Output © 2014 Goodrich, Tamassia, Goldwasser1Analysis of Algorithms Presentation for use with the textbook Data.
Analysis and Design of Algorithms. According to math historians the true origin of the word algorism: comes from a famous Persian author named ál-Khâwrázmî.
Introduction to Algorithms Jiafen Liu Sept
Lecture 2 Computational Complexity
Algorithm Efficiency CS 110: Data Structures and Algorithms First Semester,
Analysis of Algorithms
Mathematics Review and Asymptotic Notation
1 Computer Algorithms Lecture 3 Asymptotic Notation Some of these slides are courtesy of D. Plaisted, UNC and M. Nicolescu, UNR.
CS 3343: Analysis of Algorithms
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.
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 1 Prof. Charles E. Leiserson.
Algorithms Lecture 1. Introduction The methods of algorithm design form one of the core practical technologies of computer science. The main aim of this.
Introduction to Algorithms Lecture 1. Introduction The methods of algorithm design form one of the core practical technologies of computer science. The.
Analysis of Algorithm Efficiency Dr. Yingwu Zhu p5-11, p16-29, p43-53, p93-96.
CS 221 Analysis of Algorithms Instructor: Don McLaughlin.
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,
Asymptotic Analysis-Ch. 3
DR. Gatot F. Hertono, MSc. Design and Analysis of ALGORITHM (Session 2)
Tonga Institute of Higher Education Design and Analysis of Algorithms IT 254 Lecture 2: Mathematical Foundations.
1Computer Sciences Department. Book: Introduction to Algorithms, by: Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest Clifford Stein Electronic:
MS 101: Algorithms Instructor Neelima Gupta
Algorithm Analysis CS 400/600 – Data Structures. Algorithm Analysis2 Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely.
David Luebke 1 11/29/2015 CS 332: Algorithms Introduction Proof By Induction Asymptotic notation.
COSC 3101A - Design and Analysis of Algorithms 2 Asymptotic Notations Continued Proof of Correctness: Loop Invariant Designing Algorithms: Divide and Conquer.
Algorithm Analysis Part of slides are borrowed from UST.
David Luebke 1 1/6/2016 CS 332: Algorithms Asymptotic Performance.
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
Asymptotic Performance. Review: Asymptotic Performance Asymptotic performance: How does algorithm behave as the problem size gets very large? Running.
Analysis of Algorithms Asymptotic Performance. Review: Asymptotic Performance Asymptotic performance: How does algorithm behave as the problem size gets.
ADVANCED ALGORITHMS REVIEW OF ANALYSIS TECHNIQUES (UNIT-1)
Introduction to Algorithms (2 nd edition) by Cormen, Leiserson, Rivest & Stein Chapter 2: Getting Started.
CES 592 Theory of Software Systems B. Ravikumar (Ravi) Office: 124 Darwin Hall.
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 1 Prof. Charles E. Leiserson.
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.
CIS 313: Analysis and Design of Algorithms Assoc. Prof Hassan Aly Department of Computer Science and Information College of Science at AzZulfi Al-Majmaah.
CMPT 438 Algorithms.
Design and Analysis of Algorithms
Introduction to Algorithms
CS 583 Fall 2006 Analysis of Algorithms
CS 3343: Analysis of Algorithms
CS 3343: Analysis of Algorithms
Foundations II: Data Structures and Algorithms
CSC 413/513: Intro to Algorithms
Introduction to Algorithms Analysis
Discrete Mathematics 7th edition, 2009
Introduction To Algorithms
Presentation transcript:

A Lecture /24/2015 COSC3101A: Design and Analysis of Algorithms Tianying Ji Lecture 1

A Lecture /24/2015 Part 1 The course  General information Introduction to algorithms Algorithm analysis basics Asymptotic notation

A Lecture /24/2015 The Course Purpose: The theoretical study of design and analysis of algorithms  Not a programming course  Not a math course, either Textbook: Introduction to Algorithms, Cormen, Leiserson, Rivest, Stein  Second edition  An excellent reference you should own

A Lecture /24/2015 The Course Instructor: Tianying Ji   Office: CSEB 2022  Office hours: 5:30pm-7:00pm, Tuesday  TA: TBA  TA Office hours and location TBA

A Lecture /24/2015 The Course Grading policy (Probably, TBD):  Assignments: 20%  Mid-term Exam: 30%  Final Exam: 50%

A Lecture /24/2015 The Course Format  One lecture/week  About four Assignments oProblem sets oMaybe occasional programming assignments  Mid-term + final exam

A Lecture /24/2015 The Course Course overview  Mathematical background (asymptotic notation, recurrence relations, bounding sums, induction, etc.) [Ch 1, 2.2, 3, 4]  Proofs of correctness, including loop invariants [Ch 2.1]  Recursive algorithms; divide and conquer technique [Ch 2.3, 4]  Sorting algorithms and lower bounds [Ch 6,7,8]  Selection [Ch 9]  Greedy algorithms [Ch 16]  Dynamic programming [Ch 15]  Graph algorithms (searching, spanning trees, shortest path, etc.) [Ch 22,23,24,25,26]  (If time permits) A brief introduction to NP-completeness. [Ch 34]

A Lecture /24/2015 Part 1 Questions?

A Lecture /24/2015 Part 2 The course ☻ Introduction to algorithms [Ch 1]  What are Algorithms?  Analysis vs. Design  RAM Algorithm analysis basics Asymptotic notation

A Lecture /24/2015 What are algorithms? Webster definition: a procedure for solving a mathematical problem (as of finding the greatest common divisor) in a finite number of steps that frequently involves repetition of an operation; broadly : a step-by-step procedure for solving a problem or accomplishing some end especially by a computer

A Lecture /24/2015 Basics of Algorithms Well-defined computational procedure Takes input values Produces output values Results are always correct for any input event Always terminates

A Lecture /24/2015 Musical analogy ComputingMusical SoftwareMusic HardwareMusical instruments AlgorithmsChord progressions Source codeMusical notation ProgrammingComposing

A Lecture /24/2015 Basic goals for an algorithm Always correct Always terminates This class: performance  Performance often draws the line between what is possible and what is impossible.

A Lecture /24/2015 Analysis vs. Design Analysis: predict the cost of an algorithm in terms of resources and performance Design: design algorithms which minimize the cost

A Lecture /24/2015 Machine model: Generic Random Access Machine (RAM) Executes operations sequentially Set of primitive operations:  Arithmetic. Logical, Comparisons, Function calls Simplifying assumption: all ops cost 1 unit  Eliminates dependence on the speed of our computer, otherwise impossible to verify and to compare

A Lecture /24/2015 Part 2 Questions?

A Lecture /24/2015 Part 3 The course ☻ Introduction to algorithms ☻ Algorithm analysis basics [Ch 2.1, 2.2]  Sorting  Insertion sort Asymptotic notation

A Lecture /24/2015 The problem of sorting Input: sequence  a 1, a 2, …, a n  of numbers. Output: permutation  a' 1, a' 2, …, a' n  such that a' 1  a' 2  …  a' n. Example: Input: Output:

A Lecture /24/2015 Insertion sort I NSERTION -S ORT (A, n) ⊳ A[1.. n] for i ← 2 to n dokey ← A[i] j ← i – 1 while j > 0 and A[j] > key doA[j+1] ← A[j] j ← j – 1 A[j+1] ← key “pseudocode” ji key sorted A:A: 1n

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i =  j =  key =  A[j] =  A[j+1] = 

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 2j = 1key = 10 A[j] = 30 A[j+1] = 10

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 2j = 1key = 10 A[j] = 30 A[j+1] = 30

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 2j = 1key = 10 A[j] = 30 A[j+1] = 30

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 2j = 0key = 10 A[j] =  A[j+1] = 30

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 2j = 0key = 10 A[j] =  A[j+1] = 10

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 3j = 0key = 10 A[j] =  A[j+1] = 10

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 3j = 0key = 40 A[j] =  A[j+1] = 10

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 3j = 0key = 40 A[j] =  A[j+1] = 10

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 3j = 2key = 40 A[j] = 30 A[j+1] = 40

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 3j = 2key = 40 A[j] = 30 A[j+1] = 40

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 3j = 2key = 40 A[j] = 30 A[j+1] = 40

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 4j = 2key = 40 A[j] = 30 A[j+1] = 40

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 4j = 2key = 20 A[j] = 30 A[j+1] = 40

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 4j = 2key = 20 A[j] = 30 A[j+1] = 40

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 4j = 3key = 20 A[j] = 40 A[j+1] = 20

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 4j = 3key = 20 A[j] = 40 A[j+1] = 20

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 4j = 3key = 20 A[j] = 40 A[j+1] = 40

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 4j = 3key = 20 A[j] = 40 A[j+1] = 40

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 4j = 3key = 20 A[j] = 40 A[j+1] = 40

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 4j = 2key = 20 A[j] = 30 A[j+1] = 40

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 4j = 2key = 20 A[j] = 30 A[j+1] = 40

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 4j = 2key = 20 A[j] = 30 A[j+1] = 30

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 4j = 2key = 20 A[j] = 30 A[j+1] = 30

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 4j = 1key = 20 A[j] = 10 A[j+1] = 30

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 4j = 1key = 20 A[j] = 10 A[j+1] = 30

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 4j = 1key = 20 A[j] = 10 A[j+1] = 20

A Lecture /24/2015 An Example: Insertion Sort InsertionSort(A, n) for i ← 2 to n do key ← A[i] j ← i - 1 while j > 0 and A[j] > key do A[j+1] ← A[j] j ← j - 1 A[j+1] ← key i = 4j = 1key = 20 A[j] = 10 A[j+1] = 20 Done!

A Lecture /24/2015 Example of insertion sort done

A Lecture /24/2015 Kinds of analyses Worst-case: (usually) T(n) = maximum time of algorithm on any input of size n. Average-case: (sometimes) T(n) = expected time of algorithm over all inputs of size n. Need assumption of statistical distribution of inputs. Best-case: (NEVER) Cheat with a slow algorithm that works fast on some input.

A Lecture /24/2015 Insertion Sort Statement Cost Times InsertionSort(A, n) for i ← 2 to n c 1 n do key ← A[i] c 2 n-1 j ← i - 1 c 3 n-1 while j > 0 and A[j] > key c 4 T do A[j+1] ← A[j] c 5 T-(n-1) j ← j - 1 c 6 T-(n-1) 0 A[j+1] ← key c 7 n-1 T = t 2 + t 3 + … + t n = where t i is number of while expression evaluations for the i th for loop iteration

A Lecture /24/2015 Analyzing Insertion Sort T(n) = c 1 n + c 2 (n-1) + c 3 (n-1) + c 4 T + c 5 (T - (n-1)) + c 6 (T - (n-1)) + c 7 (n-1) = c 8 T + c 9 n + c 10 What can T be?  Best case -- inner loop body never executed ot i = 1  T(n) is a linear function  Worst case -- inner loop body executed for all previous elements ot i = i  T(n) is a quadratic function  Average case o???

A Lecture /24/2015 Analysis Simplifications  Ignore actual and abstract statement costs  Order of growth is the interesting measure: oHighest-order term is what counts ] Remember, we are doing asymptotic analysis ] As the input size grows larger it is the high order term that dominates

A Lecture /24/2015 Part 3 Questions?

A Lecture /24/2015 Part 4 The course ☻ Introduction to algorithms ☻ Algorithm analysis basics [Ch 2.1, 2.2] ☻ Asymptotic notation[Ch3]

A Lecture /24/2015 Asymptotic Complexity Running time of an algorithm for large input sizes. Expressed using only the highest-order term in the expression for the exact running time.  Instead of exact running time, say  (n 2 ). Describe behavior of functions in the limit. Described using Asymptotic Notation.

A Lecture /24/2015 Asymptotic Notation , O, , o,  Defined in terms of functions whose domain is the set of natural numbers.  Ex: f(n) =  (n 2 ).  Describes how f(n) grows in comparison to n 2. Determine sets of functions, in practice used to compare two function sizes. The notations differ in the rate-of-growth relation they describe between the defining function and the defined set of functions.

A Lecture /24/2015  -notation  (g(n)) = {f(n):  +ve constants c 1, c 2, and n 0 such that 0  c 1 g(n)  f(n)  c 2 g(n),  n  n 0 } For function g(n),  (g(n)) is given by: g(n) is an asymptotically tight bound for f(n). Intuitively: Set of all functions that have the same rate of growth as g(n).

A Lecture /24/2015 O -notation O(g(n)) = {f(n):  +ve constants c and n 0 such that 0  f(n)  cg(n),  n  n 0 } For function g(n), O(g(n)) is given by: g(n) is an asymptotic upper bound for f(n). Intuitively: Set of all functions whose rate of growth is the same as or lower than that of g(n). f(n) =  (g(n))  f(n) = O(g(n)).  (g(n))  O(g(n)).

A Lecture /24/2015  -notation  (g(n)) = {f(n):  +ve constants c and n 0 such that 0  cg(n)  f(n),  n  n 0 } For function g(n),  (g(n)) is given by: g(n) is an asymptotic lower bound for f(n). Intuitively: Set of all functions whose rate of growth is the same as or higher than that of g(n). f(n) =  (g(n))  f(n) =  (g(n)).  (g(n))   (g(n)).

A Lecture /24/2015 Relations Between , O, 

A Lecture /24/2015 Upper Bound Notation We say InsertionSort’s run time is O(n 2 )  Properly we should say run time is in O(n 2 )  Read O as “Big-O” (you’ll also hear it as “order”) In general a function  f(n) is O(g(n)) if there exist positive constants c and n 0 such that f(n)  c  g(n) for all n  n 0 Formally  O(g(n)) = { f(n):  positive constants c and n 0 such that f(n)  c  g(n)  n  n 0 }

A Lecture /24/2015 Insertion Sort Is O(n 2 ) Proof  Suppose runtime is an 2 + bn + c oIf any of a, b, and c are less than 0 replace the constant with its absolute value an 2 + bn + c  (a + b + c)n 2 + (a + b + c)n + (a + b + c)  3(a + b + c)n 2 for n  1 Let c’ = 3(a + b + c) and let n 0 = 1 Question  Is InsertionSort O(n 3 )?  Is InsertionSort O(n)?

A Lecture /24/2015 Big O Fact A polynomial of degree k is O(n k ) Proof:  Suppose f(n) = b k n k + b k-1 n k-1 + … + b 1 n + b 0 oLet a i = | b i |  f(n)  a k n k + a k-1 n k-1 + … + a 1 n + a 0

A Lecture /24/2015 Lower Bound Notation We say InsertionSort’s run time is  (n) In general a function  f(n) is  (g(n)) if  positive constants c and n 0 such that 0  c  g(n)  f(n)  n  n 0 Proof:  Suppose run time is an + b oAssume a and b are positive (what if b is negative?)  an  an + b

A Lecture /24/2015 Asymptotic Tight Bound A function f(n) is  (g(n)) if  positive constants c 1, c 2, and n 0 such that c 1 g(n)  f(n)  c 2 g(n)  n  n 0 Theorem  f(n) is  (g(n)) iff f(n) is both O(g(n)) and  (g(n))

A Lecture /24/2015 Practical Complexity

A Lecture /24/2015 Practical Complexity

A Lecture /24/2015 Practical Complexity

A Lecture /24/2015 Practical Complexity

A Lecture /24/2015 Other Asymptotic Notations A function f(n) is o(g(n)) if  positive constants c and n 0 such that f(n) < c g(n)  n  n 0 A function f(n) is  (g(n)) if  positive constants c and n 0 such that c g(n) < f(n)  n  n 0 Intuitively,  o() is like <  O() is like    () is like >   () is like    () is like =

A Lecture /24/2015 Part 4 Questions?

A Lecture /24/2015 Review: Induction Suppose  S(k) is true for fixed constant k oOften k = 0  S(n)  S(n+1) for all n >= k Then S(n) is true for all n >= k

A Lecture /24/2015 Proof By Induction Claim:S(n) is true for all n >= k Basis:  Show formula is true when n = k Inductive hypothesis:  Assume formula is true for an arbitrary n Step:  Show that formula is then true for n+1

A Lecture /24/2015 Induction Example: Gaussian Closed Form Prove … + n = n(n+1) / 2  Basis: oIf n = 0, then 0 = 0(0+1) / 2  Inductive hypothesis: oAssume … + n = n(n+1) / 2  Step (show true for n+1): … + n + n+1 = ( …+ n) + (n+1) = n(n+1)/2 + n+1 = [n(n+1) + 2(n+1)]/2 = (n+1)(n+2)/2 = (n+1)(n+1 + 1) / 2

A Lecture /24/2015 The End Read your text Ch1, Ch2.1, Ch2.2, Ch3!