+ 25

[ ASSIGNMENT: ] Binary search tree validation

A binary search tree is a binary tree that is ordered. This means that if you were to convert the tree to an array using an in-order traversal, the array would be in sorted order. The benefit gained by this ordering is that when the tree is balanced, searching is a logarithmic time operation, since each node you look at that isn't the one you're searching for lets you discard half of the tree. TASK: Write a function that will validate that a given binary tree is a binary search tree. The sort order is not predefined so it should work with either. These are valid binary search trees: 5 / \ 2 7 / \ \ 1 3 9 7 / \ 9 2 while these are not: 1 / \ 2 3 5 / \ 2 9 \ 7 There are several different approaches you can take to solve this task. If you're not as comfortable with recursion I'd recommend practicing that. Note: no test case tree will contain duplicate numbers! HappyCodings! :)

13th Jun 2018, 11:34 AM
Danijel Ivanović
Danijel Ivanović - avatar
7 Respuestas
+ 16
Åtomıc Will you do the task and set your code! 👍😉
13th Jun 2018, 12:11 PM
Danijel Ivanović
Danijel Ivanović - avatar
17th Jun 2018, 9:41 AM
LukArToDo
LukArToDo - avatar
+ 5
I can see the algorithm and I don't even know recursion
13th Jun 2018, 11:47 AM
Archie
Archie - avatar
+ 4
I'll try 😃
13th Jun 2018, 12:24 PM
Archie
Archie - avatar
+ 2
https://code.sololearn.com/cXFD6q4ZgGRl/?ref=app
14th Jun 2018, 8:32 PM
VcC
VcC - avatar
+ 1
my approach, with a simple Node class And checking Recursive path with sorted values!! Hope you like it! 😀 https://code.sololearn.com/cwZQM2IjofXu/?ref=app
22nd Jun 2018, 5:24 PM
Francisco Casas
Francisco Casas - avatar