Data Structures Flashcards
What is a data structure?
- A way of organising and storing data in a computer
- So that it can be accessed and modifided
Name the different data structures you need to know?
- Queues and Stacks
- Grpahs
- Trees
- Hash Tables
- Dictionary
- Vector
What is an array
- Allows multiple items of the same data type
- Under a common name
- The first element of an array is labled 0
- Can be 2D arrays
What are 2D arrays?
- Multiple axsis
- Where references are like coordinates
What are the limitations of arrays?
- Must store the same data type
- Static data structure where items cannot change in size once declared
How do you setup records?
- Define record structure - what fields will be in the record
- Declare a variable or array to use with the record structure
- Assign and retrive data from the variable record
What are lists?
- Pythons version of arrays
- Which can be edited after creation
What are tuples?
- Pythons version of arrays
- Which can be edited after creation
How do you declare tuples?
What are static data structures?
- Organisation or collection of data in memory thats fixed in size
- Max size needs to be known
- Memory can’t be rellocated once program running
- Arrays / tuples are static
What are dynamic data structures?
- Organisation or collection of data in memoery that has flexibility to grow or shrink in size
- Shows how much memory will be used
- Unused memory is allocated or de-allocated as needed
- Linked lists are dynamic
What are the advantages of dynamic data structures?
- Makes efficient use of memory
- Data structure only uses memory as it needs
What are the disadvantages of dynamic data structures?
- Risk of overflow when the allowed limit is exceeded
- RIsk of underflow if data structure is empty
- Harder to program because the code needs to keep traack of data size and location of items
What are the advantages static data structures?
- Memory allocation fixed
- Meaning no issues with adding and removing items from data structure
- Easier to program due to no requirement to check on size of data structure before accessing it
What are the disadvangtages of static data structures?
- Can be inefficient on memory
- Due to portions of the allocated memory not being used
What is the stack data structure?
- LIFO data structure (Last in First out)
- Last peice of data put in
- Is the first peice of data taken out
- Only uses pointer to see the item at the start of the stack
What is the queue data structre?
- FIFO (First Item in First Item Out)
- Uses two pointers for the front and the back
How does pushing , popping and peeking work in a stack data structure?
Push: Adds an element to the back of the queue. The pointer remains at the back of the queue.
Pop: Removes an element from the front of the queue. The pointer moves to the next element in the queue.
Peek: Returns the element at the front of the queue without removing it. The pointer remains at the front of the queue.
What is the algorithm for inserting an item into the stack?
How does insertion work in a queue?
How does deleting an item from a queue work?
- If the queue is empty, return an error message
- Remove the front node of the queue
- Set the front pointer to the next node in the queue
What are graphs?
- Dynamic data structure (grow and shrink)
- used to model nav systems, data transmission
- No rules or limitations of how the nodes can be linked to each other
What is the differnce betwen directed and undirected graphs
- Undirected = edges work in two ways
- Directed = edges work in one way
What is the weight or cost of a graph?
- Depends on the application of the graph
- Like distance or bits per second
- Found on the edges of the graph
How do you represent vertices in text form?
- The starting vertice and the ending one
- Followed by weight of edge if able to
What is an adjacency matrix?
- Used to represent a graph
- Read the top then the side to find the wieght of an edge if able it exsists
What is an adjacency list?
- Used to represent a graph
- Implemented as a list of dictionaries
- Key in each dictionary being the node and the edge weight
From A you can go to
- B - cost = 8
- C - cost = 2
What are the advantages of adjacency matrix?
- Easy to work with
- Adding new edges is simple and quick
- Checking for presence of edges can be done using for loops and a 2D array
What are the disadvantages of an adjacency matrix?
- A sparse graph with lots of edges but few edges causes empty space(wasted memory)
- Implementing the adjacent matrix in a 2D static arrya makes deletion / insertion difficult