Given a sorted array in increasing order, create a BST of minimum height I know there are a few recursive ways to solve this problem but the code below is what came to mind for me.

void create_bst(node *root, vector&lt;int&gt; arr)
{
    int len = arr.size();
    add_nodes(root,len-1); //Make the tree structure
    inorder_traversal(root,arr);
}

void add_nodes(node *n, int len)
{   
queue&lt;node *&gt; bfs;
bfs.push(n);
int i = 1;

    while(!bfs.empty())
    {
    node *temp = bfs.front();
    bfs.pop();

    temp-&gt;left = new node(i++);
    len--;
    if(len == 0)
    {
        break;
    }
    bfs.push(temp-&gt;left);

    temp-&gt;right = new node(i++);
    len--;
    if(len == 0)
    {
        break;
    }
    bfs.push(temp-&gt;right);
    }
}

void inorder_traversal(node *n, vector&lt;int&gt; arr)
{
static int i=0;
if(n-&gt;left != NULL)
{
    inorder_traversal(n-&gt;left,arr);
}
if(n != NULL)
{
    n-&gt;data = arr[i];
    i++;
}
if(n-&gt;right != NULL)
{
    inorder_traversal(n-&gt;right,arr);
}
}


The add nodes function creates the BST and the inorder traversal function inserts the appropriate values at each node. Is the algorithm above an efficient way to solve this problem?
Your code will only work one time, because of the static int i in your inorder_traversal function. You have no way to reset i to 0
Splitting creation and filling into two parts is not what I'd call efficient. This way you have to traverse the tree twice: once while creating it and once while filling it. And if you do not depend on a complete binary tree, managing a queue is a wast of time and unnecessary complexity to whom ever is trying to read your code.


My advice would be, work recursive on recursive data. The recursive way is much shorter and much easier to read, isn't it?

node* create_bst(vector&lt;int&gt; const&amp; arr)
{
  return create_bst(arr, 0, arr.size());
}

node* create_bst(vector&lt;int&gt; const&amp; arr, int start, int end)
{
  if (start &gt;= end)
    return null;

  int m = (start + end) / 2;

  node* root = new node(arr[m]);

  root-&gt;left = create_bst(arr, start, m);
  root-&gt;right = create_bst(arr, m + 1, end);

  return root;
}