---
title: "MapReduce working with example"
subject: "Information System"
chapter: 8
key: "semester_8/information_system:mapreduce-working-big-data"
source: https://www.bctengineer.com/q/semester_8/information_system/mapreduce-working-big-data
site: BCT Engineering
---

# MapReduce working with example

Information System · Chapter 8: Scalable and Emerging Information System techniques

- Asked in: 2074 Magh, 8 marks
- Video: [Map Reduce explained with example | System Design](https://www.youtube.com/watch?v=cHGaQz0E7AU) — ByteMonk
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_8/information_system/mapreduce-working-big-data
- Whole chapter: https://www.bctengineer.com/md/semester_8/information_system/chapter-8

## Question

Explain the working mechanisms of Map Reduce for big data with example.

## Short answer

MapReduce divides input, applies map to produce key-value pairs, shuffles by key, then reduces to aggregate. Example word count: 'to be or not to be' -> map: (to,1),(be,1),(or,1),(not,1),(to,1),(be,1) -> reduce sum: (be,2), (not,1), (or,1), (to,2).

## Answer

**MapReduce** is a programming model and framework for processing very large datasets in parallel on a cluster of commodity machines. The user writes two functions:
- **map(key, value) -> list of (key2, value2)**
- **reduce(key2, list of values) -> result**

The framework handles splitting of data, scheduling, communication, and fault tolerance.

#### Working mechanism
1. **Input splitting:** the input file stored in a distributed file system (GFS/HDFS) is divided into blocks (for example 64/128 MB).
2. **Map phase:** each split is given to a map task running (where possible) on the node holding the data. It reads records and emits intermediate key-value pairs.
3. **Shuffle and sort:** pairs are partitioned by key, moved across the network and sorted so that all values of the same key come together.
4. **Reduce phase:** a reduce task takes each key and its list of values and combines them into a final result.
5. **Output:** results are written back to the distributed file system.
6. **Fault tolerance:** a master (job tracker) monitors workers; if a worker fails, its task is re-run on another node.

```text
 Input -> Split1 -> Map -+
          Split2 -> Map -+-> Shuffle/Sort -> Reduce -> Out1
          Split3 -> Map -+                  Reduce -> Out2
```

#### Example: word count
Input: "to be or not to be"
- **Map output:** (to,1) (be,1) (or,1) (not,1) (to,1) (be,1)
- **Shuffle/sort:** be -> [1,1]; not -> [1]; or -> [1]; to -> [1,1]
- **Reduce (sum):** (be,2) (not,1) (or,1) (to,2)

```text
map(String line):
   for each word w in line: emit(w, 1)
reduce(String w, List counts):
   emit(w, sum(counts))
```

#### Advantages
Scales to thousands of machines, hides parallel programming complexity, tolerates failures and moves computation to data.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Which two functions does the programmer write in MapReduce?
   A. split() and merge()
   B. map() and reduce()
   C. shuffle() and sort()
   D. read() and write()
   Answer: B. The user writes map and reduce; the framework handles splitting, scheduling, communication and fault tolerance. (Key point: User-written functions)

2. What does the shuffle and sort step achieve?
   A. Deletes duplicate keys
   B. Brings all values of the same key together for one reduce task
   C. Splits the input into blocks
   D. Writes the final output to disk
   Answer: B. Pairs are partitioned by key, moved across the network and sorted so each key's values are grouped. (Key point: Shuffle and sort)

3. Why is a map task scheduled on the node holding its input split where possible?
   A. To reduce network traffic by moving computation to the data
   B. Because maps cannot read remote files
   C. To make the reduce phase unnecessary
   D. To increase replication
   Answer: A. Moving computation to data saves network bandwidth, one of MapReduce's advantages. (Key point: Data locality)

4. For the input 'to be or not to be', what does the reduce phase output?
   A. (be,2) (not,1) (or,1) (to,2)
   B. (be,1) (not,1) (or,1) (to,1)
   C. (be,2) (not,2) (or,2) (to,2)
   D. (to,6)
   Answer: A. Map emits (word,1); after shuffle be->[1,1], to->[1,1], others [1]; reduce sums them. (Key point: Word count result)

5. What happens if a worker fails during a job?
   A. The whole job is lost
   B. The master re-runs its task on another node
   C. The output is written with errors
   D. The user must resubmit the data
   Answer: B. The master (job tracker) monitors workers and re-executes failed tasks on other nodes. (Key point: Fault tolerance)

## Related in Information System

- [Big data and its processing](https://www.bctengineer.com/question.md?key=semester_8%2Finformation_system%3Abig-data-processing) — Information System, chapter 8
- [MapReduce vs Hadoop; IR process](https://www.bctengineer.com/question.md?key=semester_8%2Finformation_system%3Amapreduce-vs-hadoop-ir) — Information System, chapter 8
- [MapReduce with GFS and HDFS](https://www.bctengineer.com/question.md?key=semester_8%2Finformation_system%3Amapreduce-gfs-hdfs) — Information System, chapter 8

## Related in other subjects

- [MapReduce data flow technique](https://www.bctengineer.com/question.md?key=semester_8%2Fbig_data_technologies%3Amapreduce-data-flow) — Big Data Technologies, chapter 3
- [Optimization and data locality in MapReduce](https://www.bctengineer.com/question.md?key=semester_8%2Fbig_data_technologies%3Amapreduce-optimization-data-locality) — Big Data Technologies, chapter 3
- [MapReduce worker failure tolerance](https://www.bctengineer.com/question.md?key=semester_8%2Fbig_data_technologies%3Amapreduce-fault-tolerance) — Big Data Technologies, chapter 3
- [Breakdown mechanisms in solids under working conditions](https://www.bctengineer.com/question.md?key=semester_8%2Fhigh_voltage_engineering%3Asolid-breakdown-actual-conditions) — High Voltage Engineering, chapter 6
