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.