Data Structure Flashcards

Data Structures
Definition: Ways to organise and store data in a computer so it can be used efficiently.
List
Definition: A container that can hold a bunch of items in a specific order. You can add, remove, or change items.
Array
Definition: In Python, lists and arrays are more or less the same thing. Other languages like Java use the term 'Array' or 'ArrayList'.
Single Dimensional Array
Example: A linear collection of items. For example, a simple list of colours: ["red", "green", "blue"].
Multi-Dimensional Array
Definition: An array with more than one dimension, often thought of as a table or a grid (list of lists).
Record
Definition: Groups related data together with named fields. Also known as a Tuple in Python.
Set
Definition: A data structure that stores a collection of unique elements where the order does not matter.
Python List Method: append()
Action: Adds a new item to the end of a list.
Python List Method: remove()
Action: Removes the first occurrence of a specified value from a list.
Accessing an element in a 2D list/array
Method: Use two indices, the first for the row and the second for the column. Example: colors_2d[0][1].
Python Tuple (Record)
Key Feature: An ordered, immutable collection of items. Its contents cannot be changed.
namedtuple
Purpose: Used for creating simple, immutable record types with named fields for easy access.
Creating a Set in Python
Method: Use curly braces {} or the set() constructor with a list. Example: my_set = {1, 2, 3}.
Python Set Method: add()
Action: Adds an element to a set. If the element is already present, it does nothing.
Python Set Method: remove()
Action: Removes a specified element from a set.
Key characteristic of a Set
Rule: It does not allow duplicate elements.
Main purpose of Data Structures
Goal: To manage and process data efficiently within a computer program.
Data Structure Analogy
Analogy: They are like containers, each designed for a specific purpose in organizing data.
Key difference between Lists and Tuples
Difference: Lists are mutable (changeable), while Tuples are immutable (unchangeable).
Java ArrayList
Relation: A resizable array implementation in Java, similar in function to a Python list.
Data stored in a Record
Content: Can be of different data types, grouped together under named fields.
Order in a List
Rule: The order of items is preserved and matters.
Order in a Set
Rule: The order of items is not guaranteed and does not matter.
What happens when you add a duplicate to a Set?
Result: Nothing. The set remains unchanged as it only stores unique values.
Core Data Structures in BTEC Spec
List them: Lists, Arrays (single and multi-dimensional), Records, and Sets.