# Convert sorted array to balanced binary search tree

If you want to practice data structure and algorithm programs, you can go through 100+ java coding interview questions.

In this post ,  we will see how to convert sorted array to balanced binary search tree.

### Algorithm:

You might know that inorder traversal of binary search tree results in sorted array. We will use this property to convert sorted array to balanced binary search tree, so middle element of array or sub array will always be root for that array or subarray.

• Initialise two variables start and end with 0 and arr.length -1.
• Find middle element of array using start and end.
• Make middle element root element of tree.
• Recursively traverse left subtree, find middle and make it root node of left subtree
• Recursively traverse right subtree, find middle and make it root node of right subtree.

### Java code to convert sorted array to balanced binary search tree:

When you run above program, you will get below output:

import_contacts

## Related Posts

• 21 July

### KimCartoon alternatives -13 Best Websites Like KimCartoon in 2021

Table of ContentsBest KimCartoon alternatives in 2021CartoonsOnToonovaKissAnimeToonGetWatch Cartoons OnlineCartoonCrazyAnimedaoAnimeToonCartoon ExtraEyeonanimeNyaaMasteraniToonJetFrequently Asked Questions Is KimCartoon safe in 2021?Is KimCartoon legal in 2021?Is there any working proxy of KimCartoon in 2021?Wrapping Up Are you worried about KimCartoon getting shut recently? Well, we’ve you covered. KimCartoon has been one of the best platforms for seamlessly streaming cartoons in HD. […]

• 19 July

### Trim String in C++

Table of ContentsUsing Boost string algorithms to trim string in C++Using find_first_not_of() and find_last_not_of()` to trim strings in C++Using find_if() to trim the string in C++Using stringstream to trim the strings in C++Using a customized function to trim the strings in C++Conclusion When we take an input from an user, strings can have unwanted whitespaces […]

• 19 July

### JSON Parser in C++

Table of ContentsSimple JSON Parser in C++ using JsonCpp libraryConclusion In this post, we will see about JSON parser in C++. There is no native support for JSON in C++. We can use a number of libraries that provide support for JSON in C++. We will use JsonCpp to parse JSON files in C++ which […]

• 19 July

### Convert enum to string in C++

Table of ContentsUsing stringify macro method to convert enum to String in C++Using const char* Array to convert enum to String in C++Using a custom-defined function to convert enum to String in C++Conclusion There are a variety of methods to convert enum to String in C++. In this article, we will discuss some of the […]

• 18 July

### 13 Best Sites Like 123movies Working in 2021

Table of ContentsBest sites like 123movies in 2021F MoviesJust WatchTV MusePopcornFlixVid StrumSoap2dayWatch SeriesXfinityWatch EpisodeTubi TVRainer LandCravePrime WireBest Working Proxy of 123movies Working in 2021Frequently Asked Questions What is 123movies? Why do you need sites like 123movies? Are there any Free sites like 123movies? Wrapping Up For quite some time now, 123movies has been the one-stop destination for watching movies […]

• 18 July

### The Best Free Open Source PDF Editor for Windows and Mac in 2021

Table of ContentsBest Open Source PDF Editor in 2021InkScapeApache OpenOffice DrawPDFSamLibreOffice Draw PDF EditorPDFeditOkularEaseUS PDF Editor (Free)SkimPDF Architect (Free)Frequently Asked QuestionsWhat do you mean by an open source PDF editor? Is there an open source PDF editor?Can I edit a PDF for free?Which are the best free open source PDF editors?Wrapping Up Are you looking for […]

## Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.