3.2.6 - Data structures Flashcards
(5 cards)
Data structure
A way of organizing and storing data to enable efficient access and modification.
Array
A data structure that stores a collection of elements, typically of the same data type, in a fixed-size sequential order.
One-dimensional array
A linear data structure where elements are stored in a single row or column, accessible by a single index.
python:
names = [“Alice”, “Ben”, “Chloe”]
print(names[1]) # Output: Ben
pseudocode:
names ← [“Alice”, “Ben”, “Chloe”]
names[1] ← “Beth”
Two-dimensional array
A data structure where elements are stored in a grid or table format, accessible by two indices (row and column).
python:
table = [[“A”, “B”], [“C”, “D”]]
print(table[1][0]) # Output: C
pseudocode:
table ← [[“A”, “B”], [“C”, “D”]]
OUTPUT table[1][0]
Record
A data structure that groups together related data items of possibly different data types under one name.
python:
def create_student(name, age):
student = {
“name”: name,
“age”: age
}
return student
Create multiple students
student1 = create_student(“Alice”, 16)
student2 = create_student(“Ben”, 17)
print(student1[“name”]) # Output: Alice
print(student2[“age”]) # Output: 17
psuedocode:
RECORD Student
STRING name
INTEGER age
BOOLEAN enrolled
ENDRECORD
student1 ← Student(“Alice”, 16, TRUE)
OUTPUT student1.name