Computer Science Grade 8 20 min

Choosing Data Structures

Choosing Data Structures

Tutorial Preview

1

Introduction & Learning Objectives

Learning Objectives Identify the primary purpose of a data structure. Differentiate between an Array/List and a Dictionary/Map. Analyze a simple problem to determine its data storage needs. Select an appropriate data structure (Array/List or Dictionary/Map) for a given scenario. Justify their choice of data structure based on the problem's requirements, such as order and lookup speed. How does your phone organize your contacts so you can find a friend's number in a split second, but organize your music playlist to play in the exact order you want? 🤔 In this lesson, you'll learn about different ways to organize information in your code, called data structures. We'll focus on how to pick the perfect tool for the job, just like a chef chooses the right knife...
2

Key Concepts & Vocabulary

TermDefinitionExample Data StructureA specialized format for organizing, processing, retrieving, and storing data in a computer.A bookshelf is a data structure for books. You can organize them by author, title, or color. Array / ListA data structure that stores a collection of items in a specific, numbered order. You access items using their numerical index (position).A to-do list: `[ '1. Do homework', '2. Walk the dog', '3. Play video games' ]`. The order is important, and each item has a position (0, 1, 2...). Dictionary / MapA data structure that stores a collection of key-value pairs. You use a unique 'key' (like a word in a dictionary) to look up its 'value' (the definition).A user profile: `{ 'username': 'Gamer123&#039...
3

Core Syntax & Patterns

The Order Rule If the order of items is important, use an Array/List. Use this when you need to store items in a sequence, like steps in a recipe, a playlist, or a history of moves in a game. The position of each item matters. The Lookup Rule If you need to look up items by a unique name or identifier, use a Dictionary/Map. Use this when you need to quickly find a specific piece of information using a label, like finding a student's grade by their ID number or a user's email by their username. The Relationship Rule If data consists of labeled properties of a single object, use a Dictionary/Map. This is perfect for storing related information about one thing, such as a player's stats (health, mana, strength) or a car's properties (color, make, mode...

4 more steps in this tutorial

Sign up free to access the complete tutorial with worked examples and practice.

Sign Up Free to Continue

Sample Practice Questions

Challenging
You're designing a system for a library to track which student has checked out which book. You need to be able to instantly look up a book by its unique ISBN (a number) to see if it's checked out. The order in which books were checked out doesn't matter. What is the optimal data structure for this task?
A.Dictionary/Map, with the ISBN as the key and the student's name as the value.
B.An Array/List of book titles, because it's a list of all checked-out books.
C.Dictionary/Map, with the student's name as the key and an Array/List of their books as the value.
D.An Array/List where each item is another Array/List containing the ISBN and student name.
Challenging
A weather app needs to store the 7-day forecast. The forecast must be displayed chronologically (Today, Tomorrow, etc.). Each day's forecast has multiple properties: 'high_temp', 'low_temp', and 'condition'. What is the most effective way to structure this data?
A.single Dictionary with keys like 'day1_high', 'day1_low', 'day2_high', etc.
B.single Array/List containing all the numbers and conditions mixed together.
C.Dictionary where keys are dates and values are the high temperature only.
D.An Array/List where each item is a Dictionary/Map representing a single day's forecast.
Challenging
A developer stores a game inventory in an Array/List like this: `['Health Potion', 5, 'Magic Sword', 1, 'Gold Coins', 100]`. What is the primary flaw in this design compared to the Dictionary/Map approach from the tutorial?
A.The Array/List cannot be changed after it is created.
B.The relationship between an item and its quantity is only implied by their position, making the code fragile and hard to read.
C.This structure uses significantly more memory than a Dictionary/Map.
D.An Array/List can only store one type of data, either strings or numbers.

Want to practice and check your answers?

Sign up to access all questions with instant feedback, explanations, and progress tracking.

Start Practicing Free

More from Data Structures

Ready to find your learning gaps?

Take a free diagnostic test and get a personalized learning plan in minutes.