0
0
Intro to Computingfundamentals~20 mins

Algorithm efficiency basics (fast vs slow) in Intro to Computing - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Algorithm Efficiency Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding Algorithm Speed with Real-Life Analogy

Imagine you have two ways to find a book in a library:

  • Method A: You check every book one by one from the first shelf to the last.
  • Method B: You use the library's index to go directly to the shelf where the book is.

Which method is faster and why?

ABoth methods take the same time because you have to look at the book eventually.
BMethod B is faster because it uses a shortcut to find the book quickly.
CMethod A is faster because you see every book and won't miss it.
DNeither method works because books are randomly placed.
Attempts:
2 left
💡 Hint

Think about how using a map or index helps you reach your destination faster.

trace
intermediate
2:00remaining
Trace the Number of Steps in Two Algorithms

Given a list of 5 numbers: [3, 7, 2, 9, 5]

Algorithm 1: Check each number to see if it is 9.

Algorithm 2: Sort the list first, then check if 9 is the last number.

How many steps does each algorithm take to find the number 9?

Intro to Computing
lst = [3, 7, 2, 9, 5]

# Algorithm 1
for num in lst:
    if num == 9:
        break

# Algorithm 2
sorted_list = sorted(lst)
if sorted_list[-1] == 9:
    pass
AAlgorithm 1 takes 4 steps; Algorithm 2 takes 6 steps.
BAlgorithm 1 takes 9 steps; Algorithm 2 takes 3 steps.
CAlgorithm 1 takes 3 steps; Algorithm 2 takes 10 steps.
DAlgorithm 1 takes 5 steps; Algorithm 2 takes 5 steps.
Attempts:
2 left
💡 Hint

Count how many numbers are checked before finding 9 in Algorithm 1. For Algorithm 2, consider sorting steps plus the check.

Comparison
advanced
1:30remaining
Comparing Algorithm Growth Rates

Which algorithm will be faster for very large input sizes?

Algorithm X: Runs in time proportional to n (linear time).

Algorithm Y: Runs in time proportional to n squared (quadratic time).

AAlgorithm Y is faster for small inputs but slower for large inputs.
BBoth algorithms run at the same speed for large inputs.
CAlgorithm X is faster because its time grows slower as input size increases.
DAlgorithm Y is faster because it does more work per step.
Attempts:
2 left
💡 Hint

Think about how doubling the input size affects each algorithm's steps.

identification
advanced
1:30remaining
Identify the Algorithm Type from Description

An algorithm checks every pair of items in a list to find duplicates. If the list has n items, it compares each item with every other item.

What is the time complexity of this algorithm?

AO(n squared)
BO(n log n)
CO(n)
DO(1)
Attempts:
2 left
💡 Hint

Think about how many pairs are in a list of n items.

🚀 Application
expert
2:00remaining
Choose the Most Efficient Algorithm for Large Data

You need to search for a name in a phone book with 1 million entries.

Which method is the most efficient?

ASort the phone book first, then look for the name.
BRandomly pick names until you find the target.
CLook at each name from the start until you find the target (linear search).
DUse a binary search on the sorted phone book.
Attempts:
2 left
💡 Hint

Think about how dividing the search space helps find the target faster.