0
0
Data Structures Theoryknowledge~30 mins

Time complexity (Big O notation) in Data Structures Theory - Mini Project: Build & Apply

Choose your learning style9 modes available
Understanding Time Complexity (Big O notation)
πŸ“– Scenario: You are learning how to analyze the efficiency of simple algorithms by understanding their time complexity using Big O notation. This helps you know how the time to complete a task grows as the input size increases.
🎯 Goal: Build a simple example that shows how to count items in a list and understand the time complexity of this operation.
πŸ“‹ What You'll Learn
Create a list of exactly 5 fruit names
Create a variable to count how many fruits start with the letter 'A'
Use a for loop to check each fruit and update the count
Add a final statement that represents the time complexity of this counting operation
πŸ’‘ Why This Matters
🌍 Real World
Understanding time complexity helps you write efficient programs that run faster and handle large data well.
πŸ’Ό Career
Many tech jobs require analyzing and improving algorithm efficiency to optimize software performance.
Progress0 / 4 steps
1
Create the list of fruits
Create a list called fruits with these exact entries: 'Apple', 'Banana', 'Avocado', 'Cherry', 'Apricot'.
Data Structures Theory
Need a hint?

Use square brackets [] to create a list and separate items with commas.

2
Create a counter variable
Create a variable called count_a and set it to 0. This will count fruits starting with the letter 'A'.
Data Structures Theory
Need a hint?

Use a simple assignment to create the counter variable.

3
Count fruits starting with 'A'
Use a for loop with variable fruit to go through fruits. Inside the loop, use an if statement to check if fruit starts with the letter 'A'. If yes, increase count_a by 1.
Data Structures Theory
Need a hint?

Use the startswith() method to check the first letter of the fruit.

4
Add the time complexity comment
Add a comment line that states the time complexity of this counting operation as # Time complexity: O(n) where n is the number of fruits.
Data Structures Theory
Need a hint?

This means the time grows linearly with the number of items.