This one is a classic : reverse a string, and reverse the word of the strings, in place, and in linear time.
Cost comparison is caracter exchange. The heart of the algorithm is the reverseWord function, which reverses a word.
The first passe uses N/2 characters exchange, where N is the number of character
The second passe uses W*(w/2) characters exchange, where w is the average length of a word, and W the number of word. This falls back around N/2
Overall Cost is N exchange
Modified http://d3js.org/d3.v2.min.js?2.10.1 to a secure url
https://d3js.org/d3.v2.min.js?2.10.1