convert a sorted array to binary tree

You are given a sorted Array of numbers in ascending order .Give an efficient algo for converting it in to Height Balanced Binary tree.

Comments

  1. recursive approach:

    Struct node * convert(int arr[],int start,int end)
    {
    if(start>end) return NULL;
    else
    {
    int mid=(start+end)/2;
    struct node* root=new node;
    root->data=arr[mid];
    root->left=convert(arr,start,mid-1);
    root->right=convert(arr,mid+1,end);
    return root;
    }


    }

    ReplyDelete
  2. @Priyaranjan could you please give the solution for other questions that have not been solved yet??.....

    ReplyDelete
  3. @ankit can you be please specific and i would encourage people to come up with solution and then we can discuss.But you can always ask solution to specific questions...:)

    ReplyDelete

Post a Comment

Popular posts from this blog