Back to 课程

Computer Science GCES EDEXCEL

0% Complete
0/0 Steps
  1. Decomposition And Abstraction Edexcel
    2 主题
  2. Algorithms Edexcel
    11 主题
  3. Truth Tables Edexcel
    3 主题
  4. Binary Edexcel
    6 主题
  5. Data Representation Edexcel
    4 主题
  6. Data Storage And Compression Edexcel
    2 主题
  7. Hardware Edexcel
    5 主题
  8. Software Edexcel
    3 主题
  9. Programming Languages Edexcel
    2 主题
  10. Networks Edexcel
    7 主题
  11. Network Security Edexcel
    2 主题
  12. Environmental Issues Edexcel
    1 主题
  13. Ethical And Legal Issues Edexcel
    3 主题
  14. Cybersecurity Edexcel
    2 主题
  15. Develop Code Edexcel
    6 主题
  16. Constructs Edexcel
    4 主题
  17. Data Types And Data Structures Edexcel
    5 主题
  18. Operators Edexcel
    1 主题
  19. Subprograms Edexcel
    2 主题
课 Progress
0% Complete

Exam code:1CP2

Data Structures

What is a data structure?

  • A data structure provides a structured way to store data, which makes it easy to access and manipulate

  • Examples of data structures are:

    • Arrays

    • Records

Arrays

  • An array is a sequence of data, of the same data type stored under the same identifier

  • Elements stored in an array can be identified by an index (position in the array)

  • Indexes start with the value 0

  • An array can be both 1-dimensional and 2-dimensional

Records

  • A record is a sequence of data, usually of mixed data types with a fixed length

  • Elements stored in an array can be identified by an index (position in the array)

  • Indexes start with the value 0

Structure

Example

Arrays

scores = [1, 4, 2, 6, 2]

Records

Students = [001,"Bob", 2.99, "Birmingham"]

  • scores[0] holds the value 1

  • scores[2] holds the value 2

  • students[3] holds the value “Birmingham

Examiner Tips and Tricks

Python has it’s own data structure called a ‘list‘ which can look like both an array and record BUT they are not the same thing!

In the exam, if a list holds data of all the same type then it can be thought of as an array, if data is different types it can be thought of as a record

Python example

# Create an array of numbers

numbers = [5, 11, 15, 20, 25]

# Access elements by index

first_number = numbers[0] # Accesses the first element (index 0)

last_number = numbers[-1] # Accesses the last element (using negative index)

# Print the entire array

print("Array:", numbers)

# Modify an element

numbers[2] = 12 # Change the third element (index 2) to 12

# Print the modified array

print("Modified array:", numbers)

# Loop through the array

for number in numbers:

print("Number:", number)

1-dimensional & 2-dimensional arrays

Python example

# 1-dimensional array (list of numbers)

numbers = [3, 7, 11, 15]

# Access elements by index

first_number = numbers[0]

print("First element (1D array):", first_number)

# Loop through the array

for number in numbers:

print("Number (1D array):", number)

# 2-dimensional array

temperature_data = [

[20, 25, 30], # Week 1 temperatures

[22, 27, 29], # Week 2 temperatures

]

# Access elements by row and column index

week1_monday_temp = temperature_data[0][0] # Week 1, Monday temperature

print("Week 1, Monday temperature (2D array):", week1_monday_temp)

# Print the entire 2D array

for row in temperature_data:

print(row) # Prints each row as a list

# Loop through the 2D array (accessing elements)

for week in temperature_data:

for day in week:

print("Temperature:", day)

Responses

您的邮箱地址不会被公开。 必填项已用 * 标注