Trivial Question, INORDER tree traversal : Left->Root->Right
Trivial inorder tree traversal question\'s application \n\nINORDER traversal of binary search tree results in sorted elements with increasing value\n\ntraverse 
**Trivial inorder tree traversal question\'s application** \n\n**INORDER traversal of binary search tree results in sorted elements with increasing value**\n```\ntraverse recursively : left > root > rigth and keep on counting, if you have reached nth smallest node,\n( ie nth node in its INORDER traversal then return that node\'s value )\n```\n\n**Optimization** : early stopping , ( no need to traverse whole tree, return at the spot when you hits nth value in inorder traversal ).\n```\nint n, ans;\n    void traverse(TreeNode *root)\n    {\n        if(!root)   return;\n        \n        if(root->left)                         // traverse left\n            traverse(root->left);\n        \n        if(--n==0)                                   // if count becomes zero , means we have reached nth node in INORDER traversal\n            { \n\t\t\t    ans = root->val;   // store answer\n\t\t\t\treturn;                   // stop traversing, no need to go futher since we have already reached the answer\n\t\t\t}\n        \n        if(root->right)\n            traverse(root->right);\n            \n    }\n    int kthSmallest(TreeNode* root, int k) {\n        n=k;\n        traverse(root);\n        return ans;\n    }\n```
[]