Mehdi9721 / DSA-self-java-Also-contains-solutions-of-many-problems-

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DSA_JAVA

created own adt for array

created subsequence pattern

Sorting algorithms

AVL tree

the Height can be maintain while insertion in BST
(int height) should also be added in tree class where data is declared

void height(){
if(root==null)return -1;
return root.height;
}
The upper function will return -1 if root is null else return current height of root

NOW while inserting into BST just maintain the height of root before returning the root;
root.height= Math.max(height(root.left),height(root.right))+1;
the (+1) in the above code will increase the height by 1 when a new nood gets inserted in BST

BFS DFS

bfs dfs is a important searching techniqes of a Tree
In BFS, we perform level wise traversal of node using queue, when the upper level Nodes are traversed then we come to the lower level nodes.

BFS

Queue q= new LinkedList<>()
q.add(root)
while(!q.isEmpty){
itr=q.remove();
check if conditions for adding childs in queue
}

DFS

DFS is a top to bottom search
PREORDER , POSTORDER , INORDER is used in DFS
INORDER = > Inorder gives soted data of a BST
POSTORDER => postorder can be use when we want to delete tree

GOOGLE AMAZON (most asked)

Q-> populating next right node imnt perfect Binary Tree?

approach=>

the next is also provided hence only use LinkedList Logic to solve this question.

q= find elemets of tree from right side view

approach

traverse level wise and find the last node of each level, it can be found by using nested for loop inside while loop, inside will run till the complete level of tree and add last value

About


Languages

Language:Java 100.0%