1.4.2: Data Structures Flashcards
What are Data Structures?
- A way of organising and storing data to perform operations upon effectively
What is an Array?
- An ordered, finite set of elements of a single type
What is a Linear Array?
- A one-dimensional Array
How can Two-Dimensional Arrays be visualised?
- Tables or Spreadsheets
What can a three-Dimensional Array be visualised as?
- A multi-page spreadsheet
What is a Record?
- A row (entry) in a file, made up of fields
- Used in databases
What is a List?
- A data structure consisting of a number of ordered items where the items can occur more than once
How do Lists differ from Arrays?
- Lists are stored non-contiguously in memory, while Arrays store data in order
- Lists can contain more than one data type, while Arrays store data of one type
What is a Linked List?
- A dynamic data structure used to hold an ordered set of items which are not stored in contiguous locations
How are Linked Lists set up?
- Each item is a node, and contains a Data Field alongside the Link, or Pointer Field
What does the Data Field hold in a Linked List?
- Contains the value of the actual data which is part of the List
What does the Pointer Field contain in a Linked List?
- The address of the next item in the List
- The index of the first item is also a pointer
- A pointer identifying the index of the next available space is also stored
How is a Linked List traversed?
- The algorithm begins at the index given by the ‘Start’ pointer and outputs the values at each node until it finds that the pointer is empty or null - Signals the end of the linked list
What is an advantage of using a Linked List?
- Values can be easily added or removed by editing pointers
How can a value be added to a Linked List?
- Add the new value to the end of the linked list and update the ‘NextFree’ Pointer
- The pointer field of the value before where the value is to be inserted is updated to point to the inserted value
- The pointer field of the value just inserted is updated to point to the next value
- When traversed, the Linked List should contain the newly inserted value
How can a value be removed?
- The pointer field of the node before the the node being removed should be updated to point to the node after
- When traversed, the Linked List will omit the node that no longer has pointer fields leading to it
What is the disadvantage of Linked Lists?
- A node is not truly removed from the List, it is only ignored, which wastes memory
- Linked Lists can only be traversed in order; an item cannot be directly accessed
What does isEmpty() do to a List?
- Checks if the List is empty
- Example: listName.isEmpty()»_space; False
What does append(value) do to a List?
- Adds a new value to the end of the List
- Example: listName.append(15)
What does remove(value) do to a List?
- Removes the value the first time it appears in the List
- Example: listName.remove(23)
What does search(value) do to a List?
- Searches for a value in the List
- Example: listName.search(38)»_space; False
What does length() do to a List?
- Returns the length of the List
- Example: listName.length()»_space; 7
What does index(value) do to a List?
- Returns the position of the item
- Example: listName.index(23)»_space; 0
What does insert(position, value) do to a List?
- Inserts a value at a given position
- Example: listName.insert(4, 25)
What does pop() do to a List?
- Returns and removes the last value in the List
- Example: listName.pop()»_space; 12
What does pop(position) do to a List?
- Returns and removes the value in the List at the given position
What is a Tuple?
- An immutable (unchangeable), ordered set of values of any type
How are Tuples initialised?
- Using regular brackets ( ) instead of square brackets
What is a Graph?
- A set of vertices/nodes connected by edges/arcs
What is a Directed Graph?
- The edges can only be traversed in one direction
What is an Undirected Graph?
- The edges can be traversed in both directions
What is a Weighted Graph?
- A cost is attached to each edge
How do Graphs differ from Linked Lists and Binary Trees?
- Each vertex is able to have more than two edges and point to any vertex in the data structure
What are the advantages of an Adjacency Matrix?
- Convenient to work with due to quicker access time
- Easy to add nodes