PROFESSIONAL-CLOUD-DEVELOPER · Question #71
You are parsing a log file that contains three columns: a timestamp, an account number (a string), and a transaction amount (a number). You want to calculate the sum of all transaction amounts for…
The correct answer is B. A hash table. A hash table (also called a dictionary or map) is the optimal data structure for this problem. You use each unique account number as a key and accumulate the transaction total as the value. Lookups and inserts are O(1) on average, so processing the entire log file is O(n). A…
Question
You are parsing a log file that contains three columns: a timestamp, an account number (a string), and a transaction amount (a number). You want to calculate the sum of all transaction amounts for each unique account number efficiently. Which data structure should you use?
Options
- AA linked list
- BA hash table
- CA two-dimensional array
- DA comma-delimited string
How the community answered
(60 responses)- A5% (3)
- B90% (54)
- C3% (2)
- D2% (1)
Explanation
A hash table (also called a dictionary or map) is the optimal data structure for this problem. You use each unique account number as a key and accumulate the transaction total as the value. Lookups and inserts are O(1) on average, so processing the entire log file is O(n). A linked list (A) requires O(n) traversal per lookup, making aggregation O(n²). A two-dimensional array (C) requires knowing all account numbers in advance and doesn't support efficient key-based lookup. A comma-delimited string (D) has no indexing capability at all.
Topics
Community Discussion
No community discussion yet for this question.