According to G.L. Cohen, author of Studies in Slang Part 1 (1985), the phrase smart alec(k) arose from the exploits of one Alec Hoag. A celebrated pimp, thief, and confidence man operating out of New York City in the 1840's, Mr. Hoag, along with his wife Melinda and an accomplice known as "French Jack," operated a con called the "panel game," a method by which prostitutes and their pimps robbed foolish customers.
The "panel game" consisted of sliding walls that would enable Mr. Hoag to sneak in whilst the mark was sleeping and steal valuables. Before Mr. Hoag, a prostitute's accomplices would wait until the mark was asleep, then burst into the room. But the marks got wise and would block the door with a table or chair propped up under the doorknob, thinking they would then be safe from intruders. "Smart" Alec Hoag, because he never woke the victim, would be on the other side of town before the rube even knew what had happened.
link