CMPT 225 Lecture 6 – Review of Complexity Analysis using the Big O notation + Comparing List ADT class implementations.

Slides:



Advertisements
Similar presentations
Razdan with contribution from others 1 Algorithm Analysis What is the Big ‘O Bout? Anshuman Razdan Div of Computing.
Advertisements

Analysys & Complexity of Algorithms Big Oh Notation.
Chapter 10 Algorithm Efficiency
CSC401 – Analysis of Algorithms Lecture Notes 1 Introduction
Complexity Analysis (Part I)
CISC220 Spring 2010 James Atlas Lecture 06: Linked Lists (2), Big O Notation.
Cmpt-225 Algorithm Efficiency.
© 2006 Pearson Addison-Wesley. All rights reserved10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Cmpt-225 Simulation. Application: Simulation Simulation  A technique for modeling the behavior of both natural and human-made systems  Goal Generate.
Algorithm Analysis (Big O)
Algorithm Analysis & Complexity We saw that a linear search used n comparisons in the worst case (for an array of size n) and binary search had logn comparisons.
Program Performance & Asymptotic Notations CSE, POSTECH.
Week 2 CS 361: Advanced Data Structures and Algorithms
Mathematics Review and Asymptotic Notation
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.
Analysis of Algorithms
© 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.
1 Introduction to Data Structures. 2 Course Name : Data Structure (CSI 221) Course Teacher : Md. Zakir Hossain Lecturer, Dept. of Computer Science Stamford.
INTRODUCTION TO DATA STRUCTURES. INTRODUCTION A data structure is nothing but an arrangement of data either in computer's memory or on the disk storage.
Data Structure Introduction.
Java Methods Big-O Analysis of Algorithms Object-Oriented Programming
Algorithm Analysis (Big O)
Scalability for Search Scaling means how a system must grow if resources or work grows –Scalability is the ability of a system, network, or process, to.
Search Algorithms Written by J.J. Shepherd. Sequential Search Examines each element one at a time until the item searched for is found or not found Simplest.
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
GC 211:Data Structures Week 2: Algorithm Analysis Tools Slides are borrowed from Mr. Mohammad Alqahtani.
Data Structures I (CPCS-204) Week # 2: Algorithm Analysis tools Dr. Omar Batarfi Dr. Yahya Dahab Dr. Imtiaz Khan.
Advanced Data Structures Lecture 1
Algorithm Analysis 1.
Introduction to Data Structures
Analysis of Algorithms
GC 211:Data Structures Week 2: Algorithm Analysis Tools
COMP108 Algorithmic Foundations Algorithm efficiency
Scalability for Search
Introduction to complexity
Analysis of Algorithms
Introduction to Algorithms
GC 211:Data Structures Algorithm Analysis Tools
Lesson Objectives Aims Understand the following: The big O notation.
CMPT 120 Topic: Searching – Part 1
CSE 373: Data Structures and Algorithms Pep Talk; Algorithm Analysis
Lecture 06: Linked Lists (2), Big O Notation
Building Java Programs
The Efficiency of Algorithms
GC 211:Data Structures Algorithm Analysis Tools
CSCI 2670 Introduction to Theory of Computing
Analysys & Complexity of Algorithms
Analysis of Algorithms
PAC Intro to “big o” Lists Professor: Evan Korth New York University
Algorithm Analysis Bina Ramamurthy CSE116A,B.
The Efficiency of Algorithms
CSE 2010: Algorithms and Data Structures Algorithms
Building Java Programs
Searching, Sorting, and Asymptotic Complexity
Analysis of Algorithms
Introduction to Algorithm and its Complexity Lecture 1: 18 slides
The Efficiency of Algorithms
Analysis 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
Complexity Analysis (Part II)
Analysis of Algorithms
CMPT 225 Lecture 5 – linked list.
Lecture 3 – Data collection List ADT
Lecture 4 – Data collection List ADT
CMPT 225 Lecture 7 – Stack.
CMPT 225 Lecture 8 – Queue.
CMPT 225 Lecture 16 – Heap Sort.
Presentation transcript:

CMPT 225 Lecture 6 – Review of Complexity Analysis using the Big O notation + Comparing List ADT class implementations

Last Lecture We saw how to … Create linked list Perform operations on a linked list Create a Node class Implement a List ADT class: Using an array Using a linked-list

Learning Outcomes At the end of this lecture, a student will be able to: Complexity Analysis: Analyze the best, worst, and average case running time of various ADT operations implemented by various data structures Abstract Data Types (ADTs): Given a set of requirements, select the most appropriate data collection ADT class, taking into account its time and space efficiency

Today’s menu Review of the Big-O notation Compare the various implementations of our List ADT class: Position-oriented versus value-oriented Array-based implementation versus link-based implementation

Satisfying Client’s Requirements When developing a solution, we must, as part of our design (Step 2) Choose the data collection ADT (List, Stack, Queue, etc…) that would best solve the problem along with its most efficient implementation In order to make these choices … We compare time efficiency and/or space efficiency of various implementations (i.e., data structure + algorithms) of the chosen ADT

Time/Space Efficiency Time efficiency of an algorithm is a measure of “time” the algorithm requires to execute Space efficiency of an algorithm is a measure of “space” (e.g. memory, secondary storage) the algorithm requires to execute Expressed using Big O notation

Big O Notation Introduced by P. Bachmann & Edmund Landau Upper bound approximation n -> size of data This approximation is good enough, since we are interested in the time and space efficiency of algorithms as n -> ∞ (i.e. as the size of data collection manipulated by algorithms increases to infinity) When the efficiency of an algorithm is found to be O(g(n)), we say that its efficiency is of order g(n) g(n) -> complexity categories

Commonly used Complexity Categories g(n): 1, log n, n, n log n, n2, nk, kn When an algorithm has a time/space efficiency of O(1) –> we say that its time/space efficiency is constant O(log n -> … logarithmic O(n) -> … linear O(n2) -> … quadratic O(nk) -> … polynomial O(kn) -> … exponential

Comparing O(g(n)) as size of data collection n -> ∞ Source: http://jsdo.it/Boony/big-o-notation

How to find the efficiency of an algorithm and express it using the Big O notation? Consider an algorithm … is its execution time (or its space) a function of n? If YES, then select this function of n, i.e., g(n) that expresses its efficiency: O(log n), O(n), O(n log n), O(n2), O(nk) or O(kn) If NO, i.e., its execution time (or its space) is not a function of n, hence it is independent of n, then as n -> ∞ , it is constant, so its efficiency is O(1)

Big O Notation - Arithmetic Sequential statements O(s1 + s2) = max[ O(s1), O(s2) ] Repeated statements O(k * n) = O(n) if k is constant Nested statements O(s1 * s2) = O(s1) * O(s2)

Activity - Time Efficiency Analysis Problem Statement: Determine whether array B is a scrambled version of array A. Both arrays have length n. Test case 1 Input: A[1,1,3,3,5] and B[3,5,1,1,1] Expected result: B is not a scrambled version of A Test case 2: Input: A[6,7,8, 9] and B[9,8,7,6] Expected result: B is a scrambled version of A We can develop 2 algorithms to solve the above problem statement and analyze their time efficiency to determine which of the 2 algorithms is the most time efficient

Activity - Time Efficiency Analysis Algorithm 1

Activity - Time Efficiency Analysis Algorithm 2

Activity – Best/Average/Worst case scenarios

Back to :Array-based implementation List ADT FriendsBook (client code) Public interface List array of Profile objects Etc... Class attributes (private): Remove Search

Link-based implementation List ADT FriendsBook (client code) Public interface List Insert linked list of Profile objects Class attributes (private): Remove Search

Comparing both implementations of the position-oriented List ADT using Big O notation Time efficiency of their operations (worst case scenario): Operations array-based link-based getElementCount insert remove removeAll retrieve

Comparing both implementations of the value-oriented List ADT using Big O notation Time efficiency of their operations (worst case scenario): Operations array-based link-based getElementCount insert remove removeAll retrieve (search)

√ Learning Check We can now … Determine the time/space efficiency of an algorithm using the Big O notation Compare the various implementations of our List ADT class: Position-oriented versus value-oriented Array-based implementation versus link-based implementation

Next Lecture Another linear data collection -> Stack