LabExamAnswers Flashcards

(35 cards)

1
Q

What is the difference between text files and binary files in C?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the role of the Header record in the file-based linked list implementation?

A

The Header record stores metadata, specifically the indices of the list head (listHead) and the head of the avail list (availHead).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How does the avail list help in managing deleted nodes?

A

The avail list keeps indices of deleted nodes for reuse, minimizing file size growth.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Write the C structure definition for Header.

A

typedef struct { int listHead; int availHead; } Header;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Write the C structure definition for Node.

A

typedef struct { int data; int next; } Node;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the final linked list representation after inserting 10, 5, and 7?

A

[2] 5 → [3] 7 → [1] 10 → NULL

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the process for deleting a value from the file-based linked list?

A

Traverse to find the value, update previous node’s next index, set deleted node’s next to availHead, and update availHead.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the purpose of the getFreeIndex() function?

A

It determines the index for inserting a new node, either from the avail list or at the file end.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why are file indices used instead of pointers in file-based data structures?

A

Indices are persistent and can reference positions in the file across executions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What problems can arise if the binary file storing the linked list gets corrupted?

A

Invalid indices, broken list structure, infinite loops, inability to traverse/modify the list, and possible data loss.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Define hashing.

A

Hashing is a technique to map keys to indices in a table using a hash function for efficient data retrieval.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the properties of a good hash function?

A
  • Uniformly distributes keys
  • Minimizes collisions
  • Is deterministic
  • Is efficient to compute.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Describe the Mid-Square Method for hashing with a table size of 10.

A

Square the key, extract middle digits, and take mod table size.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a collision in hashing?

A

A collision occurs when two different keys hash to the same index.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Explain rehashing.

A

Rehashing means creating a bigger table and reinserting all elements when the current table is too full.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Compare chaining and bucket hashing.

A

Chaining links collided elements in a linked list at each index; bucket hashing uses fixed-size arrays.

17
Q

What is the cycle property of MSTs?

A

The highest weight edge in any cycle cannot be in the MST.

18
Q

What is the cut property of MSTs?

A

The smallest weight edge crossing any cut must be in the MST.

19
Q

What data structures are used in Prim’s algorithm?

A
  • Arrays: key[] (min edge weights)
  • mstSet[] (included in MST)
  • parent[] (MST tree structure).
20
Q

What is the purpose of the find() function in Kruskal’s algorithm?

A

It identifies the set a vertex belongs to for cycle detection.

21
Q

What is the output of BFS traversal for a graph starting from vertex 0?

22
Q

What is the time complexity of BFS and DFS for adjacency list?

23
Q

In a file-based linked list, the avail list is used to keep track of ______.

A

deleted nodes’ indices for reuse.

24
Q

What is the output of BFS traversal for the given adjacency list graph, starting from vertex 0?

25
What is the output of BFS traversal for the given adjacency list graph, starting from vertex 0?
0 1 2 3 4 ## Footnote The BFS traversal visits vertices in layers, starting from the specified vertex.
26
What method is used to keep track of deleted nodes' indices for reuse in a file-based linked list?
avail list ## Footnote The avail list helps in efficient memory management for linked lists.
27
How is the hash function for the division method usually expressed?
h(key) = key mod tablesize ## Footnote This formula calculates the index for storing the key in a hash table.
28
In Kruskal’s algorithm, how are edges processed?
in the order of increasing weight ## Footnote This ensures that the minimum spanning tree is built with the least weight edges first.
29
What is the primary data structure used for traversal in BFS?
queue ## Footnote The queue allows for the first-in, first-out processing of vertices.
30
What is the space complexity of an adjacency matrix for a graph with V vertices?
O(V^2) ## Footnote The matrix requires space proportional to the square of the number of vertices.
31
True or False: In a binary file, the data is stored in a human-readable format.
False ## Footnote Binary files store data in a format that is not directly readable by humans.
32
True or False: A good hash function should always produce unique outputs for different inputs.
False ## Footnote Hash functions can produce collisions, where different inputs yield the same output.
33
True or False: The avail list in a file-based linked list helps reduce disk space usage.
True ## Footnote By tracking deleted nodes, the avail list allows for memory reuse.
34
True or False: Prim’s algorithm can only be applied to directed graphs.
False ## Footnote Prim's algorithm is designed for undirected graphs.
35
True or False: DFS can be implemented both recursively and iteratively.
True ## Footnote Both methods are valid for depth-first search implementation.