Basic Concepts 2011, Fall Pusan National University Ki-Joune Li.

Slides:



Advertisements
Similar presentations
Algorithms Algorithm: what is it ?. Algorithms Algorithm: what is it ? Some representative problems : - Interval Scheduling.
Advertisements

MATH 224 – Discrete Mathematics
Analysis of Algorithms
Intro to Analysis of Algorithms. Algorithm “A sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any.
Lecture3: Algorithm Analysis Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
Razdan with contribution from others 1 Algorithm Analysis What is the Big ‘O Bout? Anshuman Razdan Div of Computing.
Analysys & Complexity of Algorithms Big Oh Notation.
Chapter 1 – Basic Concepts
Algorithmic Complexity Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Fall 2006CENG 7071 Algorithm Analysis. Fall 2006CENG 7072 Algorithmic Performance There are two aspects of algorithmic performance: Time Instructions.
Complexity Analysis (Part I)
Analysis of Algorithms1 Estimate the running time Estimate the memory space required. Time and space depend on the input size.
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.
Data Structures Performance Analysis.
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.
Elementary Data Structures and Algorithms
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
Algorithm Analysis (Big O)
COMP s1 Computing 2 Complexity
Algorithm analysis and design Introduction to Algorithms week1
Asymptotic Notations Iterative Algorithms and their analysis
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.
CSC 201 Analysis and Design of Algorithms Lecture 03: Introduction to a CSC 201 Analysis and Design of Algorithms Lecture 03: Introduction to a lgorithms.
Chapter 2.6 Comparison of Algorithms modified from Clifford A. Shaffer and George Bebis.
Week 2 CS 361: Advanced Data Structures and Algorithms
SEARCHING, SORTING, AND ASYMPTOTIC COMPLEXITY Lecture 12 CS2110 – Fall 2009.
Discrete Structures Lecture 11: Algorithms Miss, Yanyan,Ji United International College Thanks to Professor Michael Hvidsten.
Basic Concepts 2014, Fall Pusan National University Ki-Joune Li.
Chapter 1 1. Overview: System life cycle Requirements Analysis Bottom-up Top-down Design Data objects (abstract data type) and operations (algorithm)
Lecture 2 Computational Complexity
Unit III : Introduction To Data Structures and Analysis Of Algorithm 10/8/ Objective : 1.To understand primitive storage structures and types 2.To.
Analysis of Algorithms
CS 221 Analysis of Algorithms Instructor: Don McLaughlin.
© 2011 Pearson Addison-Wesley. All rights reserved 10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
CSE1301 Computer Programming: Lecture 26 List Processing (Search)
Asymptotic Notation (O, Ω, )
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
Data Structure Introduction.
Algorithm Analysis CS 400/600 – Data Structures. Algorithm Analysis2 Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely.
Computer Science and Software Engineering University of Wisconsin - Platteville 8. Comparison of Algorithms Yan Shi CS/SE 2630 Lecture Notes Part of this.
Algorithms and data structures: basic definitions An algorithm is a precise set of instructions for solving a particular task. A data structure is any.
Chapter 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
3.3 Complexity of Algorithms
RUNNING TIME 10.4 – 10.5 (P. 551 – 555). RUNNING TIME analysis of algorithms involves analyzing their effectiveness analysis of algorithms involves analyzing.
1 Asymptotic Notations Iterative Algorithms and their analysis Asymptotic Notations –Big O,  Notations Review of Discrete Math –Summations –Logarithms.
Big-O. Algorithm Analysis Exact analysis: produce a function f(n) measuring how many basic steps are needed for a given inputs n On any input of size.
Lecture 2 Analysis of Algorithms How to estimate time complexity? Analysis of algorithms Techniques based on Recursions ACKNOWLEDGEMENTS: Some contents.
Asymptotic Notations By Er. Devdutt Baresary. Introduction In mathematics, computer science, and related fields, big O notation describes the limiting.
Algorithm Analysis (Big O)
تصميم وتحليل الخوارزميات عال311 Chapter 3 Growth of Functions
E.G.M. PetrakisAlgorithm Analysis1  Algorithms that are equally correct can vary in their utilization of computational resources  time and memory  a.
1 Chapter 2 Algorithm Analysis All sections. 2 Complexity Analysis Measures efficiency (time and memory) of algorithms and programs –Can be used for the.
Algorithms Lecture #05 Uzair Ishtiaq. Asymptotic Notation.
1 Chapter 2 Algorithm Analysis Reading: Chapter 2.
Ch03-Algorithms 1. Algorithms What is an algorithm? An algorithm is a finite set of precise instructions for performing a computation or for solving a.
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.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong
Introduction To Algorithm and Data Structures Course Teacher: Moona Kanwal -Algorithm Design -Algorithm Analysis -Data structures -Abstract Data Type.
2017, Fall Pusan National University Ki-Joune Li
Chapter 2 Algorithm Analysis
Introduction to Algorithms
DATA STRUCTURES Introduction: Basic Concepts and Notations
Algorithm An algorithm is a finite set of steps required to solve a problem. An algorithm must have following properties: Input: An algorithm must have.
2018, Fall Pusan National University Ki-Joune Li
Searching, Sorting, and Asymptotic Complexity
Asst. Dr.Surasak Mungsing
2019, Fall Pusan National University Ki-Joune Li
Presentation transcript:

Basic Concepts 2011, Fall Pusan National University Ki-Joune Li

STEMPNU 2 Data Structures ? Refrigerator Problem  If we have only one item in my refrigerator, no problem.  If we have several items in a refrigerator, How to place milk, eggs, kimchi, beers, etc. in a refrigerator ? How to measure the efficiency ? Placement and cooking  Placement : something about materials  Cooking : something about activities or processes  Some Organization or Structures Data Structures  How to place data in memory

STEMPNU 3 What is good data structure? What is good placement in refrigerator ?  Easy to cook (and place) What is good data structure ?  Easy to process  Data Structures (Placement of materials) + Algorithms (Cooking) = Program (Meal)  Good Data Structures support good algorithms Method to process : Algorithm

STEMPNU What are the core functions of data structures? 4

STEMPNU 5 Abstract Data Type Object-Oriented Programming  Object ? Abstraction (or Encapsulation)  Hiding the internal details Implementation Internal mechanism and process  Only provide Interfaces Abstract Data Type  Hiding the internal structures once it has been implemented  Provide only the interface to the users

STEMPNU 6 Example of Abstract Data Types Example ADT ADT NaturalNumber is functions: for all x, y in NaturalNumber; true, false in Boolean, and where +,-,<,==, and = are integer operations Zero(): NaturalNumber ::= 0 IsZero(x): Boolean ::= if(x==0) isZero=true else isZero=false Add(x,y): NaturalNumber ::= if(x+y<=MAXINT) Add=x+y else ADD=MAXINT End NaturalNumber Implementation Zero IsZero Add

STEMPNU 7 Algorithms Algorithm  A sequence of instructions with specifications of Input Output : at least one output Definiteness : Clear instructions Finiteness Effectiveness  Abstract description of a program Can be easily converted to a program Correctness of algorithm

STEMPNU 8 Performance Analysis What is a good algorithm ?  Correctness  Good documentation and readable code  Proper structure  Effective How to measure the effectiveness of an algorithm ?  Space complexity Amount of memory it needs to run  Time complexity Amount of time (mostly CPU time) it needs to run

STEMPNU 9 Space Complexity Notation  Space complexity, f (n) : function of input size n  How should the constants be determined ?  Is it meaningful to count the number of bytes ? int sumAB(int a, int b) { int sum; sum=a+b; return sum; } int sumArray(int n, int *a) { int sum=0; for(int i=0;i<n;i++) sum += a[i]; return sum; } int sumArray(int n, int *a) { if(n<=0) return 0; return a[n-1]+sumArrary(n-1,a); } f (n) = c 1 c 1 : constant f (n) = c 2 a[n] ? f (n) = c 3 n why ?

STEMPNU 10 Time Complexity Notation  Time complexity, f (n) : function of input size n int sumAB(int a, int b) { int sum; sum=a+b; return sum; } int sumArray(int n, int *a) { int sum=0; for(int i=0;i<n;i++) sum += a[i]; return sum; } int sumArray(int n, int *a) { if(n<=0) return 0; return a[n-1]+sumArrary(n-1,a); } f (n) = 2 +  f (n) = 3 n +1 +  f (n) = (2+  ) n Is it really meaningful to determine these constants ?

STEMPNU 11 Asymptotic Notation Exact time (or step count) to run  Depends on machines and implementation (program)  NOT good measure More general (but inexact) notation : Asymptotic Notation  Big-O O(n) : Upper Bound  Omega-O  (n) : Lower Bound  Theta-O  (n) : More precise than Big-O and Omega-O  Big-O notation is the most popular one.

STEMPNU 12 Big-O notation Definition ( f of n is big-O of g of n)  f (n)  O(g (n))  there exist c and n 0 (c, n 0 >0) such that f (n)  c·g(n), for all n (  n 0 ) Example  3n + 2 = O(n), 3n + 2 = O(n 2 )  Time complexity of the following algorithm f (n)= O(n) int sumArray(int n, int *a) { if(n<=0) return 0; return a[n-1]+sumArrary(n-1,a); }

STEMPNU 13 Big-O notation : Some Properties Classification  O(1): constant, O(n): Linear, O(n 2 ): Quadratic, O(2 n ): exponential Polynomial function  If f (n) = a m n m + a m-1 n m-1 + … + a 1 n + a 0, then f (n)  O(n m ) Big-O is determined by the highest order Only the term of the highest order is of our concern Big-O : useful for determining the upper bound of time complexity  When only an upper bound is known, Big-O notation is useful  In most cases, not easy to find the exact f (n)  Big-O notation is the most used.

STEMPNU 14 Omega-O notation Definition ( f of n is Omega-O of g of n)  f (n)   (g (n))  there exist c and n 0 (c, n 0 >0) such that f (n)  c·g(n), for all n (  n 0 ) Example  3n + 2 =  (n), 3n + 2 =  (1), 3n =  (n),  Time complexity of the following algorithm f (n)=  (n) If f (n) = a m n m + a m-1 n m-1 +…+ a 1 n+a 0, then f (n)   (n m )  Omega-O is determined by the highest order Omega-O notation : useful to describe the lower bound int sumArray(int n, int *a) { if(n<=0) return 0; return a[n-1]+sumArrary(n-1,a); }

STEMPNU 15 Theta-O notation Definition ( f of n is theta-O of g of n)  f (n)   (g (n))  there exist c 1, c 2 and n 0 (c 1, c 2, and n 0 >0) such that c 1 ·g(n)  f (n)  c 2 ·g(n), for all n (  n 0 ) Example  3n + 2 =  (n), 3n + 2   (1), 3n   (n),  Time complexity of the following algorithm f (n)=  (n) If f (n) = a m n m + a m-1 n m-1 +…+ a 1 n+a 0, then f (n)   (n m )  Theta-O is determined by the highest order Theta-O  Possible Only if f (n)=  (g(n)), and f(n)=  (g(n))  Lower bound and Upper bound is the same  very exact but not easy to find such a g(n) int sumArray(int n, int *a) { if(n<=0) return 0; return a[n-1]+sumArrary(n-1,a); }

STEMPNU 16 Complexity Analysis Worst-Case Analysis  Time complexity for the worst case  Example Linear Search : f (n) = n Average Analysis  Average time complexity  f (n) = p 1 f 1 (n) + p 2 f 2 (n) + … p k f k (n), where p i is the probability for the i -th case.  Not easy to find p i In most cases, only worst-case analysis Why not Best-Case Analysis ?

STEMPNU 17 Example : Worst-Case Time complexity of Binary Search Binary Search  Big-O : O(n 2 ), O(log n)  Omega O :  (1),  (log n)  Theta O :  (log n) int BinarySearch(int v, int *a, int lower, int upper) // search m among a sorted array a[1ower], a[lower+1], … a[upper] { if(l<=u) { int m=(lower+upper)/2; if(v>a[m]), return BinarySearch(v,a,m+1,upper); else if(v<a[m]) return BinarySearch(v,a,lower,m-1); else /* v==a[m] */ return m; } return -1; // not found }

STEMPNU 18 Comparison : O(1), O(log n), O(n), O(n 2 ), O(2 n ) Graph In general  Algorithm of O(1) is almost impossible  Algorithms of O(log n) is excellent  Algorithms of O(n) is very good  Algorithms of O(n 2 ) is not bad  Algorithms of O(n 3 ) is acceptable  Algorithms of O(2 n ) is not useful