1 5. Abstract Data Structures & Algorithms 5.6 Algorithm Evaluation.

Slides:



Advertisements
Similar presentations
Order of complexity. Consider four algorithms 1.The naïve way of adding the numbers up to n 2.The smart way of adding the numbers up to n 3.A binary search.
Advertisements

Growth-rate Functions
Time Analysis Since the time it takes to execute an algorithm usually depends on the size of the input, we express the algorithm's time complexity as a.
Practice Quiz Question
Complexity Theory  Complexity theory is a problem can be solved? Given: ◦ Limited resources: processor time and memory space.
Algorithmic Complexity Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Wednesday, 11/25/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 11/25/02  QUESTIONS??  Today:  More on sorting. Advanced sorting algorithms.  Complexity:
Review for Test 2 i206 Fall 2010 John Chuang. 2 Topics  Operating System and Memory Hierarchy  Algorithm analysis and Big-O Notation  Data structures.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Sorting Algorithms and Analysis Robert Duncan. Refresher on Big-O  O(2^N)Exponential  O(N^2)Quadratic  O(N log N)Linear/Log  O(N)Linear  O(log N)Log.
© 2006 Pearson Addison-Wesley. All rights reserved10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Data Structure & Algorithm Lecture 3 –Algorithm Analysis JJCAO.
External Sorting Problem: Sorting data sets too large to fit into main memory. –Assume data are stored on disk drive. To sort, portions of the data must.
Algorithm Analysis (Big O)
COMP s1 Computing 2 Complexity
SIGCSE Tradeoffs, intuition analysis, understanding big-Oh aka O-notation Owen Astrachan
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
1 Chapter 24 Developing Efficient Algorithms. 2 Executing Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
1 Recursion Algorithm Analysis Standard Algorithms Chapter 7.
{ CS203 Lecture 7 John Hurley Cal State LA. 2 Execution Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
CS 2430 Day 28. Announcements We will have class in ULR 111 on Monday Exam 2 next Friday (sample exam will be distributed next week)
1.2. Comparing Algorithms. Learning outcomes Understand that algorithms can be compared by expressing their complexity as a function relative to the size.
(C) 2010 Pearson Education, Inc. All rights reserved. Java How to Program, 8/e.
Chapter 19 Searching, Sorting and Big O
Analysis of Algorithms
Algorithm Evaluation. What’s an algorithm? a clearly specified set of simple instructions to be followed to solve a problem a way of doing something What.
Chapter 2 Array Data Structure Winter Array The Array is the most commonly used Data Storage Structure. It’s built into most Programming languages.
Searching. RHS – SOC 2 Searching A magic trick: –Let a person secretly choose a random number between 1 and 1000 –Announce that you can guess the number.
CSE1301 Computer Programming: Lecture 26 List Processing (Search)
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 19: Searching and Sorting.
CSC 205 Java Programming II Algorithm Efficiency.
Ch 18 – Big-O Notation: Sorting & Searching Efficiencies Our interest in the efficiency of an algorithm is based on solving problems of large size. If.
Big Oh Algorithms are compared to each other by expressing their efficiency in big-oh notation Big O notation is used in Computer Science to describe the.
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
Introduction to: Programming CS105 Lecture: Yang Mu.
Java Methods Big-O Analysis of Algorithms Object-Oriented Programming
3.3 Complexity of Algorithms
Sorting.
Algorithm Analysis (Big O)
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
CS 2430 Day 30. Announcements Quiz #5: 4/19 Agenda Big O Searching –Linear search.
E.G.M. PetrakisAlgorithm Analysis1  Algorithms that are equally correct can vary in their utilization of computational resources  time and memory  a.
C++ How to Program, 7/e © by Pearson Education, Inc. All Rights Reserved.
Searching Topics Sequential Search Binary Search.
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.
0 Introduction to asymptotic complexity Search algorithms You are responsible for: Weiss, chapter 5, as follows: 5.1 What is algorithmic analysis? 5.2.
 2006 Pearson Education, Inc. All rights reserved. 1 Searching and Sorting.
WHICH SEARCH OR SORT IS BETTER?. COMPARING ALGORITHMS Time efficiency refers to how long it takes an algorithm to run Space efficiency refers to the amount.
Complexity of Algorithms Fundamental Data Structures and Algorithms Ananda Guna January 13, 2005.
Section 1.7 Comparing Algorithms: Big-O Analysis.
1 Algorithms Searching and Sorting Algorithm Efficiency.
1 5. Abstract Data Structures & Algorithms 5.6 Algorithm Evaluation.
Algorithm Complexity is concerned about how fast or slow particular algorithm performs.
Algorithmic Efficency
Introduction to complexity
Big O notation Big O notation is used in Computer Science to describe the performance or complexity of an algorithm. Big O specifically describes the worst-case.
Lesson Objectives Aims Understand the following: The big O notation.
Introduction to Algorithms
Sorting by Tammy Bailey
Big O: Make it Simple Determine how complex the algorithm is, in relative to the size of the problem (e.g: List to be sorted) 'O' Stands for 'Order' -
Teach A level Computing: Algorithms and Data Structures
Algorithmic complexity: Speed of algorithms
Big O Notation.
Analyzing an Algorithm Computing the Order of Magnitude Big O Notation
Algorithmic Complexity
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
Algorithmic complexity: Speed of algorithms
CSE 332: Parallel Algorithms
Presentation transcript:

1 5. Abstract Data Structures & Algorithms 5.6 Algorithm Evaluation

5.6.1 Big O Notation

Is efficiency the same as speed?

4 Efficiency The efficiency of an algorithm depends on: ‣ the speed of the processor ‣ available memory ‣ how well the algorithm is written Only the latter is under the programmer's control

5 Speed vs memory Usually a compromise between these two. e.g. a linked list (dynamic) requires less memory that an array (static), but searching an array is faster if they are the same size.

6 Processor speed This is not usually measured in time, but in number of operations per second. Often floating point operations per second (flops), or gigaflops, teraflops, etc. Obviously depends on the number of elements you are processing (n)

7 Memory More cache makes the processor faster. More IAS means ‣ less time paging data in and out of virtual memory on the hard drive, and ‣ more data/programs running simultaneously

8 Algorithm speed Difficult to predict - depends on circumstances E.g. a linear search of an array: ‣ best case scenario: 1 (it's the first element!) ‣ worst case scenario: n (it's not there and you've wasted your time looking at n elements!) ‣ average case scenario: n/2

9 BigO notation BigO notation assumes worst case It is defined in terms of n, the number of elements being operated on. You should know the BigO efficiency of a single operation, linear search (array or linked list), binary search, bubble and selection sort, quicksort

Single operation Only need one operation no matter what the arguments E.g. reading a value from a random access file. BigO efficiency for a single operation is O(1)

Linear search The time to search an array is proportional to the size of the array BigO efficiency for a linear search is O(n)

Binary search Binary search is more complex, but the splitting in half each time is efficient on a logarithmic scale Big O order is O(log n) A binary search is much more efficient than linear with larger numbers of elements.

Quicksort Quicksort is the binary equivalent for sorting Big O order is O(n log n) More efficient than bubble or selection sort with larger numbers of elements

Bubble sort With a bubble sort and a selection sort, you have to compare each element with every other one, so the BigO order is O(n 2 ) Time requirements are proportional to the square of the size of the list (double the number of elements, quadruple the time taken)

Sorting In some circumstances, the efficiency of an algorithm may depend on the distribution of the data E.g. a quicksort where the pivot is chosen too far away from the centre may deteriorate to O(n 2 ).

16 Other operations An input or output is O(1) (single operation) Sequential access of a data file is O(n) (it’s a linear search) Direct access of a data file is O(1) (single operation) Finding a specified element of an array is O(1).