LabExamAnswers Flashcards
(35 cards)
What is the difference between text files and binary files in C?
Text files store data in human-readable ASCII characters (e.g., .txt, .csv). Binary files store data in raw binary format (e.g., .dat, .bin) and are not human-readable.
What is the role of the Header record in the file-based linked list implementation?
The Header record stores metadata, specifically the indices of the list head (listHead) and the head of the avail list (availHead).
How does the avail list help in managing deleted nodes?
The avail list keeps indices of deleted nodes for reuse, minimizing file size growth.
Write the C structure definition for Header.
typedef struct { int listHead; int availHead; } Header;
Write the C structure definition for Node.
typedef struct { int data; int next; } Node;
What is the final linked list representation after inserting 10, 5, and 7?
[2] 5 → [3] 7 → [1] 10 → NULL
What is the process for deleting a value from the file-based linked list?
Traverse to find the value, update previous node’s next index, set deleted node’s next to availHead, and update availHead.
What is the purpose of the getFreeIndex() function?
It determines the index for inserting a new node, either from the avail list or at the file end.
Why are file indices used instead of pointers in file-based data structures?
Indices are persistent and can reference positions in the file across executions.
What problems can arise if the binary file storing the linked list gets corrupted?
Invalid indices, broken list structure, infinite loops, inability to traverse/modify the list, and possible data loss.
Define hashing.
Hashing is a technique to map keys to indices in a table using a hash function for efficient data retrieval.
What are the properties of a good hash function?
- Uniformly distributes keys
- Minimizes collisions
- Is deterministic
- Is efficient to compute.
Describe the Mid-Square Method for hashing with a table size of 10.
Square the key, extract middle digits, and take mod table size.
What is a collision in hashing?
A collision occurs when two different keys hash to the same index.
Explain rehashing.
Rehashing means creating a bigger table and reinserting all elements when the current table is too full.
Compare chaining and bucket hashing.
Chaining links collided elements in a linked list at each index; bucket hashing uses fixed-size arrays.
What is the cycle property of MSTs?
The highest weight edge in any cycle cannot be in the MST.
What is the cut property of MSTs?
The smallest weight edge crossing any cut must be in the MST.
What data structures are used in Prim’s algorithm?
- Arrays: key[] (min edge weights)
- mstSet[] (included in MST)
- parent[] (MST tree structure).
What is the purpose of the find() function in Kruskal’s algorithm?
It identifies the set a vertex belongs to for cycle detection.
What is the output of BFS traversal for a graph starting from vertex 0?
0 1 2 3 4
What is the time complexity of BFS and DFS for adjacency list?
O(V + E)
In a file-based linked list, the avail list is used to keep track of ______.
deleted nodes’ indices for reuse.
What is the output of BFS traversal for the given adjacency list graph, starting from vertex 0?
0 1 2 3 4