Software Learning Resource Service Platform BASIC CONCEPT CHAPTER 1 BASIC CONCEPT 1.

Slides:



Advertisements
Similar presentations
CHAPTER 2 ALGORITHM ANALYSIS 【 Definition 】 An algorithm is a finite set of instructions that, if followed, accomplishes a particular task. In addition,
Advertisements

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
1 Data Structures Performance Analysis. 2 Fundamental Concepts Some fundamental concepts that you should know: –Dynamic memory allocation. –Recursion.
Fall 2006CENG 7071 Algorithm Analysis. Fall 2006CENG 7072 Algorithmic Performance There are two aspects of algorithmic performance: Time Instructions.
Scott Grissom, copyright 2004 Chapter 5 Slide 1 Analysis of Algorithms (Ch 5) Chapter 5 focuses on: algorithm analysis searching algorithms sorting algorithms.
CHAPTER 11 Space and Time Complexity in Chapter 1 All the programs in this file are selected from Ellis Horowitz, Sartaj Sahni, and Susan Anderson-Freed.
Data Structures Performance Analysis.
Analysis of Algorithms (pt 2) (Chapter 4) COMP53 Oct 3, 2007.
CHAPTER 2 ANALYSIS OF ALGORITHMS Part 1. 2 Big Oh and other notations Introduction Classifying functions by their asymptotic growth Theta, Little oh,
Analysis of Algorithms COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
CHAPTER 1 BASIC CONCEPT All the programs in this file are selected from Ellis Horowitz, Sartaj Sahni, and Susan Anderson-Freed “Fundamentals of Data Structures.
What is Program  A Set of Instructions  Data Structures + Algorithms  Data Structure = A Container stores Data  Algoirthm = Logic + Control.
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
Algorithm Analysis (Big O)
CHAPTER 2 ALGORITHM ANALYSIS 【 Definition 】 An algorithm is a finite set of instructions that, if followed, accomplishes a particular task. In addition,
1 Chapter 2 Program Performance – Part 2. 2 Step Counts Instead of accounting for the time spent on chosen operations, the step-count method accounts.
Program Performance & Asymptotic Notations CSE, POSTECH.
Week 2 CS 361: Advanced Data Structures and Algorithms
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved ADT Implementation:
C. – C. Yao Data Structure. C. – C. Yao Chap 1 Basic Concepts.
For Wednesday Read Weiss chapter 3, sections 1-5. This should be largely review. If you’re struggling with the C++ aspects, you may refer to Savitch, chapter.
1 Recursion Algorithm Analysis Standard Algorithms Chapter 7.
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)
Unit III : Introduction To Data Structures and Analysis Of Algorithm 10/8/ Objective : 1.To understand primitive storage structures and types 2.To.
CS Data Structures Chapter 1 Basic Concepts.
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.
Zeinab EidAlgorithm Analysis1 Chapter 4 Analysis Tools.
Java Methods Big-O Analysis of Algorithms Object-Oriented Programming
Introduction to Analysis of Algorithms CS342 S2004.
Algorithm Analysis Part of slides are borrowed from UST.
Chapter 2 Computational Complexity. Computational Complexity Compares growth of two functions Independent of constant multipliers and lower-order effects.
Lecture 2 Analysis of Algorithms How to estimate time complexity? Analysis of algorithms Techniques based on Recursions ACKNOWLEDGEMENTS: Some contents.
Algorithm Analysis (Big O)
1 Chapter 2 Algorithm Analysis All sections. 2 Complexity Analysis Measures efficiency (time and memory) of algorithms and programs –Can be used for the.
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
1 Chapter 2 Algorithm Analysis Reading: Chapter 2.
Basic Concepts 2011, Fall Pusan National University Ki-Joune Li.
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.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Recursion,
SPACE COMPLEXITY & TIME COMPLEXITY 1. ALGORITHMS COMPLEXITY 2.
2017, Fall Pusan National University Ki-Joune Li
Algorithm Analysis 1.
Chapter 2 Algorithm Analysis
Analysis of Non – Recursive Algorithms
Analysis of Non – Recursive Algorithms
Analysis of Algorithms
GC 211:Data Structures Week 2: Algorithm Analysis Tools
GC 211:Data Structures Algorithm Analysis Tools
What is an Algorithm? Algorithm Specification.
Data Structures (1/2) 內容:Basic Concepts, Arrays and Structures, Stacks and Queues, Lists, Trees, Graphs, Sorting, Hashing, Heap Structures, and Search.
Data Structure 김용성 Data Structure in C.
Chapter 2 Fundamentals of the Analysis of Algorithm Efficiency
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.
Algorithm Efficiency Chapter 10.
2018, Fall Pusan National University Ki-Joune Li
Data Structures-CSE207.
Analysys & Complexity of Algorithms
GC 211:Data Structures Algorithm Analysis Tools
Performance analysis of algorithms
CHAPTER 1 BASIC CONCEPT All the programs in this file are selected from Ellis Horowitz, Sartaj Sahni, and Susan Anderson-Freed “Fundamentals of Data Structures.
CS210- Lecture 2 Jun 2, 2005 Announcements Questions
Data structures & Algorithm Strategies
2019, Fall Pusan National University Ki-Joune Li
Presentation transcript:

Software Learning Resource Service Platform BASIC CONCEPT CHAPTER 1 BASIC CONCEPT 1

Software Learning Resource Service Platform How to create programs (Waterfall Model)  Requirements  Analysis  Design: Architecture Design Detailed Design – Data Type 、 Algorithm User Interface Design (option)  Coding and Refinement  Verification and Testing  Maintain 2

Software Learning Resource Service Platform Algorithm  Definition An algorithm is a finite set of instructions that accomplishes a particular task.  Criteria Input ≧ 0 Output ≧ 1 Definiteness: clear and unambiguous Finiteness: terminate after a finite number of steps Effectiveness: instruction is basic enough to be carried out 3

Software Learning Resource Service Platform Recursion Definition Definition: Functions can call themselves (direct recursion) or they may call other functions that invoke the calling function again (indirect recursion). Type Type : 1.Direct Recursion 2.Indirect Recursion 3.Tail Recursion A( ){ … A( ); … } A( ){ … B( ); … } B( ){ … A( ); … } A( ){ … A( ) }

Software Learning Resource Service Platform Recursion 5 The advantages and disadvantages of recursion (compared with Iteration) (compared with Iteration): Advantages Advantages: 1.Powerful in expression. Allow us to express a very complex process in very clear term. 2.Save space. 3.The recursion is not need more local variables to support.Disadvantages: For the most part recursion is slower, and takes up more of the stack as well. EX EX: N! 、 Fibonacci Number 、 Ackerman’s function 、 Binary tree traversal 、 Quick sort 、 Tower of Hanoi 、 Permutation

Software Learning Resource Service Platform We can try to find out (a) terminal condition (b) recursive relationship →if (a) then (end or return result) else return (b) Recursion 6

Software Learning Resource Service Platform Abstract Data Type specification implementation An abstract data type (ADT) is a data type that is organized in such a way that the specification of the objects and the operations on the objects is separated from the representation of the objects and the implementation of the operations. 7

Software Learning Resource Service Platform Abstract Data Type 8 ex) Sack is an ADT specification of the objects: 1. a set of elements 2. top pointer 3. stack size the specification of the operations: 1. push (i, s) 2. pop (s) i

Software Learning Resource Service Platform Abstract Data Type 9 ex) Sack is an ADT representation of the objects : Array Link-list top: integer=0 top: pointer=nil size: integer=n no size limit

Software Learning Resource Service Platform Abstract Data Type 10 ex) Sack is an ADT the implementation of the operations push(i, s) push(i, s) if stack_full then error new t else t^data=i top=top+1 t^link=top s[top]=i top=t

Software Learning Resource Service Platform Performance Analysis or Measurement  Performance Measurement (machine dependent)  Performance Analysis (machine independent) space complexity space complexity: storage requirement fixed space requirements: code space, simple type variable, fixed size structure variable, constant variable space requirements: structure parameters, recursion time complexity time complexity: computing time 11

Software Learning Resource Service Platform Time Complexity compute the step count  Introduce variable count into programs  Tabular method step per execution  frequency Determine the total number of steps contributed by each statement step per execution  frequency add up the contribution of all statements 12

Software Learning Resource Service Platform float sum(float list[ ], int n) { float tempsum = 0; count++; /* for assignment */ int i; for (i = 0; i < n; i++) { count++; /*for the for-loop */ tempsum += list[i]; count++; /* for assignment */ } count++; /* last execution of for */ count++; /* for return */ return tempsum; } Iterative summing of a list of numbers 2n + 3 steps 13

Software Learning Resource Service Platform Tabular Method 14 Statements/eFrequencyTotal steps float sum(float list[ ], int n)000 {000 float tempsum = 0;111 int i;000 for (i=0;i<n; i++)1n+1 tempsum += list[i]1Nn return tempsum;111 }000 Total2n+3

Software Learning Resource Service Platform float rsum(float list[ ], int n) { count++; /*for if conditional */ if (n) { count++; /* for return and rsum invocation */ return rsum(list, n-1) + list[n-1]; } count++; return list[0]; } Recursive summing of a list of numbers 15 2n+2 steps

Software Learning Resource Service Platform Recursive Function to sum of a list of numbers 16 Statements/eFrequencyTotal steps float rsum(float list[], int n)000 {000 if (n)1n+1 return rsum(list, n-1)+list[n-1];1nn return list[0];111 }000 Total2n+2

Software Learning Resource Service Platform Tabular Method 17 for (i=1; i<n, i++) { a=(b+c)*d/e } for (i=1; i<n, i++) { T1=b+c T2=T1*d T3=T2/e } n?3n?

Software Learning Resource Service Platform Asymptotic Notation (O) 18  Definition f(n) = O(g(n)) iff there exist two positive constants c and n 0 such that f(n)  cg(n) for all n, n  n 0.  Examples 2n+3= 3n 2 +2n+3= O(n) /* 2n+3  3n for n  3 */ O(n 2 ) /* 3n2+2n+3  4n2 for n  3 */ O(n 2 )? /* 2n+3  n2 for n  3 */

Software Learning Resource Service Platform Theorem 19

Software Learning Resource Service Platform Asymptotic Notation (O) (upper bound) 20  Examples –

Software Learning Resource Service Platform Basic Principle  O(1): constant  O(logn)  O(n): linear  O(nlogn)  O(n 2 ): quadratic  O(n 3 ): cubic  O(2 n ): exponential  O( )  O(n!)  O( ) 21

Software Learning Resource Service Platform 22 *Figure 1.7:Function values (p.42)

Software Learning Resource Service Platform 23 *Figure 1.8:Plot of function values(p.43) Human Population Moore’s Law Cell Division

Software Learning Resource Service Platform 24 *Figure 1.9:Times on a 1 billion instruction per second computer(p.44)

Software Learning Resource Service Platform 25 Ordering by asymptotic growth rates in asceding order Question:

Software Learning Resource Service Platform 26 Ordering by asymptotic growth rates in asceding order Question:

Software Learning Resource Service Platform Asymptotic Notation (Ω) (Lower bound)  Definition f(n) = Ω(g(n)) iff there exist two positive constants c and n 0 such that f(n) ≧ cg(n), for all n, n ≧ n 0  Examples 27

Software Learning Resource Service Platform Asymptotic Notation (θ)  Definition f(n) = θ(g(n)) iff there exist three positive constants C 1,C 2 and n 0 such that C 1 g(n) ≦ f(n) ≦ C 2 g(n) for all n, n ≧ n 0  Examples 28 3n+2= (n) /* 3n+2  3n for n  2 */ 3n+2= O (n) /* 3n+2  4n for n  2 */

Software Learning Resource Service Platform 29 Question:

Software Learning Resource Service Platform 30 Question:

Software Learning Resource Service Platform 31 Which of the following statements is not correct? (a)20 is O(1) (b)n(n-1)/2 is O( ) (c)max(, ) is O( ) (d) is O( ) (e)If p(x) is any degree polynomial with a positive leading coefficient, then p(n) is O( ) Question:  O(2 n )

Software Learning Resource Service Platform 32 List the functions below from lowest to highest order Question:

Software Learning Resource Service Platform 33 Question:

Software Learning Resource Service Platform Show that the following statements are correct (a) (b) (c) 34 Question:

Software Learning Resource Service Platform For i=1 to n do For k=(i+1) to n do x=x+1 以 x=x+1 之執行次數當 T(n) , T(n)? 35 Question:

Software Learning Resource Service Platform For i=1 to n do For j=i to n do For k=j to n do x=x+1 以 x=x+1 之執行次數當 T(n) , T(n)? 36 Question:

Software Learning Resource Service Platform For k=1 to n do For i=0 to k-1 do For j=0 to k-1 do x=x+1 以 x=x+1 之執行次數當 T(n) , T(n)? 37 Question:

Software Learning Resource Service Platform T(n)=2T(n-1)+T(1), T(1)=1, T(n)? 38 Question:

Software Learning Resource Service Platform T(n)=T(n/2)+T(1), T(1)=1, T(n)? 39 Question:

Software Learning Resource Service Platform T(n)=2T(n/2)+n, T(1)=1, T(n)? 40 Question:

Software Learning Resource Service Platform T(n)=T(n-1)+n, T(1)=1, T(n)? 41 Question:

Software Learning Resource Service Platform T(n)=T(n-1)+T(n-2), T(0)=0, T(1)=1, T(n)? 42 Question: