From 2eeb370205485c52f9f88621971d73e433a24f03 Mon Sep 17 00:00:00 2001 From: GauravWalia19 Date: Fri, 21 Dec 2018 12:32:07 +0530 Subject: [PATCH] added binary trees traversals & complexity in java --- .../TREES/BINARY-TREE/BinaryTreeNode.java | 37 +++++ .../TREES/BINARY-TREE/Inorder.java | 34 +++++ .../TREES/BINARY-TREE/IterativeInorder.java | 54 ++++++++ .../TREES/BINARY-TREE/IterativePostorder.java | 63 +++++++++ .../TREES/BINARY-TREE/IterativePreorder.java | 48 +++++++ .../TREES/BINARY-TREE/LevelOrder.java | 48 +++++++ .../TREES/BINARY-TREE/Postorder.java | 33 +++++ .../TREES/BINARY-TREE/Preorder.java | 34 +++++ Java/README.md | 18 +++ datastructures.md | 126 ++++++++++-------- docs/complexity.md | 123 +++++++++++------ 11 files changed, 521 insertions(+), 97 deletions(-) create mode 100644 Java/Data-Structures/TREES/BINARY-TREE/BinaryTreeNode.java create mode 100644 Java/Data-Structures/TREES/BINARY-TREE/Inorder.java create mode 100644 Java/Data-Structures/TREES/BINARY-TREE/IterativeInorder.java create mode 100644 Java/Data-Structures/TREES/BINARY-TREE/IterativePostorder.java create mode 100644 Java/Data-Structures/TREES/BINARY-TREE/IterativePreorder.java create mode 100644 Java/Data-Structures/TREES/BINARY-TREE/LevelOrder.java create mode 100644 Java/Data-Structures/TREES/BINARY-TREE/Postorder.java create mode 100644 Java/Data-Structures/TREES/BINARY-TREE/Preorder.java diff --git a/Java/Data-Structures/TREES/BINARY-TREE/BinaryTreeNode.java b/Java/Data-Structures/TREES/BINARY-TREE/BinaryTreeNode.java new file mode 100644 index 0000000..fb56fb3 --- /dev/null +++ b/Java/Data-Structures/TREES/BINARY-TREE/BinaryTreeNode.java @@ -0,0 +1,37 @@ +public class BinaryTreeNode +{ + public int data; + public BinaryTreeNode left; + public BinaryTreeNode right; + + public BinaryTreeNode(int data) + { + this.data=data; + left=null; + right=null; + } + public int getData() + { + return data; + } + public void setData(int data) + { + this.data=data; + } + public BinaryTreeNode getLeft() + { + return left; + } + public void setLeft(BinaryTreeNode left) + { + this.left = left; + } + public BinaryTreeNode getRight() + { + return right; + } + public void setRight(BinaryTreeNode right) + { + this.right=right; + } +} \ No newline at end of file diff --git a/Java/Data-Structures/TREES/BINARY-TREE/Inorder.java b/Java/Data-Structures/TREES/BINARY-TREE/Inorder.java new file mode 100644 index 0000000..a43b621 --- /dev/null +++ b/Java/Data-Structures/TREES/BINARY-TREE/Inorder.java @@ -0,0 +1,34 @@ +public class Inorder +{ + public static void main(String[] args) + { + BinaryTreeNode ROOT = null; + BinaryTreeNode a = new BinaryTreeNode(1); + BinaryTreeNode b = new BinaryTreeNode(2); + BinaryTreeNode c = new BinaryTreeNode(3); + BinaryTreeNode d = new BinaryTreeNode(4); + BinaryTreeNode e = new BinaryTreeNode(5); + BinaryTreeNode f = new BinaryTreeNode(6); + BinaryTreeNode g = new BinaryTreeNode(7); + + ROOT=a; + ROOT.setLeft(b); + ROOT.setRight(c); + b.setLeft(d); + b.setRight(e); + c.setLeft(f); + c.setRight(g); + + inorder(ROOT); + } + public static void inorder(BinaryTreeNode ROOT) + { + if(ROOT==null) + { + return; + } + inorder(ROOT.left); + System.out.print(ROOT.data+" "); + inorder(ROOT.right); + } +} \ No newline at end of file diff --git a/Java/Data-Structures/TREES/BINARY-TREE/IterativeInorder.java b/Java/Data-Structures/TREES/BINARY-TREE/IterativeInorder.java new file mode 100644 index 0000000..15e023a --- /dev/null +++ b/Java/Data-Structures/TREES/BINARY-TREE/IterativeInorder.java @@ -0,0 +1,54 @@ +import java.util.*; +public class IterativeInorder +{ + public static void main(String[] args) { + BinaryTreeNode ROOT = null; + BinaryTreeNode a = new BinaryTreeNode(1); + BinaryTreeNode b = new BinaryTreeNode(2); + BinaryTreeNode c = new BinaryTreeNode(3); + BinaryTreeNode d = new BinaryTreeNode(4); + BinaryTreeNode e = new BinaryTreeNode(5); + BinaryTreeNode f = new BinaryTreeNode(6); + BinaryTreeNode g = new BinaryTreeNode(7); + + ROOT=a; + ROOT.setLeft(b); + ROOT.setRight(c); + b.setLeft(d); + b.setRight(e); + c.setLeft(f); + c.setRight(g); + + inorder(ROOT); + } + + public static void inorder(BinaryTreeNode ROOT) + { + if(ROOT==null) + { + return; + } + Stack S = new Stack(); + boolean done=false; + BinaryTreeNode current=ROOT; + while(!done) + { + if(current!=null) + { + S.push(current); + current=current.left; + } + else //if null value found + { + if(S.isEmpty()) + done=true; + else + { + current = S.pop(); + System.out.print(current.data+" "); + current=current.right; + } + } + } + } +} \ No newline at end of file diff --git a/Java/Data-Structures/TREES/BINARY-TREE/IterativePostorder.java b/Java/Data-Structures/TREES/BINARY-TREE/IterativePostorder.java new file mode 100644 index 0000000..d71e784 --- /dev/null +++ b/Java/Data-Structures/TREES/BINARY-TREE/IterativePostorder.java @@ -0,0 +1,63 @@ +import java.util.*; +public class IterativePostorder +{ + public static void main(String[] args) { + BinaryTreeNode ROOT = null; + BinaryTreeNode a = new BinaryTreeNode(1); + BinaryTreeNode b = new BinaryTreeNode(2); + BinaryTreeNode c = new BinaryTreeNode(3); + BinaryTreeNode d = new BinaryTreeNode(4); + BinaryTreeNode e = new BinaryTreeNode(5); + BinaryTreeNode f = new BinaryTreeNode(6); + BinaryTreeNode g = new BinaryTreeNode(7); + + ROOT=a; + ROOT.setLeft(b); + ROOT.setRight(c); + b.setLeft(d); + b.setRight(e); + c.setLeft(f); + c.setRight(g); + + postorder(ROOT); + } + public static void postorder(BinaryTreeNode ROOT) + { + if(ROOT==null) + { + return; + } + Stack S = new Stack(); + S.push(ROOT); + BinaryTreeNode prev=null; + while(!S.isEmpty()) + { + BinaryTreeNode current = S.peek(); + if(prev==null || prev.left==current || prev.right==current) + { + //traverse left then right + if(current.left!=null) + { + S.push(current.left); + } + else if(current.right!=null) + { + S.push(current.right); + } + } + else if(current.left==prev) + { + if(current.right!=null) + { + S.push(current.right); + } + } + else + { + System.out.print(current.data+" "); + S.pop(); + } + prev=current; + } + } +} \ No newline at end of file diff --git a/Java/Data-Structures/TREES/BINARY-TREE/IterativePreorder.java b/Java/Data-Structures/TREES/BINARY-TREE/IterativePreorder.java new file mode 100644 index 0000000..89a3d13 --- /dev/null +++ b/Java/Data-Structures/TREES/BINARY-TREE/IterativePreorder.java @@ -0,0 +1,48 @@ +import java.util.*; +public class IterativePreorder +{ + public static void main(String[] args) + { + BinaryTreeNode ROOT = null; + BinaryTreeNode a = new BinaryTreeNode(1); + BinaryTreeNode b = new BinaryTreeNode(2); + BinaryTreeNode c = new BinaryTreeNode(3); + BinaryTreeNode d = new BinaryTreeNode(4); + BinaryTreeNode e = new BinaryTreeNode(5); + BinaryTreeNode f = new BinaryTreeNode(6); + BinaryTreeNode g = new BinaryTreeNode(7); + + ROOT=a; + ROOT.setLeft(b); + ROOT.setRight(c); + b.setLeft(d); + b.setRight(e); + c.setLeft(f); + c.setRight(g); + + preorder(ROOT); + } + public static void preorder(BinaryTreeNode ROOT) + { + if(ROOT==null) + { + return; + } + Stack s = new Stack(); + s.push(ROOT); + while(!s.empty()) + { + BinaryTreeNode tmp= s.pop(); + System.out.print(tmp.data+" "); + + if(tmp.right!=null) + { + s.push(tmp.right); + } + if(tmp.left!=null) + { + s.push(tmp.left); + } + } + } +} \ No newline at end of file diff --git a/Java/Data-Structures/TREES/BINARY-TREE/LevelOrder.java b/Java/Data-Structures/TREES/BINARY-TREE/LevelOrder.java new file mode 100644 index 0000000..618c7a6 --- /dev/null +++ b/Java/Data-Structures/TREES/BINARY-TREE/LevelOrder.java @@ -0,0 +1,48 @@ +import java.util.*; +public class LevelOrder +{ + public static void main(String[] args) { + BinaryTreeNode ROOT = null; + BinaryTreeNode a = new BinaryTreeNode(1); + BinaryTreeNode b = new BinaryTreeNode(2); + BinaryTreeNode c = new BinaryTreeNode(3); + BinaryTreeNode d = new BinaryTreeNode(4); + BinaryTreeNode e = new BinaryTreeNode(5); + BinaryTreeNode f = new BinaryTreeNode(6); + BinaryTreeNode g = new BinaryTreeNode(7); + + ROOT=a; + ROOT.setLeft(b); + ROOT.setRight(c); + b.setLeft(d); + b.setRight(e); + c.setLeft(f); + c.setRight(g); + + levelorder(ROOT); + } + public static void levelorder(BinaryTreeNode ROOT) + { + if(ROOT==null) + { + return; + } + Queue Q = new LinkedList(); + BinaryTreeNode current=ROOT; + + while(current!=null) + { + System.out.print(current.data +" "); + if(current.left!=null) + { + Q.add(current.left); + } + if(current.right!=null) + { + Q.add(current.right); + } + + current=Q.poll(); + } + } +} \ No newline at end of file diff --git a/Java/Data-Structures/TREES/BINARY-TREE/Postorder.java b/Java/Data-Structures/TREES/BINARY-TREE/Postorder.java new file mode 100644 index 0000000..03e2d0e --- /dev/null +++ b/Java/Data-Structures/TREES/BINARY-TREE/Postorder.java @@ -0,0 +1,33 @@ +public class Postorder +{ + public static void main(String[] args) { + BinaryTreeNode ROOT = null; + BinaryTreeNode a = new BinaryTreeNode(1); + BinaryTreeNode b = new BinaryTreeNode(2); + BinaryTreeNode c = new BinaryTreeNode(3); + BinaryTreeNode d = new BinaryTreeNode(4); + BinaryTreeNode e = new BinaryTreeNode(5); + BinaryTreeNode f = new BinaryTreeNode(6); + BinaryTreeNode g = new BinaryTreeNode(7); + + ROOT=a; + ROOT.setLeft(b); + ROOT.setRight(c); + b.setLeft(d); + b.setRight(e); + c.setLeft(f); + c.setRight(g); + + postorder(ROOT); + } + public static void postorder(BinaryTreeNode ROOT) + { + if(ROOT==null) + { + return; + } + postorder(ROOT.left); + postorder(ROOT.right); + System.out.print(ROOT.data+" "); + } +} \ No newline at end of file diff --git a/Java/Data-Structures/TREES/BINARY-TREE/Preorder.java b/Java/Data-Structures/TREES/BINARY-TREE/Preorder.java new file mode 100644 index 0000000..5d8e711 --- /dev/null +++ b/Java/Data-Structures/TREES/BINARY-TREE/Preorder.java @@ -0,0 +1,34 @@ +public class Preorder +{ + public static void main(String[] args) + { + BinaryTreeNode ROOT = null; + BinaryTreeNode a = new BinaryTreeNode(1); + BinaryTreeNode b = new BinaryTreeNode(2); + BinaryTreeNode c = new BinaryTreeNode(3); + BinaryTreeNode d = new BinaryTreeNode(4); + BinaryTreeNode e = new BinaryTreeNode(5); + BinaryTreeNode f = new BinaryTreeNode(6); + BinaryTreeNode g = new BinaryTreeNode(7); + + ROOT=a; + ROOT.setLeft(b); + ROOT.setRight(c); + b.setLeft(d); + b.setRight(e); + c.setLeft(f); + c.setRight(g); + + preorder(ROOT); + } + public static void preorder(BinaryTreeNode ROOT) + { + if(ROOT==null) + { + return; + } + System.out.print(ROOT.getData()+" "); //root + preorder(ROOT.getLeft()); //left + preorder(ROOT.getRight()); //right + } +} \ No newline at end of file diff --git a/Java/README.md b/Java/README.md index 3f40734..d2475b9 100644 --- a/Java/README.md +++ b/Java/README.md @@ -46,6 +46,24 @@ #### TREES +##### BINARY TREES + +* [Binary Tree Node Example](Data-Structures/TREES/BINARY-TREE/BinaryTreeNode.java) +* Traversals + * Depth First Search + * IN ORDER + * [ITERATIVE](Data-Structures/TREES/BINARY-TREE/IterativeInorder.java) + * [RECURSIVE](Data-Structures/TREES/BINARY-TREE/Inorder.java) + * PRE ORDER + * [ITERATIVE](Data-Structures/TREES/BINARY-TREE/IterativePreorder.java) + * [RECURSIVE](Data-Structures/TREES/BINARY-TREE/Preorder.java) + * POST ORDER + * [ITERATIVE](Data-Structures/TREES/BINARY-TREE/IterativePostorder.java) + * [RECURSIVE](Data-Structures/TREES/BINARY-TREE/Postorder.java) + * Breadth First Search + * LEVEL ORDER + * [ITERATIVE](Data-Structures/TREES/BINARY-TREE/LevelOrder.java) + ### :rocket: DYNAMIC PROGRAMMING ### :rocket: MISC diff --git a/datastructures.md b/datastructures.md index b6e1c86..374ef7b 100644 --- a/datastructures.md +++ b/datastructures.md @@ -2,11 +2,9 @@ Indexer for Data Structures Lover -## INDEX +## :octocat: ARRAYS -### :octocat: ARRAYS - -#### 1 DIMENSIONAL +### 1 DIMENSIONAL * blog * docs @@ -14,8 +12,11 @@ Indexer for Data Structures Lover * [C](C/Data-Structures/ARRAYS/1darrays.c) * [C++](C++/Data-Structures/ARRAYS/1darrays.cpp) * [JAVA](Java/Data-Structures/ARRAYS/oneDarray.java) +* implementation using heaps + * [C](C/Data-Structures/HEAPS/dynamicarray.c) + * [C++](C++/Data-Structures/HEAPS/1darray.cpp) -#### 2 DIMENSIONAL +### 2 DIMENSIONAL * blog * docs @@ -23,8 +24,11 @@ Indexer for Data Structures Lover * [C](C/Data-Structures/ARRAYS/2darrays.c) * [C++](C++/Data-Structures/ARRAYS/2darrays.cpp) * [JAVA](Java/Data-Structures/ARRAYS/twoDarray.java) +* implementation using heaps + * [C](C/Data-Structures/HEAPS/dynamic2d.c) + * [C++](C++/Data-Structures/HEAPS/2darray.cpp) -#### 3 DIMENSIONAL +### 3 DIMENSIONAL * blog * docs @@ -32,8 +36,11 @@ Indexer for Data Structures Lover * [C](C/Data-Structures/ARRAYS/3darrays.c) * [C++](C++/Data-Structures/ARRAYS/3darrays.cpp) * [JAVA](Java/Data-Structures/ARRAYS/threeDarray.java) +* implementation using heaps + * [C](C/Data-Structures/HEAPS/dynamic3d.c) + * [C++](C++/Data-Structures/HEAPS/1darray.cpp) -#### 4 DIMENSIONAL +### 4 DIMENSIONAL * blog * docs @@ -42,15 +49,15 @@ Indexer for Data Structures Lover * [C++](C++/Data-Structures/ARRAYS/4darrays.cpp) * [JAVA](Java/Data-Structures/ARRAYS/fourDarray.java) -#### INBUILT ARRAY CLASSES +### INBUILT ARRAY CLASSES -##### ARRAYS CLASS(JAVA) +#### ARRAYS CLASS(JAVA) * blog * docs * [arrays class in java](Java/Data-Structures/ARRAYS/arrays.java) -##### ARRAY CLASS(C++) +#### ARRAY CLASS(C++) * blog * docs @@ -63,16 +70,16 @@ Indexer for Data Structures Lover * implementation * [C](C/Data-Structures/ARRAYS/jaggedarray.c) -### :octocat: STRING +## :octocat: STRING * blog * docs * implementation * [JAVA](Java/Data-Structures/STRING/Strings.java) -### :octocat: LISTS +## :octocat: LISTS -#### SINGLE +### SINGLE * blog * docs @@ -80,40 +87,40 @@ Indexer for Data Structures Lover * [C](C/Data-Structures/LINKED-LIST/SINGLE/Main.c) * [C++](C++/Data-Structures/LISTS/LINKED-LIST/SINGLE/Main.cpp) -#### DOUBLE +### DOUBLE * blog * docs * implementation * [C](C/Data-Structures/LINKED-LIST/DOUBLE/Main.c) -#### CIRCULAR +### CIRCULAR -#### INBUILT LISTS +### INBUILT LISTS -##### ARRAYLIST +#### ARRAYLIST * blog * docs * implementation -##### VECTOR +#### VECTOR * blog * docs * implementation * [C++](C++/Data-Structures/LISTS/VECTORS/Main.cpp) -##### LIST +#### LIST PY * blog * docs * implementation * [PYTHON](Python3/Data-Structures/LISTS/inbuiltList.py) -### :octocat: STACKS +## :octocat: STACKS -#### FIXED ARRAY STACK +### FIXED ARRAY STACK * blog * docs @@ -121,16 +128,16 @@ Indexer for Data Structures Lover * [C++](C++/Data-Structures/STACKS/Stack.hpp) * [JAVA](Java/Data-Structures/STACKS/FIXED-ARRAY-STACK/ArrayStack.java) -#### DYNAMIC ARRAY STACK +### DYNAMIC ARRAY STACK -#### LINKED STACK +### LINKED STACK * blog * docs * implementation * [JAVA](Java/Data-Structures/STACKS/LINKED-STACK/LinkedStack.java) -#### INBUILT STACKS +### INBUILT STACKS * blog * docs @@ -138,63 +145,76 @@ Indexer for Data Structures Lover * [C++](C++/Data-Structures/STACKS/stack.cpp) * [JAVA](Java/Data-Structures/STACKS/INBUILT-STACK/Stacks.java) -#### MISC STACKS +### MISC STACKS -##### Minimum bracket reversal for making brackets balanced +#### Minimum bracket reversal for making brackets balanced * blog * docs * implementation * [C](C/Data-Structures/STACKS/MISC-STACKS/minimum_bracket_reversal_for_balanced_expression.c) -##### Postfix Evaluation +#### Postfix Evaluation * blog * docs * implementation * [C](C/Data-Structures/STACKS/MISC-STACKS/postfix_evaluation.c) -##### TWO WAY STACK +#### TWO WAY STACK * blog * docs * implementation * [C++](C++/Data-Structures/STACKS/Tstack.hpp) -### :octocat: QUEUES +## :octocat: QUEUES -### :octocat: HASHTABLES +## :octocat: TREES -### :octocat: SETS +### BINARY TREES -### :octocat: TREES +#### TRAVERSALS -### :octocat: HEAPS +##### DEPTH FIRST SEARCH -#### 1 DIMENSIONAL ARRAYS +* IN ORDER + * [ITERATIVE](Data-Structures/TREES/BINARY-TREE/IterativeInorder.java) + * [RECURSIVE](Data-Structures/TREES/BINARY-TREE/Inorder.java) +* PRE ORDER + * [ITERATIVE](Data-Structures/TREES/BINARY-TREE/IterativePreorder.java) + * [RECURSIVE](Data-Structures/TREES/BINARY-TREE/Preorder.java) +* POST ORDER + * [ITERATIVE](Data-Structures/TREES/BINARY-TREE/IterativePostorder.java) + * [RECURSIVE](Data-Structures/TREES/BINARY-TREE/Postorder.java) -* blog -* docs -* implementation - * [C](C/Data-Structures/HEAPS/dynamicarray.c) - * [C++](C++/Data-Structures/HEAPS/1darray.cpp) +##### BREADTH FIRST SEARCH -#### 2 DIMENSIONAL ARRAYS +* LEVEL ORDER + * [ITERATIVE](Data-Structures/TREES/BINARY-TREE/LevelOrder.java) -* blog -* docs -* implementation - * [C](C/Data-Structures/HEAPS/dynamic2d.c) - * [C++](C++/Data-Structures/HEAPS/2darray.cpp) +### GENERIC TREES -#### 3 DIMENSIONAL ARRAYS +### THREADED BINARY TREE -* blog -* docs -* implementation - * [C](C/Data-Structures/HEAPS/dynamic3d.c) - * [C++](C++/Data-Structures/HEAPS/1darray.cpp) +### XOR TREES + +### BINARY SEARCH TREE + +### AVL TREES + +### RED BLACK TREES + +### SPLAY TREES + +### AUGMENTED TREES + +### SCAPEGOAT TREES + +### INTERVAL TREES + +### HEAP TREE -### :octocat: GRAPHS +## :octocat: GRAPHS -### :octocat: BLOCKCHAIN \ No newline at end of file +## :octocat: BLOCKCHAIN \ No newline at end of file diff --git a/docs/complexity.md b/docs/complexity.md index e2e66ca..db439d7 100644 --- a/docs/complexity.md +++ b/docs/complexity.md @@ -60,9 +60,15 @@ This page contains the complexities of different algorithms in this repository. * [ARRAYS CLASS IN JAVA](#arrays-class-in-java) * ARRAY CLASS IN C++ * [MISC ARRAYS](#misc-arrays) + * HEAPED 1D ARRAY + * HEAPED 2D ARRAY + * HEAPED 3D ARRAY * [JAGGED ARRAY](#jagged-array) + * [STRING](#string) + * Strings in C * [Strings in JAVA](#strings-in-java) + * Strings in C++ * [LISTS](#lists) * SINGLE * [SINGULAR LINKED LIST](#singular-linked-list-having-head-and-next) @@ -100,8 +106,8 @@ This page contains the complexities of different algorithms in this repository. * LINKED PRIORITY QUEUE * HEAPED PRIORITY QUEUE * HASHTABLE - * TREES - * BINARY TREE + * [TREES](#trees) + * [BINARY TREE](#binary-trees) * GENERIC TREES * THREADED BINARY TREE * XOR TREES @@ -135,14 +141,14 @@ This page contains the complexities of different algorithms in this repository. #### :rocket: SORTING - SNo. | Algorithm | Order of complexity O(n) | Type of Complexity | Stable/Unstable Sort | In Place Algorithm | Space Complexity - ---- | --------- Data-Structures/STRING/Strings.java| ------------------------ | ------------------ | -------------------- | ------------------ | ---------------- - 1 | Bubble Sort | O(n^2) | Quadratic | Stable / Can be Unstable** | :heavy_check_mark: | O(1) - 2 | Selection Sort | O(n^2) | Quadratic | Unstable | :heavy_check_mark: | O(1) - 3 | Insertion Sort | O(n^2) | Quadratic | Stable | :heavy_check_mark: | O(1) - 4 | Shell Sort | O(n^2) or better | Quadratic or other | Unstable | :heavy_check_mark: | - 5 | Counting Sort | O(n) | Linear | Stable / Unstable | :heavy_multiplication_x: | - 6 | Radix Sort | O(n) or slower than O(nlogn) | Linear / Logarithmic | Stable | Can Be | + SNo. | Algorithm | Order and type of Time complexity O(n) | Order and Type of Space Complexity | Stable/Unstable Sort | In Place Algorithm + ---- | --------- | -------------------------------------- | ---------------------------------- | -------------------- | ------------------ + 1 | Bubble Sort | O(n^2) -- Quadratic | O(1) -- Constant | Stable / Can be Unstable** | :heavy_check_mark: + 2 | Selection Sort | O(n^2) -- Quadratic | O(1) -- Constant | Unstable | :heavy_check_mark: + 3 | Insertion Sort | O(n^2) -- Quadratic | O(1) -- Constant | Stable | :heavy_check_mark: + 4 | Shell Sort | O(n^2) or better -- Quadratic or other | | Unstable | :heavy_check_mark: + 5 | Counting Sort | O(n) -- Linear | | Stable / Unstable | :heavy_multiplication_x: + 6 | Radix Sort | O(n) or slower than O(nlogn) -- Linear / Logarithmic | | Stable | Can Be **Not an efficient Way @@ -270,6 +276,45 @@ This page contains the complexities of different algorithms in this repository. #### MISC ARRAYS +##### HEAPED 1D ARRAYS + + SNo. | Operations | Order of complexity O(n) | Type of Complexity + ---- | ---------- | ------------------------ | ------------------ + 1 | Use value by indexes | O(1) | Constant + 2 | Insertion at beginning | O(n) | Linear + 3 | Deletion at beginning | O(n) | Linear + 4 | Insertion at end (empty array) | O(n) | Linear + 5 | Deletion at end (empty array) | O(n) | Linear + 6 | Deletion of the value without having index | O(n) | Linear + 7 | Update value without having index | O(n) | Linear + 8 | Update value having index | O(1) | Constant + +##### HEAPED 2D ARRAYS + + SNo. | Operations | Order of complexity O(n) | Type of Complexity + ---- | ---------- | ------------------------ | ------------------ + 1 | Use value by indexes | O(1) | Constant + 2 | Insertion at beginning | O(n^2) | Quadratic + 3 | Deletion at beginning | O(n^2) | Quadratic + 4 | Insertion at end (empty array) | O(n^2) | Quadratic + 5 | Deletion at end (empty array) | O(n^2) | Quadratic + 6 | Deletion of the value without having index | O(n^2) | Quadratic + 7 | Update value without having index | O(n^2) | Quadratic + 8 | Update value having index | O(1) | Constant + +##### HEAPED 3D ARRAYS + + SNo. | Operations | Order of complexity O(n) | Type of Complexity + ---- | ---------- | ------------------------ | ------------------ + 1 | Use value by indexes | O(1) | Constant + 2 | Insertion at beginning | O(n^3) | Cubic + 3 | Deletion at beginning | O(n^3) | Cubic + 4 | Insertion at end (empty array) | O(n^3) | Cubic + 5 | Deletion at end (empty array) | O(n^3) | Cubic + 6 | Deletion of the value without having index | O(n^3) | Cubic + 7 | Update value without having index | O(n^3) | Cubic + 8 | Update value having index | O(1) | Constant + ##### JAGGED ARRAYS #### INBUILT ARRAY CLASSES @@ -493,46 +538,36 @@ SNo. | Operations | Order and Type of Time Complexity O(n) | Order and Type of S ### TREES -### HEAPS +#### BINARY TREES -#### DYNAMIC 1D ARRAYS (C,C++) + SNo. | Operations | Order and Type of Time Complexity O(n) | Order and Type of Space Complexity | Iterative | Recursive + ---- | ---------- | -------------------------------------- | ---------------------------------- | --------- | --------- + 1 | In Order Traversal | O(n) -- Linear | O(n) -- Linear | :heavy_check_mark: | :heavy_check_mark: + 2 | Pre Order Traversal | O(n) -- Linear | O(n) -- Linear | :heavy_check_mark: | :heavy_check_mark: + 3 | Post Order Traversal | O(n) -- Linear | O(n) -- Linear | :heavy_check_mark: | :heavy_check_mark: + 4 | Level Order Traversal | O(n) -- Linear | O(n) -- Linear | :heavy_check_mark: | :x: - SNo. | Operations | Order of complexity O(n) | Type of Complexity - ---- | ---------- | ------------------------ | ------------------ - 1 | Use value by indexes | O(1) | Constant - 2 | Insertion at beginning | O(n) | Linear - 3 | Deletion at beginning | O(n) | Linear - 4 | Insertion at end (empty array) | O(n) | Linear - 5 | Deletion at end (empty array) | O(n) | Linear - 6 | Deletion of the value without having index | O(n) | Linear - 7 | Update value without having index | O(n) | Linear - 8 | Update value having index | O(1) | Constant +#### GENERIC TREES -#### DYNAMIC 2D ARRAYS (C,C++) +#### THREADED BINARY TREE - SNo. | Operations | Order of complexity O(n) | Type of Complexity - ---- | ---------- | ------------------------ | ------------------ - 1 | Use value by indexes | O(1) | Constant - 2 | Insertion at beginning | O(n^2) | Quadratic - 3 | Deletion at beginning | O(n^2) | Quadratic - 4 | Insertion at end (empty array) | O(n^2) | Quadratic - 5 | Deletion at end (empty array) | O(n^2) | Quadratic - 6 | Deletion of the value without having index | O(n^2) | Quadratic - 7 | Update value without having index | O(n^2) | Quadratic - 8 | Update value having index | O(1) | Constant +#### XOR TREES -#### DYNAMIC 3D ARRAYS (C,C++) +#### BINARY SEARCH TREE - SNo. | Operations | Order of complexity O(n) | Type of Complexity - ---- | ---------- | ------------------------ | ------------------ - 1 | Use value by indexes | O(1) | Constant - 2 | Insertion at beginning | O(n^3) | Cubic - 3 | Deletion at beginning | O(n^3) | Cubic - 4 | Insertion at end (empty array) | O(n^3) | Cubic - 5 | Deletion at end (empty array) | O(n^3) | Cubic - 6 | Deletion of the value without having index | O(n^3) | Cubic - 7 | Update value without having index | O(n^3) | Cubic - 8 | Update value having index | O(1) | Constant +#### AVL TREES + +#### RED BLACK TREES + +#### SPLAY TREES + +#### AUGMENTED TREES + +#### SCAPEGOAT TREES + +#### INTERVAL TREES + +#### HEAP TREE ### GRAPHS