Customers queue up to purchase Apple's new iPhone 5 smartphone outside an Apple store, before its opening, on September 21, 2012 in Paris. We've all spent endless hours waiting in lines. What's the science behind it and how has the process changed? - 

Sales, holiday shopping, rush hour traffic -- we've all spent countless hours of our lives stuck in lines. But there's actually a science behind lining up -- part physics, part psychology.

Dick Larson, director of the Center for Engineering Systems Fundamentals at Massachusetts Institute of Technology, says queueing theory has its roots in a Danish engineer named A.K. Erlang. He developed the science when trying to figure out the maximum profit a telephone company could make.

About 50 years ago, the psychology of queueing was born. How has the process of waiting for a product or service changed in the last few decades?

"I'm old enough to remember -- when I had to get cash, I had to go to bankers' hours 10-3 and go up to a human teller, choose one of several lines, and cash a check," says Larson. "Now ATMs are ubiquitous, but the trick is the server becomes yourself. So the human server has gone away and you've replaced the human server and it's facilitated by human technology."

Larson says there's a long-standing axiom in the services industries: customer satisfaction is equal to the difference between expectation and actually delivery. In other words, if a business can manage customers' expectations to be at one level, but deliver at a higher level, customers are happy.

Larson calls Disney the "Machiavellian experts in waiting in lines," saying the company helped develop the psychology of queueing when they opened up Disneyland in Anaheim. Today, they have signs that let patrons know how long they have to wait before they can get on the ride.

"They deliberately overestimate that," says Larson, and then customers feel like they luck out if they get on sooner than expected.

For consumers looking to avoid lines where possible, Larson suggests staying away from rush hours like lunch and dinner times. Single-serpentine lines are also a better bet than multiple-line systems: just think about how frustrating it is at the grocery store or in airport security when you feel like you've chosen the wrong line, and everyone else is passing you by.

Follow Tess Vigeland at @tessvigeland