Main content
Course: AP??/College Computer Science Principles?>?Unit 4
Lesson 2: Evaluating algorithmsMeasuring an algorithm's efficiency
Problem
An online store manages an inventory of millions of products. On their front page, they show customers products related to the ones they've recently bought.
This procedure comes up with a list of similar products for a given list of products:
PROCEDURE findSimilarProducts(products) {
similarProducts ← []
FOR EACH product IN products {
similarProduct ← calcSimilar(product)
APPEND(similarProducts, similarProduct)
}
RETURN similarProducts
}
The
calcSimilar()
procedure takes 2 minutes to return a result, as it needs to do a complicated series of database lookups and mathematic operations. The other operations, creating the empty list and appending items to the list, only take a few nanoseconds.If the store calls the procedure on a list of 5 products, approximately how long will it take to complete?
?
Related content