Reasons to study Data Structures & Algorithms

Slides:



Advertisements
Similar presentations
Lecture: Algorithmic complexity
Advertisements

Razdan with contribution from others 1 Algorithm Analysis What is the Big ‘O Bout? Anshuman Razdan Div of Computing.
Chapter 10 Algorithm Efficiency
 Last lesson  Arrays for implementing collection classes  Performance analysis (review)  Today  Performance analysis  Logarithm.
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
Algorithm Cost Algorithm Complexity. Algorithm Cost.
Algorithm Analysis. Algorithm Def An algorithm is a step-by-step procedure.
Introduction to complexity. 2 Analysis of Algorithms Why do we need to analyze algorithms? –To measure the performance –Comparison of different algorithms.
Basic Concepts 2014, Fall Pusan National University Ki-Joune Li.
Data Structure and Algorithm Analysis About the Course Objective Organize a large amount of data Algorithm: the operation on the organized data.
Analyzing algorithms & Asymptotic Notation BIO/CS 471 – Algorithms for Bioinformatics.
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
COSC 2P03 Week 11 Reasons to study Data Structures & Algorithms Provide abstraction Handling of real-world data storage Programmer’s tools Modeling of.
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.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 2 Prepared by İnanç TAHRALI.
Chapter 2 Computational Complexity. Computational Complexity Compares growth of two functions Independent of constant multipliers and lower-order effects.
Foundations of Algorithms, Fourth Edition
COSC 1P03 Data Structures and Abstraction 2.1 Analysis of Algorithms Only Adam had no mother-in-law. That's how we know he lived in paradise.
Algorithm Analysis. What is an algorithm ? A clearly specifiable set of instructions –to solve a problem Given a problem –decide that the algorithm is.
Data Structures Using C++ 2E
Searching Topics Sequential Search Binary Search.
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.
0 Introduction to asymptotic complexity Search algorithms You are responsible for: Weiss, chapter 5, as follows: 5.1 What is algorithmic analysis? 5.2.
1 Chapter 2 Algorithm Analysis All sections. 2 Complexity Analysis Measures efficiency (time and memory) of algorithms and programs –Can be used for the.
1 Chapter 2 Algorithm Analysis Reading: Chapter 2.
Basic Concepts 2011, Fall Pusan National University Ki-Joune Li.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 3. Introduction to the Analysis of Algorithms.
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.
Algorithms April-May 2013 Dr. Youn-Hee Han The Project for the Establishing the Korea ㅡ Vietnam College of Technology in Bac Giang.
Data Structures I (CPCS-204) Week # 2: Algorithm Analysis tools Dr. Omar Batarfi Dr. Yahya Dahab Dr. Imtiaz Khan.
Recursion.
Algorithm Analysis 1.
Chapter 2 Algorithm Analysis
Analysis of Non – Recursive Algorithms
Analysis of Non – Recursive Algorithms
Analysis of Algorithms
Thought for the Day “Years wrinkle the skin, but to give up enthusiasm wrinkles the soul.” – Douglas MacArthur.
Introduction to complexity
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
COMP 53 – Week Seven Big O Sorting.
Data Structures Using The Big-O Notation 1.
Big-Oh and Execution Time: A Review
Algorithm Analysis (not included in any exams!)
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
CS 201 Fundamental Structures of Computer Science
Programming and Data Structure
Analysis of Algorithms
DS.A.1 Algorithm Analysis Chapter 2 Overview
Programming and Data Structure
Reasons to study Data Structures & Algorithms
Asst. Dr.Surasak Mungsing
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.
Introduction to Algorithm and its Complexity Lecture 1: 18 slides
CSE 1342 Programming Concepts
Time Complexity Lecture 15 Mon, Feb 27, 2006.
8. Comparison of Algorithms
Complexity Analysis (Part II)
Estimating Algorithm Performance
Analysis of Algorithms
Algorithms and data structures: basic definitions
Algorithm Analysis How can we demonstrate that one algorithm is superior to another without being misled by any of the following problems: Special cases.
2019, Fall Pusan National University Ki-Joune Li
Presentation transcript:

Reasons to study Data Structures & Algorithms Provide abstraction Handling of real-world data storage Programmer’s tools Modeling of real-world objects and concepts Programs more readable, understandable, maintainable If you have a good feeling for them, you are a better programmer! You can solve the problem faster Your program works better, with fewer bugs You will know when you have been given an impossible task COSC 2P03 Week 1

Considerations Speed Memory usage Complexity of structure Examples of tradeoffs: Insertion speed vs. search speed vs. deletion speed Structure vs. speed Your task as a programmer: think of the tradeoffs and select the best option COSC 2P03 Week 1

Complexity Expresses the efficiency of an algorithm Running time expressed as function of problem size Problem size: number of inputs Some complexity classes: Logarithmic Linear Quadratic Exponential COSC 2P03 Week 1

“Big O” notation Function g(n) is O(f(n)) if there are positive constants c and n0 such that g(n) ≤ c*f(n) for all n ≥ n0 Upper bound on its rate of growth Determines algorithm’s “cost” in terms of time to run Note: other measurements exist for lower bound (etc) COSC 2P03 Week 1

Complexity Examples 1 and 2 for(i = 0; i < n; i++) { b[i] = a[i]+1; c[i] = a[i]+b[i]; } for(j = 7; j < n; j=j+3) { COSC 2P03 Week 1

Complexity Example 3 Question: what if the outer loop were changed to: for(i = 0; i < n; i++) { if(a[i] > 0) { for(j = 0; j < n; j++) c[i] = c[i] + b[j]; } else c[i] = b[i]; Question: what if the outer loop were changed to: for(i = 1; i < n; i=i*2)? COSC 2P03 Week 1

Complexity Example 4 int xyz(int n) { if(n <= 1) return 1; else return xyz(n/2) + n; } Question: what if the last statement were changed to return xyz(n-2) + n; ? COSC 2P03 Week 1

Complexity Example 5 int bc(int n) { int c; c = 0; while(n > 0) { c = c + (n % 2); n = n / 2; } return c; COSC 2P03 Week 1

Complexity Example 6 int pc(int n) { int i, c; if(n == 1) { return 1;   if(n == 1) { return 1; } c = 0; for(i = 0; i < n; i++) { c = c + pc(n-1); return c; COSC 2P03 Week 1

Table of Computational Complexity If a step takes 0.001 ms and the problem size is N: N=10 N=100 N=1000 Steps Time f(N) = N 10 0.01ms 100 0.1ms 1000 1ms f(N) = N2 104 10ms 106 1s f(N) = N3 1.0ms 109 16.67min f(N) = 2N 1024 1.02ms 1.27x1030 4.0x1016 yrs 1.07x10301 3.4x10287 yrs COSC 2P03 Week 1

Comparison: O(n2) vs O(n log n) Assume a machine is running at 200 000 MIPs Assume 1 instruction per iteration. Time to sort 1 billion numbers: Bubble sort O(n2) (109)2 steps / (2x1011 steps/sec) ≈ 2 months. Quick sort O(n log n) 109 * log2(109) steps / (2x1011 steps/sec) ≈ 109 * 30 steps / (2x1011 steps/sec) ≈ 0.15 seconds. COSC 2P03 Week 1

The Rules of Recursion (Weiss, section 1.3) There must be base cases that can be solved without recursion Recursive calls must always make progress towards a base case Assume that all recursive calls work Never duplicate work by solving the same instance of a problem in separate recursive calls COSC 2P03 Week 1 12

Recursive method printOut (Weiss, section 1.3) public static void printOut(int n) { if(n >= 10) printOut(n/10); printDigit(n % 10); } COSC 2P03 Week 1 13

Output printOut(5034) { if(5034 >= 10) // true printOut(5034 / 10); printDigit(5034 % 10); } Output 4 3 5 printOut(503) { if(503 >= 10) // true printOut(503 / 10); printDigit(503 % 10); } printOut(50) { if(50 >= 10) // true printOut(50 / 10); printDigit(50 % 10); } printOut(5) { if(5 >= 10) // false printDigit(5 % 10); } 14 COSC 2P03 Week 1

Sequence of calls to determine F5 fib(5) fib(4) fib(3) fib(3) fib(2) fib(2) fib(1) fib(2) fib(1) fib(1) fib(0) fib(1) fib(0) fib(1) fib(0) COSC 2P03 Week 1 15