In deze les zitten 22 slides, met interactieve quizzen en tekstslides.
Lesduur is: 60 min
Onderdelen in deze les
OCR A Level - Lists and linked lists
Slide 1 - Tekstslide
Key objective - Learn what a linked list is and why we use them?
Key Objective - To learn what lists and linked lists are.
Learning objectives:
- Understand lists and linked lists
- Difference between dynamic and static data structures
- Implement list operations
Slide 2 - Tekstslide
What is a list?
Slide 3 - Open vraag
Lists are data structures that can contain multiple data types.
The elements are stored in order and are indexed starting from 0.
They are stored non-contiguous, meaning they do not have to be stored next to each other in memory.
my_list = [10, 20, 30, 40, 50]
Slide 4 - Tekstslide
There are other data structures similar to lists such as:
- Records
- Tuples
- Dictionaries
Slide 5 - Tekstslide
Self investigation
Self Investigation
Visit W3 schools and research list methods in Python
Slide 6 - Tekstslide
Operation
Initial List
New List
my_list.insert(0, 5)
[10, 20, 30, 40, 50]
my_list.append(60)
[10, 20, 30, 40, 50]
my_list.remove(30)
[10, 20, 30, 40, 50]
my_list.pop(1)
[10, 20, 30, 40, 50]
my_list.reverse()
[10, 20, 30, 40, 50]
my_list.sort()
[40, 10, 30, 20, 50]
[5,10,20,30,40,50]
[10,20,30,40,50,60]
[10,20,40,50
[10,30,40,50]
[50,40,30,20,10]
[10,20,30,40,50
Slide 7 - Sleepvraag
Task:
You are tasked with developing a simple grade management system for a student. The program should allow the user to perform the following operations:
- Add a new grade to the list of grades.
- Remove a specific grade from the list.
- Compute the average of all grades in the list.
- Sort the grades either in ascending or descending order.
- Display the list of all grades the student has received.
Stretch:
- Write functions to find and display the highest and lowest grades in the list.
- Only allow grades between 0 and 100 (inclusive). Reject invalid inputs.
- Create a UI using simple loop that continuously asks the user for their choice of operation (add, remove, average, sort, display) and performs that operation until the user decides to exit.
Slide 8 - Tekstslide
Slide 9 - Tekstslide
Static Data Structure
- In languages like C/Java, lists (arrays) are fixed size
- This is a fixed data structure that is reserved at the start of the program.
- Eg we can set up a fixed size of list at the start of the program.
- Static data structure fixed during program compilation
- Memory locations fixed and can be accessed easily and quickly and are in a contiguous position in memory.
- Memory is allocated even when it is not being used.
Slide 10 - Tekstslide
Dynamic memory allocation
Dynamic memory allocation uses linked lists and makes it much easier to remove
Slide 11 - Tekstslide
Dynamic Data Structure
- In languages like Python, the list is dynamically resizable.
- More flexible and more efficient only use memory that is needed.
- Access time may be slower due to indexing and pointer usage
- Memory can be allocated and deallocated as required while the program is running
- Dynamic data structure can change during the running of the program