I once saw two video clips, back-to-back. They were both from a video called "Banned in the USA". Very chilling stuff.
The first was from a South American town, where a man had been caught after molesting a young girl. The townspeople beat him nearly to death (I thought he was dead), then dragged him to the edge of town where they tied him to a tree. Once on the tree, they poured gasoline on him. It was at this point that I realized, he's still alive. Squirming as he burned, someone approached him and shot him several times.
Beaten, burned alive, and shot. If that isn't a deterrent for child molesters - I don't know what is.
The second was similar. Two men caught after raping and killing a young girl in a middle eastern country. The military had the men in custody and took them to the town square where they were allowed to pray. Each man was tied to a post and blindfolded. Family members of the young girl were given fully automatic rifles, and they did what they wanted to the two men.
Public, brutal punishments act as a deterrent to those who consider these types of crimes.