Overview Flashcards
What is a data structure
Data structures are a way to store data in an efficient manner inside the Random Access Memory, called “RAM”
What is an array
An array is a collection of ordered, contiguous (next to each other in memory) group of elements
What is a byte
8 bits
What is RAM measured in
Bytes
What is a bit
A position that can store a 0 or 1
Integer size
4 bytes
What are the two components of RAM that are stored
Value and Address
Char size
1 byte (typically if they are ASCII characters)
Array sizing
Since arrays are contiguous and of fixed size and we don’t know if spots in RAM are open or not, we can’t always just add to the initial array. And we can’t have one array be split amongst the RAM. Order of the values matters as well. Biggest limitation of static arrays. Python and stuff have dynamic arrays as default.
Dynamic array sizing
A new array will get created (typically twice the size of the first) for more space
What can be used to implement a stack?
A dynamic array
Python: myArr = [] # default dynamic array
C++: vector<int> myArr</int>
What’s a good way to think about a stack?
Instead of horizontal, think of it as vertical. So when we say we’re pushing on to the top of the stack it means we are throwing a value to the “top” or “end” and it will land at the next available spot. We don’t have to worry about the space since it’s dynamic array. When we pop we can only do it from the “end” or “top” of the array.
What is the difference between linked lists and arrays in memory?
Arrays are stored contiguously in memory. Linked lists have no order to them in memory, but the addresses are “linked” together. They can be in some random order but connected via pointers.
What are Queues?
FIFO, first in first out
For example, print jobs. If multiple people are trying to print documents, it will be handled on a first come first serve basis.
It is an abstract interface, similar to a stack and can be implemented by multiple data structures, provided that they fulfill the contract of implementing enqueue and dequeue operations.
What is the most common implementation of a queue?
Using a linked list