✅ c++ Recursive || Iterative || TC:O(H+K)
Approach :\nInorder traversal of BST print the element in increasing order so that kth smallest element in BST is the kth item in inorder traversal\n\nRecursive
***Approach :***\n***Inorder traversal of BST***  **print the element in increasing order so that kth smallest element in BST is the kth item in inorder traversal**\n\n**Recursive**\n**Time complexcity O(H+K)** H is height of bst\n**Space complexcity O(1)**\nhence we are not using any extra space but for the recursion calls space is allocated and that would be in order of O(H+K) **(Recursion stack space)**\n```\nint kthSmallest(TreeNode* root, int &k) \n    {\n        if(root==NULL) return -1;\n        \n        int left=kthSmallest(root->left,k);          // left recursive call\n        \n        if(left!=-1) return left;                      // if we get answer from left call than return it\n        k--;\n        if(k==0) return root->val;                 // this is kth smallest element\n         \n        int right=kthSmallest(root->right,k);     // right recursive call\n        \n        if(right!=-1) return right;                   // if we get answert from right call than return it\n        \n        return -1;                                 // return -1 if we not get answer from this call\n    }\n```\n\n**Iterative**\n**Time complexcity O(H+K)** H is height of bst\n**Space complexcity O(H+K)**\n```\nint kthSmallest(TreeNode* root, int k) \n    {\n        stack<TreeNode *> stk;\n        while(1)\n        {\n            while(root!=NULL)\n            {\n                stk.push(root);\n                root=root->left;\n            }\n            root=stk.top();\n            stk.pop();\n            k--;\n            if(k==0) return root->val;\n            root=root->right;\n        }\n    }\n```
[]