Topic 5 (HL)
Abstract Data Structures
IB Computer Science
How to Approach this Topic
- Don’t freak out - this topic is deceptively difficult
- Learn the fundamentals presented in this video
- Practice your reading comprehension
- Do practice problems
Static Data Structures
- Number of elements determined at creation of data structure - cannot be
changed later on
- Can be memory inefficient, because RAM is allocated based on predetermined
number of elements, rather than actual elements, leaving possibility of unused
memory space
- Iterated through using FOR loops
- Examples: Arrays
Dynamic Data Structures
- No need to predetermine number of elements, any number of elements can
exist in data structure at any time
- Each element exists at a particular memory address and is referred to as a
node .
- Each node contains a “reference” to the memory address of the next element
in the data structure. This reference is called a pointer .
- Usually more memory efficient than static data structures
- Iterated through using WHILE loops
- Examples: Collections
Static vs. Dynamic
2D Arrays
- An array of arrays
- array[row][column]
- Used to display data points with 2 dimensions
- Used to display grids
2D Arrays - Basic Tasks
- Identify specific positions in 2D arrays
- Iterate through 2D Arrays
- Iterate through rows in 2D arrays
- Iterate through “columns” in 2D Arrays
- Count values in 2D Arrays
Recursion
- Recursion is when a method calls itself until some terminating condition is
met, known as the base case .
- Recursion can be used in situations where the next result of an operation
depends on the current result.
- Some good examples including the Fibonacci sequence or a factorial function
- Each step until the base case is reached is called a recursive step .
- All recursive functions can be written iteratively (without calling itself)
Recursion Examples
Recursion - Basic Tasks
- Calculate the output of a recursive function
Recursion Pros & Cons
Part 2 - Table of Contents
- Recursion Review
- Stacks
- Queues
- Linked Lists
- Part 3: Binary Trees, Extra Practice
Stacks
- Dynamic Data Structure
- LIFO (Last in First Out) - the last
element to be “pushed” (inserted) into
the stack is the first to be removed
(“popped”)
- Used to keep track of function calls
Stacks - Basic Tasks
- Add and remove values from a stack
- Completely empty a stack
- Transfer from array to stack and vice-versa
- Count the number of values in a stack
Queues
- Dynamic Data Structure
- FIFO (First in First Out) - the first
element to be “enqueued”
(inserted) is the last to be
“dequeued” (removed) like a
real-life queue
Queues - Basic Tasks
- Add and remove values from a queue
- Completely remove values from a queue
- Transfer from array to queue and vice-versa
- Transfer from stack to queue and vice-versa
- Count the number of values in a queue
Part 3 - Table of Contents/Channel Updates
- Linked Lists
- Binary Search Trees
Channel Updates
- Option A in Progress
- Check the description for Cram Guides
- For existing customers, minor updates to HL and SL Guides
Linked Lists
- Head, Pointer, Node, Tail
- Types of Linked Lists
- Single Linked
- Double Linked
- Circular Linked
Linked Lists - Basic Tasks
- Traverse a linked list
- Front and back of circular linked list
- Insert values from a linked list
- Remove values from a linked list
Binary (Search) Trees - Basic Tasks
- Build a binary tree from a set of integers or letters
- Traverse a binary tree using preorder, inorder, and postorder methods
- Add new values to a binary tree
- Remove existing values from a binary tree
Binary (Search) Trees Pros & Cons
Advantages Disadvantages
Searching is time efficient - Only half the Need to be “balanced”
elements need to be checked
Elements don’t need to be removed to be Insertion and deletion are slow due to need
checked like stacks or queues to rebalance tree
Searching is slower than arrays in cases
where the location is known - the tree
needs to be traversed regardless