The grueling and emotional task of arranging the names at the 9/11 memorial has finally been completed — after years of debate and over 1,200 special placement requests — with many being honored next to people they either worked with, died alongside or loved.

Accomodating the wishes of the relatives, as well as reps for fallen first responders, was so complex that the memorial created a special computer algorithm to figure out where to place people.

“It was extremely difficult,” said 9/11 Memorial President Joe Daniels of the project to relocate names.

They eventually settled on a plan that included nine separate groups, including one for first responders.

Employees of the same company — like Cantor Fitzgerald — were also positioned together.

Those on the hijacked airplanes are placed near each other, for the most part.

But the placement process got difficult because many relatives had special requests to put individuals — like siblings or people from separate companies who were known to have died together — next to one another.

In many cases, those special requests threw a wrench in the existing plan, which was why they developed the algorithm.

As an example of one request that they accommodated, the family of two brothers who were killed — Firefighter Peter Langone and police officer Thomas Langone — wanted the siblings’ names next to each other.

To accommodate that request, they had to make sure that the end of Peter Langone’s unit met the beginning of the NYPD section.

In another instance, Donald James McIntyre, a Port Authority cop, died in the south tower.

On that day, he told his wife that he was headed to the 84th Floor to see his cousin, John Anthony Sherry, a trader with Euro Brokers.

It was the last time she spoke to him.

To make sure their names were listed side by side, the 9/11 Memorial made sure the end of the first responders’ section had McIntyre’s name last, while Sherry’s is the first name in the next section, which starts the workers of his company.

The initial plan — favored by the memorial designer and Mayor Bloomberg — called for the names to be randomly assigned throughout the memorial, which honors victims of the 2001 and 1993 World Trade Center attacks.

But victims’ groups and reps for first responders balked at the haphazard nature, and reps for the NYPD and FDNY were adamant that first responders be grouped together and separate from civilian victims.

Edith Lutnick — whose brother died in the terror attack — was one of many family members who were critical of the initial plans for locating names at the memorial.

She said she’s happy that they worked hard to place people near loved ones, but is still upset that the bronze parapets that have the victims’ names will not have other identifying details, like age or the company they worked for.

“I am grateful that the Memorial Museum did work very hard with us,” she said.

“We made sure that they [the victims names] are surrounded by people that they worked with and had relationships with and were important to them.”