3.2.6 - Data structures Flashcards

(5 cards)

1
Q

Data structure

A

A way of organizing and storing data to enable efficient access and modification.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Array

A

A data structure that stores a collection of elements, typically of the same data type, in a fixed-size sequential order.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

One-dimensional array

A

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”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Two-dimensional array

A

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]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Record

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly