- 2073 Magh · 10 marks
MapReduce max marks per college
Short answer
Map input: (byte offest, 'Ram,ABC,70') etc. for all eight rows. Mapper outputs (college, marks) pairs. Reducer input: (ABC,[70,80,60]), (PQR,[90,70,60]), (XYZ,[90,80]). Final output maximum marks: ABC 80%, PQR 90%, XYZ 90%.
For following data, list the input to/output from both the map and reduce functions for getting maximum marks of each college.
| Student Name | College Name | Final Marks in % |
|---|---|---|
| Ram | ABC | 70 |
| Sita | ABC | 80 |
| Hari | ABC | 60 |
| Gita | XYZ | 90 |
| Rita | XYZ | 80 |
| Shyam | PQR | 90 |
| Laxmi | PQR | 70 |
| Gopal | PQR | 60 |
We use one MapReduce job. The mapper emits (college, marks) for each record. The framework groups values by key (shuffle and sort). The reducer takes the maximum of the list of marks for each college.
Mapper and reducer pseudocode
map(key = byte offset, value = "Name,College,Marks"):
fields = split(value, ",")
emit(trim(fields[1]), int(trim(fields[2]))) // (college, marks)
reduce(key = college, values = list of marks):
max = 0
for v in values:
if v > max: max = v
emit(college, max)
Input to the map function
Each row is one (key, value) pair. The key is the byte offset of the line (not used), the value is the line.
| Key (offset) | Value |
|---|---|
| 0 | Ram, ABC, 70 |
| 1 | Sita, ABC, 80 |
| 2 | Hari, ABC, 60 |
| 3 | Gita, XYZ, 90 |
| 4 | Rita, XYZ, 80 |
| 5 | Shyam, PQR, 90 |
| 6 | Laxmi, PQR, 70 |
| 7 | Gopal, PQR, 60 |
(Offsets are shown as line numbers for simplicity.)
Output of the map function (input to shuffle)
(ABC, 70) (ABC, 80) (ABC, 60)
(XYZ, 90) (XYZ, 80)
(PQR, 90) (PQR, 70) (PQR, 60)
After shuffle and sort (input to the reduce function)
The framework groups all values of the same key and sorts keys:
| Key | List of values |
|---|---|
| ABC | [70, 80, 60] |
| PQR | [90, 70, 60] |
| XYZ | [90, 80] |
Output of the reduce function (final output)
| College | Maximum marks |
|---|---|
| ABC | 80 |
| PQR | 90 |
| XYZ | 90 |
Data flow
Input lines -> MAP -> (college,marks)
-> SHUFFLE/SORT -> (college,[marks])
-> REDUCE -> (college,max)
Since max is associative and commutative, the same reducer can also be used as a combiner, to reduce network traffic by sending only the local maximum from each mapper.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- MapReduce data flow technique · Big Data Technologies, chapter 3
- Optimization and data locality in MapReduce · Big Data Technologies, chapter 3
- Max and min word occurrence with MapReduce · Big Data Technologies, chapter 3
- MapReduce worker failure tolerance · Big Data Technologies, chapter 3
- MapReduce workflow with example · Big Data Technologies, chapter 3 · asked 2×
- Combiner function in MapReduce · Big Data Technologies, chapter 3
- AMC, RAM and interval: FC 80%, PWP 35% · Irrigation and Drainage Engineering, chapter 2 · asked 2×
- Student records with two functions · Computer Programming, chapter 8
- Maximum peak input for undistorted output · Advanced Electronics, chapter 2
- Principal stresses, max shear: 80, 60, 20 MPa · Strength of Materials, chapter 4