Module 01 Intro Example For Big-O Shipping
Module 01 Intro Example For Big-O Shipping
Algorithms
An introductory example
Delivering packages
• Suppose we need to deliver 20 packages to 20 homes.
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
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
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?
…
Home 1 Home 2 Home 20
Warehouse
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.