Comp 245 Data Structures Analysis of Algorithms. Purpose A professional programmer must be able to determine how efficient his code is. Efficiency, as.

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
MATH 224 – Discrete Mathematics
CMSC 2021 Searching and Sorting. CMSC 2022 Review of Searching Linear (sequential) search Linear search on an ordered list Binary search.
Computer Science 101 Efficiency and Complexity Analysis.
Fundamentals of Python: From First Programs Through Data Structures
Chapter 5 Efficiency and Analysis. Algorithm selection Algorithms are ordered lists of steps for solving a problem Algorithms are also abstractions of.
Chapter 11 Sorting and Searching. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Chapter Objectives Examine the linear search and.
Sorting and Searching. Searching List of numbers (5, 9, 2, 6, 3, 4, 8) Find 3 and tell me where it was.
Chapter 3: The Efficiency of Algorithms
Searching Arrays Linear search Binary search small arrays
Chapter 2: Fundamentals of the Analysis of Algorithm Efficiency
CS107 Introduction to Computer Science Lecture 7, 8 An Introduction to Algorithms: Efficiency of algorithms.
© 2006 Pearson Addison-Wesley. All rights reserved10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Analysis of Algorithms CPS212 Gordon College. Measuring the efficiency of algorithms There are 2 algorithms: algo1 and algo2 that produce the same results.
Analysis of Algorithms Dilemma: you have two (or more) methods to solve problem, how to choose the BEST? One approach: implement each algorithm in C, test.
1 Recursion Algorithm Analysis Standard Algorithms Chapter 7.
Chapter 12 Recursion, Complexity, and Searching and Sorting
Analysis of Algorithms
Chapter 19: Searching and Sorting 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.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 19: Searching and Sorting.
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.
Lecture 4: Sorting Algorithms Prof Branestawm’s Sorting Challenge.
Week 12 - Wednesday.  What did we talk about last time?  Asymptotic notation.
New Mexico Computer Science For All Algorithm Analysis Maureen Psaila-Dombrowski.
The Bubble Sort by Mr. Dave Clausen La Cañada High School.
Java Methods Big-O Analysis of Algorithms Object-Oriented Programming
Searching Chapter 13 Objectives Upon completion you will be able to:
Searching & Sorting Programming 2. Searching Searching is the process of determining if a target item is present in a list of items, and locating it A.
Computer Science 101 A Survey of Computer Science Timing Problems.
3.3 Complexity of Algorithms
Chapter 8 Sorting and Searching Goals: 1.Java implementation of sorting algorithms 2.Selection and Insertion Sorts 3.Recursive Sorts: Mergesort and Quicksort.
CMSC 100 Efficiency of Algorithms Guest Lecturers: Clay Alberty and Kellie LaFlamme Professor Marie desJardins Tuesday, October 2, 2012 Some material adapted.
CS 106 Introduction to Computer Science I 03 / 02 / 2007 Instructor: Michael Eckmann.
Chapter 9 Sorting. The efficiency of data handling can often be increased if the data are sorted according to some criteria of order. The first step is.
Computer Science 112 Fundamentals of Programming II Searching, Sorting, and Complexity Analysis.
Searching Topics Sequential Search Binary Search.
1 Algorithms Starring: Binary Search Co Starring: Big-O.
Algorithm Analysis with Big Oh ©Rick Mercer. Two Searching Algorithms  Objectives  Analyze the efficiency of algorithms  Analyze two classic algorithms.
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Assignment 5 is posted. Exercise 8 is very similar to what you will be doing with assignment 5. Exam.
Algorithm Analysis 1.
The Bubble Sort Mr. Dave Clausen La Cañada High School
Analysis of Algorithms
Introduction to complexity
Computer Science 112 Fundamentals of Programming II
Lesson Objectives Aims Understand the following: The big O notation.
Chapter 8 Arrays Objectives
Sorting Data are arranged according to their values.
Building Java Programs
Algorithm design and Analysis
Introduction to Data Structures
Chapter 3: The Efficiency of Algorithms
Lecture 6 Efficiency of Algorithms (2) (S&G, ch.3)
Sorting Data are arranged according to their values.
Algorithm Efficiency and Sorting
Chapter 3: The Efficiency of Algorithms
Analyzing an Algorithm Computing the Order of Magnitude Big O Notation
24 Searching and Sorting.
Algorithmic Complexity
Complexity of a Bubble Sort
Algorithm Efficiency and Sorting
Time Complexity Lecture 15 Mon, Feb 27, 2006.
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
Data Structures Using C++ 2E
Algorithm Efficiency and Sorting
Algorithm Efficiency and Sorting
Presentation transcript:

Comp 245 Data Structures Analysis of Algorithms

Purpose A professional programmer must be able to determine how efficient his code is. Efficiency, as we will analyze, will be determined by the approximate number of instructions needed to carry out the algorithm.

Example Assume you are asked to write an algorithm to calculate the sum of the following arithmetic series: … + (N-1) + N One method would be to write a loop that would continuously add the next number in the series to an accumulator until you reached the n th number. Another way would be to use Gauss’ formula: (N * (N+1))/2

Code Comparison Loop Solution int sum = 0; for (int i = 1; i <= N; i++) sum = sum + i; Calculating the sum will take approximately N instructions. This solution is considered linear. Formula Solution (Gaussian solution) int sum = (N * (N+1))/2; Calculating the sum will take ONE instruction regardless of N. This solution is considered constant.

Order of Magnitude Assume the following polynomial function: 3x 3 + 2x 2 – x + 5 This polynomial is classified as a third degree polynomial. This is considered the order of magnitude. The 3x 3 term dominates the equation as x gets large. The instruction efficiency of an algorithm will be a polynomial and classified according to it’s order of magnitude.

Main Classifications of Algorithms Big O Notation ConstantO(1)Gauss LogarithmicO(log 2 N)Binary Search LinearO(N)Seq Search Linear LogarithmicO(Nlog 2 N)Quicksort QuadraticO(N 2 )Bubblesort

Algorithms We Will Analyze Search Routines Unordered Sequential Search Ordered Sequential Search Binary Search Hashing Sort Routines Bubble Sort Selection Sort QuickSort

Search Method of Analysis Search algorithms are dominated by comparison operations: (value == target) Three types of cases to analyze: Best Case – finding target on first comparison Average Case – how many comparisons on average to find the target Worst Case – finding target on last access or target does not exist

Sort Method of Analysis Sort algorithms are dominated by comparison and swap operations. Three types of cases to analyze: Best Case – data is already sorted Average Case – data is randomly arranged Worst Case – data is in reverse order