Download presentation

Presentation is loading. Please wait.

Published byMoses Brumit Modified over 3 years ago

1
Lecture 11: Algorithms and Time Complexity I Discrete Mathematical Structures: Theory and Applications

2
Discrete Mathematical Structures: Theory and Applications 2 Learning Objectives Learn about algorithm analysis Become familiar with big-O, omega, and theta notations Explore various algorithms and their time complexity

3
Discrete Mathematical Structures: Theory and Applications 3 Algorithm Analysis A gift company that delivers calculates the shortest distance from the shop to a particular destination and hands the route to the driver. 50 packages are to be delivered to 50 different houses. The 50 houses are located 1 mile apart and are in the same area. The first house is also 1 mile from the shop.

4
Discrete Mathematical Structures: Theory and Applications 4 Algorithm Analysis Each dot represents a house and the distance between houses is 1 mile, as shown in Figure 9.2.

5
Discrete Mathematical Structures: Theory and Applications 5 Algorithm Analysis To deliver 50 packages to their destinations, one of the drivers picks up all 50 packages, drives 1 mile to the first house, and delivers the first package. Then the driver drives another mile and delivers the second package, drives another mile and delivers the third package, and so on.

6
Discrete Mathematical Structures: Theory and Applications 6 Algorithm Analysis Using this scheme, the distance driven to deliver the packages is: 1 + 1 + 1 +· · ·+ 1 = 50 miles Therefore, the total distance traveled to deliver the packages and then return to the shop is: 50 + 50 = 100 miles

7
Discrete Mathematical Structures: Theory and Applications 7 Algorithm Analysis Another driver is given a similar route to deliver another set of 50 packages. The driver looks at the route and delivers the packages as follows: The driver picks up the first package, drives 1 mile to the first house, delivers the package, and then returns to the shop. Next, the driver picks up the second package, drives 2 miles, delivers the package, and returns to the shop. The driver then picks up the third package, drives 3 miles, delivers the package, and returns to the shop.

8
Discrete Mathematical Structures: Theory and Applications 8 Algorithm Analysis This driver delivers only one package at a time. After delivering a package, the driver comes back to the shop to pick up and deliver the second package. Using this scheme, the total distance traveled is: 2 · (1 + 2 + 3+· · ·+ 50) = 2550 miles Now suppose that there are n packages to be delivered to n houses, and each house is 1 mile apart as shown in Figure 9.2. If the packages are delivered using the first scheme, the following equation gives the total distance traveled: 1 + 1+· · ·+1 + n = 2n (9.1)

9
Discrete Mathematical Structures: Theory and Applications 9 Algorithm Analysis

10
Discrete Mathematical Structures: Theory and Applications 10 Algorithm Analysis When analyzing a particular algorithm, count the number of operations that the algorithm executes. Focus on the number of operations, not on the actual computer time to execute the algorithm. This is because a given algorithm can be implemented on a variety of computers and the speed of the computer can affect the execution time. However, the number of operations performed by the algorithm would be the same on each computer.

11
Discrete Mathematical Structures: Theory and Applications 11

12
Discrete Mathematical Structures: Theory and Applications 12

13
Discrete Mathematical Structures: Theory and Applications 13

14
Discrete Mathematical Structures: Theory and Applications 14

15
Discrete Mathematical Structures: Theory and Applications 15 Algorithm Analysis

16
Discrete Mathematical Structures: Theory and Applications 16

17
Discrete Mathematical Structures: Theory and Applications 17

18
Discrete Mathematical Structures: Theory and Applications 18

19
Discrete Mathematical Structures: Theory and Applications 19 Algorithm Analysis

20
Discrete Mathematical Structures: Theory and Applications 20

21
Discrete Mathematical Structures: Theory and Applications 21

22
Discrete Mathematical Structures: Theory and Applications 22

Similar presentations

OK

Data Structures Using C++ 2E Chapter 1 Software Engineering Principles and C++ Classes.

Data Structures Using C++ 2E Chapter 1 Software Engineering Principles and C++ Classes.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Download ppt on teamviewer 10 Ppt on leverages parker Ppt on product advertising photography Ppt on non material heritage Ppt on power sharing for class 10 download Doc convert to ppt online reader Ppt on circles for class 9 Ppt on zener diode polarity Ppt on wireless sensor network security Ppt on management by objectives template