# Map Recude

## What is it?

A programming paradigm that allows processing large quantities of information with parallelism.

It is divided into two stages:

1. &#x20;"**MAP**" is responsible for soliciting/ordering/processing information independently/isolated. The result is a set of ordered _key-value_ pares.
2. "**Reduce**" is responsible for combining/grouping the information from the previous stage into a very reduced set of data (at most one).

## Algorithm

<figure><img src="https://2387753953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9sVneYw7epWOEEPKsfCf%2Fuploads%2Fa8hN58Utp51uMwNMOLTR%2FScreenshot%20from%202023-06-17%2019-02-01.png?alt=media&#x26;token=672bcd0d-43b0-4270-a720-7bf507f15d74" alt=""><figcaption></figcaption></figure>

Chunks of information are processed by _Mappers_ in an isolated and because of that, these can be distributed in and network.

The result of the _Mapper's_ work is an intermediate sub-product that is supplied to the _Reducers_ in a process denominated _shuffling process_.

The result of the _Reducers_ is the final result.

### Example

Histogram of word in _Lusiadas_.

* Begin by creating chunks - to simplify, each verse is a chunk.
* **Map** - for each verse, a _key-value_ pair list with each word and the number of times it appears, is created.
* **Reduce** - the previous result will be summed and aggregated.
* In the end, the histogram is the result.

<figure><img src="https://2387753953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9sVneYw7epWOEEPKsfCf%2Fuploads%2FLf9KfVd6goFCeOjR0F2Z%2FScreenshot%20from%202023-06-17%2022-26-29.png?alt=media&#x26;token=0e0a2f72-95bf-4d10-a44b-64ab5176e223" alt=""><figcaption></figcaption></figure>

## Advantages

### Parallel processing

Each task is completely independent, we divide the problem to simplify it.

### Information placement

The data is not centralized, but distributed by all the computation nodes.

Instead of transmitting data between nodes, the **Map** and **Reduce** are the ones that migrate to the location of the data.
