CISC220 Spring 2010 James Atlas Lecture 06: Linked Lists (2), Big O Notation.

Slides:



Advertisements
Similar presentations
 O: order of magnitude  Look at the loops and to see whether the loops are nested. ◦ One single loop: O(n) ◦ A nested loop: O(n 2 ) ◦ A nested loop.
Advertisements

Algorithm Analysis.
Lecture: Algorithmic complexity
HST 952 Computing for Biomedical Scientists Lecture 10.
Algorithm Complexity Analysis: Big-O Notation (Chapter 10.4)
MAT 4 – Kompleks Funktionsteori MATEMATIK 4 INDUKTION OG REKURSION MM 1.5 MM 1.5: Kompleksitet Topics: Computational complexity Big O notation Complexity.
Fall 2006CENG 7071 Algorithm Analysis. Fall 2006CENG 7072 Algorithmic Performance There are two aspects of algorithmic performance: Time Instructions.
Cmpt-225 Algorithm Efficiency.
The Efficiency of Algorithms
The Efficiency of Algorithms
Computer Science 2 Data Structures and Algorithms V section 2 Intro to “big o” Lists Professor: Evan Korth New York University 1.
CS 206 Introduction to Computer Science II 01 / 28 / 2009 Instructor: Michael Eckmann.
Data Structures and Algorithms1 Basics -- 2 From: Data Structures and Their Algorithms, by Harry R. Lewis and Larry Denenberg (Harvard University: Harper.
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
Algorithm Analysis (Big O)
Spring2012 Lecture#10 CSE 246 Data Structures and Algorithms.
COMP s1 Computing 2 Complexity
Week 2 CS 361: Advanced Data Structures and Algorithms
Algorithm Analysis. Algorithm An algorithm is a clearly specified set of instructions which, when followed, solves a problem. recipes directions for putting.
CSC 201 Analysis and Design of Algorithms Lecture 04: CSC 201 Analysis and Design of Algorithms Lecture 04: Time complexity analysis in form of Big-Oh.
Design and Analysis Algorithm Drs. Achmad Ridok M.Kom Fitra A. Bachtiar, S.T., M. Eng Imam Cholissodin, S.Si., M.Kom Aryo Pinandito, MT Pertemuan 04.
Analysis of Algorithms
Mathematical Preliminaries The Factorial Function Permutations Logarithms Summations Recurrence Relations Algorithm Analysis.
© 2011 Pearson Addison-Wesley. All rights reserved 10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Chapter 10 A Algorithm Efficiency. © 2004 Pearson Addison-Wesley. All rights reserved 10 A-2 Determining the Efficiency of Algorithms Analysis of algorithms.
Asymptotic Analysis-Ch. 3
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
Algorithm Efficiency and Sorting Data Structure & Algorithm.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Computer Science and Software Engineering University of Wisconsin - Platteville 8. Comparison of Algorithms Yan Shi CS/SE 2630 Lecture Notes Part of this.
RUNNING TIME 10.4 – 10.5 (P. 551 – 555). RUNNING TIME analysis of algorithms involves analyzing their effectiveness analysis of algorithms involves analyzing.
Algorithmic Analysis Charl du Plessis and Robert Ketteringham.
CISC 235: Topic 1 Complexity of Iterative Algorithms.
Efficiency of Algorithms. Node - data : Object - link : Node + createNode() + getData() + setData() + getLink() + setLink() + addNodeAfter() + removeNodeAfter()
Algorithm Analysis (Big O)
CISC220 Fall 2009 James Atlas Dec 07: Final Exam Review.
CISC220 Spring 2010 James Atlas Lecture 07: Big O Notation.
DS.A.1 Algorithm Analysis Chapter 2 Overview Definitions of Big-Oh and Other Notations Common Functions and Growth Rates Simple Model of Computation Worst.
CSE 421 Algorithms Richard Anderson Winter 2009 Lecture 4.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Concepts of Algorithms CSC-244 Unit 3 and 4 Algorithm Growth Rates Shahid Iqbal Lone Computer College Qassim University K.S.A.
Complexity of Algorithms Fundamental Data Structures and Algorithms Ananda Guna January 13, 2005.
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
GC 211:Data Structures Week 2: Algorithm Analysis Tools Slides are borrowed from Mr. Mohammad Alqahtani.
Algorithm Complexity Analysis (Chapter 10.4) Dr. Yingwu Zhu.
CSE 3358 NOTE SET 2 Data Structures and Algorithms 1.
Lecture 3COMPSCI.220.S1.T Running Time: Estimation Rules Running time is proportional to the most significant term in T(n) Once a problem size.
Algorithm Analysis 1.
Analysis of Algorithms
Thought for the Day “Years wrinkle the skin, but to give up enthusiasm wrinkles the soul.” – Douglas MacArthur.
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
Analysis of Algorithms
Introduction to Algorithms
GC 211:Data Structures Algorithm Analysis Tools
Lecture 06: Linked Lists (2), Big O Notation
Program Efficiency Interested in “order of magnitude”
Building Java Programs
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
Chapter 2: Fundamentals of the Analysis of Algorithm Efficiency
Lecture 5: complexity reading:
Analysis of Algorithms
DS.A.1 Algorithm Analysis Chapter 2 Overview
Time Complexity Lecture 14 Sec 10.4 Thu, Feb 22, 2007.
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
Intro to Data Structures
8. Comparison of Algorithms
Sum this up for me Let’s write a method to calculate the sum from 1 to some n public static int sum1(int n) { int sum = 0; for (int i = 1; i
Analysis of Algorithms
Presentation transcript:

CISC220 Spring 2010 James Atlas Lecture 06: Linked Lists (2), Big O Notation

Objectives for Today Introduce Big-O notation Reading - K+W Chap , 2.6

Collection add(x) remove(x) member(x) size() first()

Single Linked List

Class Exercise Implement add, member, first

Efficiency of Algorithms An operation for our ADT can be thought of as a “problem” An algorithm solves the “problem” –A series of steps –Each step has a cost Time Space –Efficiency is a measurement of this cost

Example 2.14/2.16

Big-O notation Describes the relationship between input size and execution time If we double the number of inputs, n, and the execution time is approximately doubled –Linear growth rate –Growth rate has an order of n –O(n)

Example 2.14/2.16 Analysis 2.14 –execution time proportional to x_length –O(n) 2.16 –execution time proportional to (x_length) 2 –O(n 2 )

Let’s count individual instructions for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { Simple Statement } for (int k = 0; k < n; k++) { Simple Statement 1 Simple Statement 2 Simple Statement 3 Simple Statement 4 Simple Statement 5 } Simple Statement 1 Simple Statement 2... Simple Statement 25

Let’s count individual instructions for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { Simple Statement } n 2 executions

Let’s count individual instructions for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { Simple Statement } for (int k = 0; k < n; k++) { Simple Statement 1 Simple Statement 2 Simple Statement 3 Simple Statement 4 Simple Statement 5 } n executions, 5 statements per = 5n

Let’s count individual instructions for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { Simple Statement } for (int k = 0; k < n; k++) { Simple Statement 1 Simple Statement 2 Simple Statement 3 Simple Statement 4 Simple Statement 5 } Simple Statement 1 Simple Statement 2... Simple Statement 25 1 execution, 25 statements = 25

Let’s count individual instructions for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { Simple Statement } for (int k = 0; k < n; k++) { Simple Statement 1 Simple Statement 2 Simple Statement 3 Simple Statement 4 Simple Statement 5 } Simple Statement 1 Simple Statement 2... Simple Statement 25 T(n) = total execution time as a function of n T(n) = n 2 + 5n + 25

Formal Big-O Definition T(n) = n 2 + 5n + 25 T(n) = O(f(n)) means that there exists a function, f(n), that for sufficiently large n and some constant c: cf(n)  T(n)

n n + 25 vs. 3n 2

Common Big-O Runtimes Constant -- O(1) Logarithmic -- O(log n) Fractional -- O(sqrt n) Linear -- O(n) Log-Linear-- O(n log n) Quadratic -- O(n 2 ) Cubic -- O(n 3 ) Exponential -- O(2 n ) Factorial -- O(n!)

Various Runtimes

Powers of n (Order of the polynomial)

Multiplicative Constants

Multiplicative Constants (cont’)

Dominant Terms (1)

Dominant Terms (2)

Dominant Terms (3)

Dominant Terms Comparison

Dominant Terms Comparison (cont’)

Class Exercise Implement last on our Linked List

Group Exercise Implement last in O(1)