1.4.2 Data Structures Flashcards
What is an array?
- Can be like a variable that can contain more than 1 item.
- It is also a collection of elements of the same data type grouped under a single identifier.
- Done by allocating contiguous (all the data stored together one after another)
- They are static
Name an example of a 1 and 2 dimensional array
- 1D = Names = [“Sam”, “Lucy”, “James”, “Jack”]
- 2D = Names = [[“Sam”, “Lucy”, “James”], [“Peter”, “Sarah”, “Adam”]]
What is a record?
- A record is a collection of related fields
- A record is a data structure that allows items of data of different types to be stored.
- This is useful when creating a set of related data items.
What is field?
- A field is a variable, and each field in a record can have a different data type.
What are the steps of making a record structure
- Step 1 : Define the record structure - what fields will be in the record
- Step 2 : Declare a variable or array to use with record structure
- Step 3: Assign and retrieve data from the variable record
What is a Tuple
- Immutable (data it contains can’t be edited once assigned at runtime)
- Can contain data of different data types.
- student = (“James”, “Smith”, “30/01 / 2000”)
What is a data structure and name a few
- Is simply a way of representing the data held in a computer’s memory
- 1 2 or 3 dimensional arrays, records, tuples, lists, stacks, queues, linked lists, binary trees, directed/undirected graphs, hash tables
What does a static data structure mean and name an example
- Size is fixed when structure created / size cannot change during processing
- Array
What is a dynamic data structure and name a disadvantage?
- Size can change during processing
- Don’t have a limited size however tend to be more complex to implement and can use a lot of memory.
- Storage required is unknown initially / more difficult to program
What is a list?
- Lists is a simple data structure similar to an array. However like a tuple it can hold a range of data types
What are the similarities and differences between an array, list or tuple
- Lists: Mutable - data it contains can be changed at runtime, Array: Mutable, Tuple: Immutable - can’t be changed
- Lists and Arrays: Ordered items, Tuple: Unordered
- Lists and Arrays: Items can be changed/replaced. Tuples: No
- Lists and Tuples: Store more than 1 data type, Arrays: Store only 1 data type.
What are the similarities between constants and tuples
- Both are features of high-level programming languages
- Both have data defined at design time and can’t be changed at run time (immutable)
- Can both make program execution faster because a compiler can optimise code for immediate addressing
What are the differences between constants and tuples
- A constant can only hold 1 value of 1 data type.
- A tuple is an unordered set of multiple values of different data types.
What are the similarities between record structures and classes
- Are both features of high-level procedural languages.
- Record structures and class attributes can hold multiple data types (variables/ attributes) within 1 identifier
What are the differences between record structures and classes
- Record structures are usually associated with procedural languages.
- Classes are a feature of object-oriented techniques.
- Class attributes can be encapsulated and classes can have methods.
- Classes can have inheritance to apply methods and attributes to sub classes.
What is a doubly linked list?
- By adding an extra pointer, nodes can point to the next and previous items
What is a circular list?
- Can be created by making the last node point to the first node
What is a doubly circular linked list?
- Each node in a circular linked list can also have an additional pointer pointing to the previous item.
What can be used to implement a linked list?
- Using a static array
- Or object-oriented techniques
- Any available memory address can be used to store data doesn’t need to be adjacent. Nodes point to the next node.
- The memory footprint of data structure isnt determined at compile time and can eb changed at runtime.
What are the applications of a linked list
- Operating systems, managing processor to store process blocks in ready state.
- Image viewers to switch between previous/next images.
- Music players to store tracks.
- Web browsers to navigate back/forth.
- Hash table collision - overflow
- Maintaining a file allocation table of linked clusters on secondary storage.
What operations can be performed on a linked list?
- Add: Add a node to a linked list
- Delete: Remove a node from a linked list
- Next: Moves to the next item in the list
- Previous: Moves to the previous item in the list.
- Traverse: A linear search through the linked list
State an explain an advantage and a disadvantage of the linked list data structure?
- Advantage: Dynamic data structure - a linked list can grow/shrink at run time as items aren’t held contiguously in memory.
- Disadvantage: Can be slow to search - doesn’t allow random access to the elements. Searching - requires starting at the beginning and following every pointer until item is reached.
Describe what is meant by the term “Linked list”
- A dynamic data structure
- Each node/item consists of data and a pointer
- Pointer gives location of the next node
Describe the difference between an array and a linked list?
- A linked list is a dynamic data structure whereas an array is static.
- An array can have any element accessed directly whereas a linked list needs to be traversed from start.
- Contents of an array are stored contiguously in memory whereas linked list may not be.
What is a graph and how does it differ from a linked list and binary tree?
- Data structure consisting of vertices (nodes) and edges (pointers)
- It differs from a linked list and binary tree because each vertex can have more than 2 edges and point to any vertex in the data structure.
The edges in a graph can either:
- Point in 1 direction (directed graph)
- Not specify a direction (undirected graph)
- They can also be weighted with each edge given a value (can represent distance/time) representing a relationship between vertices.
How are graphs usually stored as
- Store graphs as objects or using a dictionary known as adjacency lists
- Can store using an array with rows and columns representing vertices and edges.
What are the applications of a graph?
- Mapping road networks for navigation systems.
- Storing social network data.
- Resource allocation in Operating systems.
- Representing molecular structures in geometry.
What are some of the standard operations that can be performed on a graph?
- Adjacent: Returns whether there is an edge between 2 vertices.
- Neighbours: Returns all vertices between 2 vertices.
- Add: Adds a new vertex to the graph.
- Remove: Removes a vertex from a graph.
- Get Vertex Value/Set Vertex Value.
What are the search operations that can be performed on a graph?
- Depth-First Search - Starts at the root vertex, visits each vertex and explores each branch before backtracking.
- Breadth-First Search - Starts at the root vertex and visits each neighbouring node before moving to the vertices at the next depth.
What are the Traversal operations that can be performed on a graph?
- Pre-Order Traversal
- In-Order Traversal
- Post-Order Traversal
What is a stack?
.
- Items are pushed onto the top of the stack when they are added to it and popped off the top when they are deleted.
- Known as Last-In-First-Out Structure.
- A stack has a pointer that always points to the node at the top.
What is pushing an item to a full stack called and what is pooping an item from an empty stack called?
- Pushing an item onto a full stack is called stack overflow
- Popping an item off an empty stack is called stack underflow.
How can a stack be implemented?
- Often using an array or object-oriented technique.
What are the applications of a stack?
- Used by processors to track the flow of programs.
- When a procedure or function is called, it changes the value of the program counter to the first instruction of the subroutine
- When the subroutine ends, the processor must return to the previous value. Allows subroutine calls to be nested.
- Performing depth-first searches
- Keeping track of undo operations
- Backtracking algorithms
- Evaluating mathematical expressions without brackets.
What operations can be performed on a stack?
- Push - Adding an item to the top of the stack
- Pop - Removing an item from the top of the stack
- Peek - Returning the value from the top of the stack without removing it
What is a queue?
- It is a linear data structure
- Items are enqueued at the back and dequeued from the front. Can peek at front items without removing it
- Known as First-In-First-Out structure
- A queue has a back pointer that points to the last item and a front pointer that points to the first item.
What is it called when you enqueue an item to a full queue and dequeue an item from an empty queue called?
- An attempt to enqueue an item in a full queue is called queue overflow
- An attempt to dequeue an item from an empty queue is called a queue overflow.