# Search for an efficient data structure and / or algorithm

I'm tasked with an animated chart based on a timeline, and I'm struggling to find a suitable data structure and / or algorithm that are reasonably efficient. I have a working system that suffers from performance issues the larger my dataset gets.

Let's say I have a bunch of people in an array

``````[Bob, Jane, Kevin, Alice, Bob, Alice, Jane, Bob, Fred]
``````

My final result will be a series of columns equal to the number of people x Number of times in the array.

``````Bob - 3 times
Jane, Alice - 2 times
Kevin, Fred - 1 time
``````

That would translate into my graphic after

``````Column 1 - 2 persons appearing once
Column 2 - 2 persons appearing twice
Column 3 - 1 person appearing 3 times
``````

Normally, this data structure is unique and very fast. However, I was instructed to create this as a timeline of the people in the array in the order of the array.

Bob is the first person in the array. So we take it off and apply it to our graph. He for now is the only person involved. After we edit it, so are our columns

``````Column 1 - 1 person appearing 1 time
Column 2 - 0 persons appearing twice
Column 3 - 0 persons appearing 3 times
``````

Next we add Jane, Kevin, and Alice, so we have:

``````Column 1 - 4 people displayed 1 time
Column 2 - 0 persons appearing twice
Column 3 - 0 persons appearing 3 times
``````

Now we add Bob again and our diagram changes. Bob no longer considers the first column.

``````Column 1 - 3 persons appearing once (Jane, Alice and Kevin)
Column 2 - 1 person appearing twice (Bob)
Column 3 - 0 persons appearing 3 times
``````

This will take until the end of the array. Performance is slowing down when there are more than a few hundred data points.

I also need to know the final state of the graph to calculate the size.

Can someone with a structure / algorithm help save / manage the data to keep performance linear?