Two nodes of a binary search tree have been incorrectly swapped. How will you efficiently restore the tree to its correct state?

2

An inorder traversal of BST will be in sorted order.

In the incorrect BST  2 of the nodes are swapped .
use this to your advantage and find these 2 elements in inorder traversal which violate the sorted order.This 2 elements need to  be swapped.Thats it!!

Just modify inorder traversal function as follows
[gist https://gist.github.com/vishnujayvel/5879942 ]