1 Nonrecursive Algorithm Analysis * Dr. Ying Lu September 6, 2012 RAIK 283: Data Structures & Algorithms *slides refrred tohttp://www.aw-bc.com/info/levitin.

Slides:



Advertisements
Similar presentations
MATH 224 – Discrete Mathematics
Advertisements

Knapsack Problem Section 7.6. Problem Suppose we have n items U={u 1,..u n }, that we would like to insert into a knapsack of size C. Each item u i has.
Analysis of Algorithms
1 Recursive Algorithm Analysis Dr. Ying Lu RAIK 283: Data Structures & Algorithms September 13, 2012.
Divide and Conquer Strategy
CS4413 Divide-and-Conquer
Design and Analysis of Algorithms – Chapter 51 Divide and Conquer (III)* Dr. Ying Lu RAIK 283: Data Structures & Algorithms *slides referred.
Chapter 2: Fundamentals of the Analysis of Algorithm Efficiency
Text Chapters 1, 2. Sorting ä Sorting Problem: ä Input: A sequence of n numbers ä Output: A permutation (reordering) of the input sequence such that:
Chapter 2 Fundamentals of the Analysis of Algorithm Efficiency Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Design and Analysis of Algorithms - Chapter 21 Analysis of Algorithms b Issues: CorrectnessCorrectness Time efficiencyTime efficiency Space efficiencySpace.
Algorithms. Problems, Algorithms, Programs Problem - a well defined task. –Sort a list of numbers. –Find a particular item in a list. –Find a winning.
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.
CSC 2300 Data Structures & Algorithms January 30, 2007 Chapter 2. Algorithm Analysis.
Chapter 2: Fundamentals of the Analysis of Algorithm Efficiency
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 2 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Design and Analysis of Algorithms – Chapter 51 Divide and Conquer (I) Dr. Ying Lu RAIK 283: Data Structures & Algorithms.
Design and Analysis of Algorithms Chapter Analysis of Algorithms Dr. Ying Lu August 28, 2012
Algorithms. Problems, Algorithms, Programs Problem - a well defined task. –Sort a list of numbers. –Find a particular item in a list. –Find a winning.
February 17, 2015Applied Discrete Mathematics Week 3: Algorithms 1 Double Summations Table 2 in 4 th Edition: Section th Edition: Section th.
Analysis and Design of Algorithms. According to math historians the true origin of the word algorism: comes from a famous Persian author named ál-Khâwrázmî.
1 Chapter 24 Developing Efficient Algorithms. 2 Executing Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
Lecture 2 Computational Complexity
CS 3343: Analysis of Algorithms
Algorithm Correctness A correct algorithm is one in which every valid input instance produces the correct output. The correctness must be proved mathematically.
Design and Analysis of Algorithms - Chapter 21 Analysis of Algorithms b Issues: CorrectnessCorrectness Time efficiencyTime efficiency Space efficiencySpace.
10/13/20151 CS 3343: Analysis of Algorithms Lecture 9: Review for midterm 1 Analysis of quick sort.
Analysis of Algorithm Efficiency Dr. Yingwu Zhu p5-11, p16-29, p43-53, p93-96.
RAIK 283: Data Structures & Algorithms
Télécom 2A – Algo Complexity (1) Time Complexity and the divide and conquer strategy Or : how to measure algorithm run-time And : design efficient algorithms.
12-CRS-0106 REVISED 8 FEB 2013 CSG523/ Desain dan Analisis Algoritma Mathematical Analysis of Nonrecursive Algorithm Intelligence, Computing, Multimedia.
Lecture 5 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
Data Structure Introduction.
CS 361 – Chapters 8-9 Sorting algorithms –Selection, insertion, bubble, “swap” –Merge, quick, stooge –Counting, bucket, radix How to select the n-th largest/smallest.
Design and Analysis of Algorithms Chapter Asymptotic Notations* Dr. Ying Lu August 30, RAIK.
Data Structures and Algorithm Analysis Introduction Lecturer: Ligang Dong, egan Tel: , Office: SIEE Building.
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “ Introduction to the Design & Analysis of Algorithms, ” 2 nd ed., Ch. 1 Chapter.
Divide and Conquer Strategy
2-0 Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “ Introduction to the Design & Analysis of Algorithms, ” 2 nd ed., Ch. 2 Theoretical.
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 2 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Design and Analysis of Algorithms – Chapter 71 Space-Time Tradeoffs: String Matching Algorithms* Dr. Ying Lu RAIK 283: Data Structures.
Lecture 4 Jianjun Hu Department of Computer Science and Engineerintg University of South Carolina CSCE350 Algorithms and Data Structure.
LECTURE 2 : fundamentals of analysis of algorithm efficiency Introduction to design and analysis algorithm 1.
CS 116 Object Oriented Programming II Lecture 13 Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong
Algorithms.
Analysis of Algorithms
Analysis of algorithms
Applied Discrete Mathematics Week 2: Functions and Sequences
Design and Analysis of Algorithms Chapter -2
Analysis of algorithms
Algorithm Analysis CSE 2011 Winter September 2018.
Chapter 2 Fundamentals of the Analysis of Algorithm Efficiency
Chapter 2 Fundamentals of the Analysis of Algorithm Efficiency
Chapter 2 Fundamentals of the Analysis of Algorithm Efficiency
Algorithms + Data Structures = Programs -Niklaus Wirth
CS 3343: Analysis of Algorithms
2.1 Day 3 Linear Transformations
Fundamentals of the Analysis of Algorithm Efficiency
Mathematical Analysis of Non- recursive Algorithm PREPARED BY, DEEPA. B, AP/ CSE VANITHA. P, AP/ CSE.
Ch. 2: Getting Started.
CSC 380: Design and Analysis of Algorithms
CSC 380: Design and Analysis of Algorithms
At the end of this session, learner will be able to:
Analysis of algorithms
Fundamentals of the Analysis of Algorithm Efficiency
Divide and Conquer Merge sort and quick sort Binary search
Applications of Arrays
Divide and Conquer Merge sort and quick sort Binary search
Presentation transcript:

1 Nonrecursive Algorithm Analysis * Dr. Ying Lu September 6, 2012 RAIK 283: Data Structures & Algorithms *slides refrred tohttp://

2 Time efficiency of nonrecursive algorithms b Steps in mathematical analysis of nonrecursive algorithms:

3 Time efficiency of nonrecursive algorithms b Steps in mathematical analysis of nonrecursive algorithms: Decide on parameter n indicating input’s sizeDecide on parameter n indicating input’s size Identify algorithm’s basic operationIdentify algorithm’s basic operation Determine worst, average, & best case for inputs of size nDetermine worst, average, & best case for inputs of size n Set up summation for C(n) reflecting algorithm’s loop structureSet up summation for C(n) reflecting algorithm’s loop structure Simplify summation using standard formulas (see Appendix A)Simplify summation using standard formulas (see Appendix A)

4 Series b Proof by Gauss when 9 years old (!):

5 General rules for sums

6

7 Examples: b Matrix multiplication Section 2.3Section 2.3 b Selection sort Section 3.1Section 3.1 b Insertion sort Section 4.1Section 4.1

8 Matrix multiplication b MatrixMultiplication(A[0..n-1, 0..n-1], B[0..n-1, 0..n-1]) b Input: two n-by-n matrices A and B b Output: C = A * B =

Sorting problem b Given a list of n orderable items, rearrange them in a non-decreasing order 9

Sorting problem b Given a list of n orderable items, rearrange them in a non-decreasing order Selection SortSelection Sort –E.g. “3, 7, 8, 2” 10

11 Selection sort

Sorting problem b Given a list of n orderable items, rearrange them in a non-decreasing order Insertion SortInsertion Sort –E.g. “5, 2, 9, 1” 12

13 Insertion sort

In-class exercises 14 b P (c) & (d) b P (a) & (b)

In-Class Exercises b Problem 12: Door in a wall You are facing a wall that stretches infinitely in both directions. There is a door in the wall, but you know neither how far away nor in which direction. You can see the door only when you are right next to it. Design an algorithm that enables you to reach the door. How many steps will it require? b Please analyze the following two solutions of the problem. 15

Solution 1 b Walk right and left going each time one step farther from the initial position. A simple implementation of this idea is to do the following until the door is reached: For i = 0, 1,..., make i steps to the right, return to the initial position, make i steps to the left, and return to the initial position again. b How many steps will this algorithm require to find the door? b Does it require walking at most O(n) steps where n is the (unknown to you) number of steps between your initial position and the door. 16

Solution 2 b Walk intermittently right and left going each time exponentially farther from the initial position. A simple implementation of this idea is to do the following until the door is reached: For i = 0, 1,..., make 2 i steps to the right, return to the initial position, make 2 i steps to the left, and return to the initial position again. Let 2 k−1 < n ≤ 2 k. b How many steps will this algorithm require to find the door? b Does it require walking at most O(n) steps where n is the (unknown to you) number of steps between your initial position and the door. 17