-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasics.java
More file actions
30 lines (27 loc) · 936 Bytes
/
Basics.java
File metadata and controls
30 lines (27 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package BinarySearchTrees;
/**
* Important Conditions for binary trees ->.
* In Binary Search Trees every node to the left of the given node is smaller than the node.
* In Binary Search Trees every node to the right of the given node is larger than the node.
*/
public class Basics {
/**
* Inorder always prints the sorted values. Important!!
*/
public static void inorder(Node root) {
if (root == null) return;
inorder(root.left);
System.out.print(root.val + " ");
inorder(root.right);
}
/**
* Advantages : Efficient Searching O(log * n)
* Efficient Insertion and Deletion
* Usage in TreeMaps, PriorityQueues.
*/
public static void main(String[] args) {
String[] arr = {"50", "20", "60", "17", "34", "55", "89", "10", "", "28", "", "", "", "70", "", "", "14"};
Node root = Construct.construct(arr);
inorder(root);
}
}