WASHINGTON — The comparisons are perhaps inevitable. President Barack Obama and former South African leader Nelson Mandela each served as their nation's first black president, living symbols of struggles to overcome deep-seated racial tensions. Each was awarded the Nobel Peace Prize.

But as Obama prepares to honor Mandela at a memorial service Tuesday in South Africa, people close to the U.S. president say he is well-aware that his rapid rise through America's political ranks pales in comparison to Mandela's 27 years in prison fighting against a repressive government that brutally enforced laws that enshrined racial discrimination.

Rather than view himself as a counterpart to Mandela, Obama has said he sees himself as one of the countless millions who drew inspiration from Mandela's life.

"Like so many around the globe, I cannot fully imagine my own life without the example that Nelson Mandela set, and so long as I live, I will do what I can to learn from him," Obama said in somber remarks after Mandela died last week at the age of 95.

In the days following Mandela's death, Obama began crafting the 20-minute speech he will deliver during Tuesday's service in Johannesburg, where tens of thousands of South Africans and dozens of foreign dignitaries are expected to pack a sports stadium. Obama is expected to speak of Mandela's influence on South Africa and on his own life, while also reflecting on the complexity of Mandela's rise from anti-apartheid fighter and prisoner to president and global icon.

The memorial service will also serve as a rare reunion of nearly all living American presidents. Former President George W. Bush and wife Laura Bush joined the president and wife Michelle Obama on Air Force One as it departed Washington Monday morning. Former Presidents Bill Clinton and Jimmy Carter were traveling to South Africa separately. George H.W. Bush, the only other living U.S. president, will not attend because the 89-year-old is no longer able to travel long distances, his spokesman Jim McGrath said.

Also traveling with Obama were national security adviser Susan Rice, Attorney General Eric Holder, and former Secretary of State Hillary Clinton, who was meeting her husband in South Africa.

For Obama, who was too young to be active in the American civil rights movement, it was Mandela's struggle against apartheid that first drew him into politics. He studied Mandela's speeches and writings while studying at Occidental College from 1979-81 and became active in campus protests against the apartheid government.

"My very first political action, the first thing I ever did that involved an issue or a policy or politics, was a protest against apartheid," Obama said last week. "The day that (Mandela) was released from prison gave me a sense of what human beings can do when they're guided by their hopes and not by their fears."

By the time Obama became president, Mandela had retired from public life. But they did have one in-person meeting, a hastily arranged 2005 encounter while Mandela was visiting Washington. The South African leader had been encouraged to meet a young black U.S. senator who was a rising star in American politics and invited Obama to visit him at his hotel.

A single photo from the meeting shows the two men smiling and shaking hands, with Obama standing and Mandela sitting, his legs stretched out in front of him. The photo hangs in Obama's personal office at the White House, as well as in Mandela's office in Johannesburg.

Obama and Mandela had sporadic contact after that meeting, including a congratulatory phone call from Mandela after Obama's 2008 election and a condolences call from the U.S. president after the South African's granddaughter was killed in a 2010 car accident.

In 2011, Mrs. Obama and her two daughters held a private meeting with Mandela during a visit to South Africa. But the elderly leader was hospitalized and too sick to meet with Obama when he traveled there earlier this year.

Mandela's ailing health cast a shadow over that trip, heightening the emotion when Obama and his family visited the Robben Island prison where Mandela spent 18 of his 27 years in prison. Obama also met with members of Mandela's family during his July visit and the White House said he hopes to spend time with them again on Tuesday.

Follow Julie Pace on Twitter: http://twitter.com/jpaceDC