0% found this document useful (0 votes)
10 views14 pages

Module 01 Intro Example For Big-O Shipping

Uploaded by

bekamdawit551
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views14 pages

Module 01 Intro Example For Big-O Shipping

Uploaded by

bekamdawit551
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Data Structures and

Algorithms
An introductory example
Delivering packages
• Suppose we need to deliver 20 packages to 20 homes.

• The packages all start at the warehouse.

• The delivery driver needs to get all 20 to their destination.


Package

Warehouse a home
Delivery truck
Base on an example form D. S. Malik’s Data Structures using C++ 2nd. Ed.
Delivering packages
• Some more information:
• The first home is located 1 mile from the warehouse.
• The second home is located 1 mile from the first.
• This continues for 18 more miles until the last home is reached.


Home 1 Home 2 Home 20
Warehouse

1 mile 1 mile 1 mile


1 mile

20 miles Base on an example form D. S. Malik’s Data Structures using C++ 2nd. Ed.
Delivering packages You are the delivery driver.
How would you do this?
• Some more information: Think about for a few minutes!
• The first home is located 1 mile from the warehouse.
• The second home is located 1 mile from the first.
• This continues for 18 more miles until the last home is reached.


Home 1 Home 2 Home 20
Warehouse

1 mile 1 mile 1 mile


1 mile

20 miles Base on an example form D. S. Malik’s Data Structures using C++ 2nd. Ed.
Delivering packages You are the delivery driver.
How would you do this?

• Some more information: Talk to your neighbor about their


strategy
• The first home is located 1 mile from the warehouse.
• The second home is located 1 mile from the first.
• This continues for 18 more miles until the last home is reached.


Home 1 Home 2 Home 20
Warehouse

1 mile 1 mile 1 mile


1 mile

20 miles Base on an example form D. S. Malik’s Data Structures using C++ 2nd. Ed.
Delivering packages
• Strategy A:
• Get package number 1
• Drive to Home 1
• Deliver package
• Return to warehouse
• Repeat with next package.

Base on an example form D. S. Malik’s Data Structures using C++ 2nd. Ed.
Delivering packages
• Strategy B:
• Get all 20 packages
• Drive to home 1
• Deliver package
• Drive to next home.
• Repeat until home 20 is reached and return to the warehouse.

Base on an example form D. S. Malik’s Data Structures using C++ 2nd. Ed.
How do Strategy A and Strategy B compare
• How could we compare these two strategies?
• Which way is better?
• Is there a more efficient way?
One metric: total miles driven
• How many miles of driving did strategy A require?
• How many miles of driving did strategy B require?
• Write a simulation in C++ to determine the total miles for both
strategies.

You might also like