Podcast
Questions and Answers
What data structure is used to represent a graph in an adjacency list format?
What data structure is used to represent a graph in an adjacency list format?
Which operation in an adjacency list representation has a time complexity that notably differs from an adjacency matrix when adding a node?
Which operation in an adjacency list representation has a time complexity that notably differs from an adjacency matrix when adding a node?
What is the primary limitation of using an adjacency matrix for a sparse graph?
What is the primary limitation of using an adjacency matrix for a sparse graph?
In a scenario where you frequently check if two nodes are adjacent, which representation would be more efficient?
In a scenario where you frequently check if two nodes are adjacent, which representation would be more efficient?
Signup and view all the answers
What advantage does an adjacency list have over an adjacency matrix when managing a dynamic graph?
What advantage does an adjacency list have over an adjacency matrix when managing a dynamic graph?
Signup and view all the answers
What is a key advantage of using a linked list over a dynamic array?
What is a key advantage of using a linked list over a dynamic array?
Signup and view all the answers
What is the purpose of the calculation start + cell_size * index in low-level arrays?
What is the purpose of the calculation start + cell_size * index in low-level arrays?
Signup and view all the answers
Which operation on a singly linked list has a time complexity of O(n)?
Which operation on a singly linked list has a time complexity of O(n)?
Signup and view all the answers
How does a doubly linked list improve efficiency compared to a singly linked list?
How does a doubly linked list improve efficiency compared to a singly linked list?
Signup and view all the answers
What does the id() function in Python return?
What does the id() function in Python return?
Signup and view all the answers
What is the purpose of using header and trailer nodes in a linked list?
What is the purpose of using header and trailer nodes in a linked list?
Signup and view all the answers
Which of the following statements about the time complexity of operations in a linked list is true?
Which of the following statements about the time complexity of operations in a linked list is true?
Signup and view all the answers
Why would the outputs of the id() function differ when the same script is run multiple times?
Why would the outputs of the id() function differ when the same script is run multiple times?
Signup and view all the answers
Which characteristic is true about low-level arrays?
Which characteristic is true about low-level arrays?
Signup and view all the answers
What happens when a dynamic array reaches its capacity according to the growth strategy of doubling?
What happens when a dynamic array reaches its capacity according to the growth strategy of doubling?
Signup and view all the answers
What is the amortized running time of each append operation in a dynamically growing array using geometric increase?
What is the amortized running time of each append operation in a dynamically growing array using geometric increase?
Signup and view all the answers
Which representation of expressions does NOT require parentheses?
Which representation of expressions does NOT require parentheses?
Signup and view all the answers
Why does performing a series of n append operations with a fixed increment take Ω(n²) time?
Why does performing a series of n append operations with a fixed increment take Ω(n²) time?
Signup and view all the answers
What will be the value of 'tmp' after the expression 'tmp = primes[3:6]' followed by 'tmp = 15'?
What will be the value of 'tmp' after the expression 'tmp = primes[3:6]' followed by 'tmp = 15'?
Signup and view all the answers
In a postfix expression, where is the operator placed in relation to its operands?
In a postfix expression, where is the operator placed in relation to its operands?
Signup and view all the answers
What is the result of the expression '*+AB+CD' in infix form?
What is the result of the expression '*+AB+CD' in infix form?
Signup and view all the answers
What capacity growth strategy is more efficient in terms of time complexity for append operations?
What capacity growth strategy is more efficient in terms of time complexity for append operations?
Signup and view all the answers
What condition must a binary tree meet to be classified as complete?
What condition must a binary tree meet to be classified as complete?
Signup and view all the answers
What is the maximum number of nodes at level 3 of a binary tree?
What is the maximum number of nodes at level 3 of a binary tree?
Signup and view all the answers
How many total nodes can a binary tree of height 2 have at most?
How many total nodes can a binary tree of height 2 have at most?
Signup and view all the answers
Which statement is true regarding balanced binary trees?
Which statement is true regarding balanced binary trees?
Signup and view all the answers
What is the definition of a full binary tree?
What is the definition of a full binary tree?
Signup and view all the answers
Which of the following statements is false regarding complete binary trees?
Which of the following statements is false regarding complete binary trees?
Signup and view all the answers
For a complete binary tree of height 0, what is the maximum number of nodes?
For a complete binary tree of height 0, what is the maximum number of nodes?
Signup and view all the answers
Which condition does NOT apply to a balanced binary tree?
Which condition does NOT apply to a balanced binary tree?
Signup and view all the answers
What is a requirement for applying topological sort on a graph?
What is a requirement for applying topological sort on a graph?
Signup and view all the answers
In topological sorting, how is the order of nodes determined?
In topological sorting, how is the order of nodes determined?
Signup and view all the answers
How many different valid topological sorts can a directed acyclic graph have?
How many different valid topological sorts can a directed acyclic graph have?
Signup and view all the answers
What does Dijkstra’s algorithm aim to find in a graph?
What does Dijkstra’s algorithm aim to find in a graph?
Signup and view all the answers
Which sorting algorithm is notably recognized for its divide and conquer approach?
Which sorting algorithm is notably recognized for its divide and conquer approach?
Signup and view all the answers
Which of the following statements about topological sort is incorrect?
Which of the following statements about topological sort is incorrect?
Signup and view all the answers
What is the main goal of a Trie data structure?
What is the main goal of a Trie data structure?
Signup and view all the answers
What common characteristic do Merge Sort and Quick Sort share?
What common characteristic do Merge Sort and Quick Sort share?
Signup and view all the answers
Study Notes
CSC2720 Final Exam Review
- Exam Schedule: Wednesday, December 11, 2024, 11:00 AM - 1:00 PM, Urban Life Building Room 100
- Exam Format: 30% of the total grade, closed book.
- Allowed Materials: One A4-size handwritten, double-sided note. Printed notes are not allowed.
- Identification: Panther ID card (or driver's license) required for identity verification.
Big O Notation of Composite Functions
- Composite Function (c.O(f(x))): A composite function is a function that is a constant multiple of another function. Its Big O notation is denoted as O(f(x)).
-
Example 1:
def print10times(arr):
...10.O(N) ~ O(N)
In this example, the function runs 10 times regardless of array size. (O(10)) The nested loop affectingO(N)
, resulting in O(N). -
Example 2:
10 + O(N) ~ O(N)
The constant 10 has a Big O notation of O(1), combined with O(N) the function will run in O(N) time.
Python Lists
- Data Structure: An ordered, mutable collection of items in Python.
-
Syntax:
sample_list = [item1, item2, ...]
- Mutability: Lists are mutable, meaning their elements can be changed after creation.
- Heterogeneity: List elements can be of different data types.
-
Built-in Methods:
append()
,insert()
,remove()
,pop()
,sort()
,sorted()
,index()
,andcount()
.
Python Lists - Time Complexity
- index[ ]: O(1)
- index assignment: O(1)
- append, pop(): O(1)
- pop(index): O(n)
- insert(index, item): O(n)
- contains, reverse: O(n)
- sort (): O(n log n)
Python Dictionaries
- Data Structure: A collection of key-value pairs, where keys are unique and values can be any type.
-
Operations:
copy
,get item
,set item
,delete item
,contains
,iteration
-
Time Complexity:
copy
: O(n),get item
: O(1),set item
: O(1),delete item
: O(1),contains
: O(1),iteration
: O(n)
Low-Level Arrays
- Representation: Python internally stores strings as an array of 16-bit (2-byte) Unicode characters.
-
Indexing: Memory address of an array element can be calculated using
start + cell_size * index
. - Constant Time Access: Arbitrary access to array elements is in constant time O(1).
Referential Arrays
- References: Python variables refer to objects in memory.
- id(): Returns the unique identifier of an object.
- Immutable vs. Mutable: Changing elements in a copy of a list will only affect the copy, not the original. Modifications to a list's elements directly affect the original list.
Amortized Analysis of Dynamic Arrays
- Growth Strategy: Arrays increase in size in increments, typically doubling the size.
- Amortized Time Complexity of Append: O(1) for operations.
-
Arithmetic Progression Issues: Fixed incrementing sizes during reallocation can result in O(n²) complexity when appending a series of elements, where
n
represents the total number of elements. This issue doesn't arise with doubling or geometric growth strategies during reallocation of dynamic arrays, where the time complexity will be O(n).
Evaluating Postfix Expressions
- Properties: The operator is placed after the operands. Left side of the operands are already present.
-
Evaluation Steps:
- Create a stack.
- Read the expression from left to right.
- If an operand is read, push it onto the stack.
- If an operator is read:
- Pop the necessary operands.
- Apply the operator.
- Push the result back onto the stack.
- The final result is the value remaining on the stack.
Stack and Queues
- Data Structures not covered in this review.
Deque
- Data Structure: A double-ended queue. Allows insertion and deletion at both ends (front and rear).
-
Common Operations:
add_rear(item)
,add_front(item)
,remove_rear()
,remove_front()
,front()
,rear()
,is_empty()
,size()
.
Linked Lists
- Memory Efficiency: No need to pre-allocate contiguous memory.
- Efficient Insertions/Deletions: O(1) time complexity because adjusting 'next' pointers is required, unlike shifting elements in an array. Can be used to implement other data structures like stacks or queues.
Doubly Linked Lists
- Each node keeps references to both the preceding and succeeding nodes.
- Improved time complexity for operations involving insertions and deletions at the beginning or end, especially compared to singly linked lists.
- Often include header and trailer nodes which are sentinel(or guard)nodes.
Hash Tables
- Implementation: Use a lookup table (array) and a hash function maps keys(item) to indices (locations/slots in an array), where the hashcode is modular with the size of the table (key%N).
- Collisions: Multiple keys might map to the same index.
- Hash Codes: Function generating an integer from an arbitrary key and used to produce the index.
- Compression Functions: Convert hash codes to valid array indices (e.g., using modular arithmetic). The division method can have limitations in some cases.
Hash Codes - Variable-Length Objects
- The summation and XOR hash codes are not suitable if the order of elements matters.
- Polynomial Hash Codes: Use different weights for elements at different positions (as given in example code) to provide better hash codes for variable-length objects.
Binary Search Tree
Binary Tree - Array-Based Implementation
- Representation: Storage with an array, where index-based calculation is used to traverse child nodes (left = 2i+1, right = 2i+2 and parent = (i-1)/2). The index must start at 0 to be effective.
- Operations: Initialization, insert, find, deletion, get, parent
Priority Queues in Python
-
Implementation: using
heapq
module.heapq
often defaults to min-heap. (heappush()
,heappop()
,heapify()
,nlargest()
,nsmallest()
) will be used for the algorithms.
K-Way Merge
- Idea (Better Solution using Heap): Instead of repeatedly finding the minimum element in O(k), use a min-heap to find the minimum element in O(logk). This approach efficiently combines and processes elements from multiple sorted input lists.
Graph Representations: Adjacency Matrix and Adjacency List
- Adjacency Matrix: Square matrix representing edges (usually boolean). Easy for checking adjacency of two nodes (O(1)); but, adds /removes nodes/edges are O(n^2).
- Adjacency List: Collection of linked lists. Fast lookups/adjacencies are O(1); but, adds/removes nodes/edges are linear for a given graph size. The time complexities to add/remove nodes/edges will be a function of the size of the graph.
Graph Traversals (BFS and DFS)
- Algorithms: Implementations covered through code examples for Breadth-First Search (BFS) and Depth-First Search (DFS) traversal, recursive and iterative for DFS.
Other Important Topics
- Topological Sorting: Ordering nodes in a directed acyclic graph to satisfy predecessors/successors. This will be illustrated/implemented in code.
- Dijkstra's Algorithm: Finding shortest paths in a weighted graph, commonly used for network routing.
- Tries: Implementing a trie data structure, including methods for insertion and retrieval where the methods are implemented in code.
- Sorting Algorithms (Merge Sort and Quick Sort): Understanding and applying the concepts, with code implementations to understand the time complexities of these sorting algorithms.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Test your knowledge on data structures, specifically focusing on graphs and linked lists. This quiz covers concepts like adjacency lists, time complexity, and differences between various representations. Delve into how these structures impact operations and efficiency in dynamic scenarios.