AVL Tree ko ratna nahi hai, Logic samj jaao achee se, baaki Khud implement kar loge....
@zafrul_islam9 ай бұрын
Yes, I want to learn about segment trees, Fenwick trees, and tries.
@ayushmaanyadav7229 ай бұрын
Bhaiya c language ke baad c++ chalu karu ke sidhe 180 days hard me ghus jau .please reply
@GopalMaheshwari-ApkaDost9 ай бұрын
sir ye koi puchne vali bat thodina hai sab pahaiyeiye😅
@Sanataniblood-mb5pu6 ай бұрын
Awesome bhaiya ❤
@RishabhChatterjee-fg2gz5 ай бұрын
Bhaiya Trie, Segment trees bhi parna hai aap se AVL tree ko jab college mein para tha tab implementation nehi kar paunga esa felling hota tha, par ye to bahut easy hai
@mohit62159 ай бұрын
Bhaiya this is the G.O.A.T of all DSA trees ,please pickup fenwick trees and tries because google asks many QUESTIONS in the interview
@Sanataniblood-mb5pu6 ай бұрын
Etana koi nhi samajhta bhaiya your efforts are incredible 🙏🏻
@gurtegsinghsohi4114 ай бұрын
Hi , can someone please find logical error in my code .. i even tried to debug with chatgpt and also dry run many times but still error is coming For Input: 54 44 86 43 46 78 88 N N N 50 61 83 N 89 8 46 86 88 61 89 78 54 83 Your Code's output is: Unbalanced BST, inorder traversal : 43 44 50 54 78 83 89 It's Correct output is: 43 44 50 Output Difference Unbalanced BST, inorder traversal : 43 44 50 54 78 83 89 CODE ----------------------- int getheight(Node* root){ if(root==NULL){ return 0; } return root->height; } int check(Node* root){ return getheight(root->left) - getheight(root->right); } Node* rrotate(Node* root){ Node* child = root->left; Node* cr = child->right; child->right = root; root->left = cr; root->height = 1 + max(getheight(root->left),getheight(root->right)); child->height = 1 + max(getheight(child->left),getheight(child->right)); return child; } Node* lrotate(Node* root){ Node* child = root->right; Node* cl = child->left; child->left = root; root->right = cl; root->height = 1 + max(getheight(root->left),getheight(root->right)); child->height = 1 + max(getheight(child->left),getheight(child->right)); return child; } Node* deleteNode(Node* root, int k) { if(!root){ return NULL; } if(root->data > k){ root->left = deleteNode(root->left,k); }else if(root->data < k){ root->right = deleteNode(root->right,k); }else{ if(root->left == NULL && root->right == NULL){ delete root; return NULL; } else if(!root->left && root->right){ Node* temp = root->right; delete root; return temp; }else if(!root->right && root->left){ Node* temp =root->left; delete root; return temp; }else{ Node* temp = root->right; while(temp->left){ temp = temp ->left; } root->data = temp->data; root->right = deleteNode(root->right,temp->data); } root->height = 1 + max(getheight(root->left),getheight(root->right)); int b = check(root); if(b>1){ if(check(root->left)>=0){ return rrotate(root); }else{ root->left = lrotate(root->left); return rrotate(root); } }else if(b < -1){ if(check(root->right)right = rrotate(root->right); return lrotate(root); } }else{ return root; } }
@sunandachakraborty78445 ай бұрын
This is the most underrated yt channel !! :) Thanks sir for such efforts ❤
@motivationvideo-be6hv9 ай бұрын
Bhiya ek baat hai jindgi me koi teacher student ke liye kitni mehnat karta hai❤❤
@sumitvishwakarma10759 ай бұрын
6 days more and the challenge of 180 days will be completed. Thankyou bhaiya I learned many things because of you #coderarmy ❤
@vaishalichoudhary59 ай бұрын
Yes ..I want to learn about segment trees, Fenwick trees, and tries...:)
@MaheshwariLakde6 ай бұрын
sabhi topics padhne hai bhaiya trie bhi segment tree bhi sabhi..!! Thanks for such quality content..!!
Ji bhaiya ..we want to learn about segment trees, Fenwick trees, tries and further advance topics, just a request that please don't hold this series👍👍❤❤
@jaivikpatel28824 ай бұрын
best video and detailed video for avl tree
@SK__EDITZ453 ай бұрын
sir you are the best teacher i have ever seen the concept clarity in your lectures are just incredible...its my humble request to you to please make thw videos on k-tree,b-tree,b+-tree and red-black tree please sir.... and i am from uttarakhand too sir....love you from the bottom of my heart..and i always suggest to my friend circle to study from you as you are the best teacher🥰🥰🥰
@jamitkumar7251Ай бұрын
thanks a lot sir..., uh made this topic super easy
@amankumbhalwar9 ай бұрын
kisi ne bhi ye puri playlist follow ki hai ya aage karne wale hai please 1st video me comment kar do ki ye playlist aachi hai aur kyu follow karni chahiye :)
@puneetsetia68009 ай бұрын
Bhaut bdiya complete sir you made my interest in it
@Codes_king9 ай бұрын
Such me two times dekha video aur sb automatic clear ho gaya aur bahut acche se implement bhi kar liya, maza aa gaya , Baap level AVL Tree on KZbin 🙏🙏
@gurtegsinghsohi4114 ай бұрын
Hi , can someone please find logical error in my code .. i even tried to debug with chatgpt and also dry run many times but still error is coming For Input: 54 44 86 43 46 78 88 N N N 50 61 83 N 89 8 46 86 88 61 89 78 54 83 Your Code's output is: Unbalanced BST, inorder traversal : 43 44 50 54 78 83 89 It's Correct output is: 43 44 50 Output Difference Unbalanced BST, inorder traversal : 43 44 50 54 78 83 89 CODE ----------------------- int getheight(Node* root){ if(root==NULL){ return 0; } return root->height; } int check(Node* root){ return getheight(root->left) - getheight(root->right); } Node* rrotate(Node* root){ Node* child = root->left; Node* cr = child->right; child->right = root; root->left = cr; root->height = 1 + max(getheight(root->left),getheight(root->right)); child->height = 1 + max(getheight(child->left),getheight(child->right)); return child; } Node* lrotate(Node* root){ Node* child = root->right; Node* cl = child->left; child->left = root; root->right = cl; root->height = 1 + max(getheight(root->left),getheight(root->right)); child->height = 1 + max(getheight(child->left),getheight(child->right)); return child; } Node* deleteNode(Node* root, int k) { if(!root){ return NULL; } if(root->data > k){ root->left = deleteNode(root->left,k); }else if(root->data < k){ root->right = deleteNode(root->right,k); }else{ if(root->left == NULL && root->right == NULL){ delete root; return NULL; } else if(!root->left && root->right){ Node* temp = root->right; delete root; return temp; }else if(!root->right && root->left){ Node* temp =root->left; delete root; return temp; }else{ Node* temp = root->right; while(temp->left){ temp = temp ->left; } root->data = temp->data; root->right = deleteNode(root->right,temp->data); } root->height = 1 + max(getheight(root->left),getheight(root->right)); int b = check(root); if(b>1){ if(check(root->left)>=0){ return rrotate(root); }else{ root->left = lrotate(root->left); return rrotate(root); } }else if(b < -1){ if(check(root->right)right = rrotate(root->right); return lrotate(root); } }else{ return root; } }
@heetpatel30377 ай бұрын
Jai shree Ram ❤️ Bohot bohot shukriya Dil se dhanyawad
@alihaider-ik5ie3 ай бұрын
class Solution { public: /* You are required to complete this method */ int Hight(Node* root) { if (!root) { return 0; } return root->height; } Node* leftrotation(Node* root) { Node* child = root->right; // Fix this to rotate the right child Node* childleft = child->left; // Perform rotation child->left = root; root->right = childleft; // Update heights root->height = 1 + max(Hight(root->left), Hight(root->right)); child->height = 1 + max(Hight(child->left), Hight(child->right)); // Return new root return child; } Node* rightrotation(Node* root) { Node* child = root->left; // Fix this to rotate the left child Node* childright = child->right; // Perform rotation child->right = root; root->left = childright; // Update heights root->height = 1 + max(Hight(root->left), Hight(root->right)); child->height = 1 + max(Hight(child->left), Hight(child->right)); // Return new root return child; } int getbalance(Node* root) { return Hight(root->left) - Hight(root->right); } Node* insertToAVL(Node* root, int data) { // Your code here if (!root) { return new Node(data); } if (data < root->data) { root->left = insertToAVL(root->left, data); } else if (data > root->data) { root->right = insertToAVL(root->right, data); } else { return root; } // Update height of this ancestor node root->height = 1 + max(Hight(root->left), Hight(root->right)); // Get the balance factor int balance = getbalance(root); // Left Left Case if (balance > 1 && data < root->left->data) { return rightrotation(root); } // Right Right Case if (balance < -1 && data > root->right->data) { return leftrotation(root); } // Left Right Case if (balance > 1 && data > root->left->data) { root->left = leftrotation(root->left); return rightrotation(root); } // Right Left Case if (balance < -1 && data < root->right->data) { root->right = rightrotation(root->right); return leftrotation(root); } // Return the unchanged root pointer return root; } };
@itshirdeshk9 ай бұрын
Day 174 ✅🔥 Hn bhaiya hume sare type of trees chaiye 🎄🌴🌳🌲😁✨
@shubhamkumarjha91929 ай бұрын
Good morning bhaiya ji. 💖
@tarunbansal60819 ай бұрын
yes want to lear n fenwick, segment and tries
@aakashy_074 ай бұрын
Thank you bhaiya for ur incredible efforts..😊
@ujjawalgupta331926 күн бұрын
My Solution for Problem Deletion in AVL tree : int getHeight(Node* root) { if(!root) return 0; return root->height; } Node* rightRotation(Node* root) { Node* leftChild = root->left; Node* temp = leftChild->right; leftChild->right = root; root->left = temp; root->height = max(getHeight(root->left), getHeight(root->right)) + 1; leftChild->height = max(getHeight(leftChild->left) , getHeight(leftChild->right)) + 1; return leftChild; } Node* leftRotation(Node* root) { Node* rightChild = root->right; Node* temp = rightChild->left; rightChild->left = root; root->right = temp; root->height = max(getHeight(root->left), getHeight(root->right)) + 1; rightChild->height = max(getHeight(rightChild->left) , getHeight(rightChild->right)) + 1; return rightChild; } Node* deleteNode(Node* root, int x) { // tree is empty if(!root) return NULL; // move to left if(root->data > x) { root->left = deleteNode(root->left, x); } // move to right else if(root->data < x) { root->right = deleteNode(root->right, x); } // current node has to delete else { // current node is leaf node if(!root->left && !root->right) { delete root; return NULL; } // current node has only left subtree else if(root->left && !root->right) { Node* temp = root->left; delete root; return temp; } // current node has only right subtree else if(!root->left && root->right) { Node* temp = root->right; delete root; return temp; } // Both left and right subtree exits else { Node* temp = root->left; while(temp->right) temp = temp->right; root->data = temp->data; temp->data = x; root->left = deleteNode(root->left, x); } } // Check for balance int balance = getHeight(root->left) - getHeight(root->right); // Unbalance fix if(balance > 1) { // case L if(getHeight(root->left->right) > getHeight(root->left->left)) { // case LR root->left = leftRotation(root->left); root = rightRotation(root); } else { //case LL root = rightRotation(root); } } else if(balance < -1) { // case R if(getHeight(root->right->right) >= getHeight(root->right->left)) { // case RR root = leftRotation(root); } else { // case RL root->right = rightRotation(root->right); root = leftRotation(root); } } // update height root->height = max(getHeight(root->left), getHeight(root->right)) + 1; // balance tree return return root; }
@ybyewhy94098 ай бұрын
yes teach also the remaining advance topic
@tripurarisen436213 күн бұрын
Chamak gaya sir ji
@chanchalsoni75356 ай бұрын
ek hi dil h dost...kitni baar jeetoge☺
@nonstopcodingcodewithadity82389 ай бұрын
Good morning bro 😅aaj maths exam hai but apka lecture dhak raha fail huga aaj tho padhne ka fayada nhi maths tho dsa kar raha
@SurajGupta-ux2se7 ай бұрын
yes bhaiya please make videos on tries, segment trees as well
@ankushladani4969 ай бұрын
Tries padhao Segment tree Fenwick tree Padhao....🎉🎉
@AyushSingh-le1co9 ай бұрын
Ha bhaiya tries bhi padhaiyega
@NitinSingh-zy8io7 ай бұрын
please teach more advance topic like segment tree, trie, red and black tree and more topics like this
@Aniruddha_Mukherjee9 ай бұрын
Good morning bhaiya ji😍
@CoderArmy99 ай бұрын
Good Morning bhai
@rocketgamerzz.75776 ай бұрын
Like button for bhaiyya to teach red black tree also :)
@ankushladani4969 ай бұрын
Thanks Bhaiya...❤🎉
@sabiruddinkhan49617 күн бұрын
Haa bhaiya padhna hai segment tree,dp and all
@Piyush_sahu.19 ай бұрын
Bhaiya love so much Views kam hogaye as compared to 1st video compitition kam hogaya apne appp
@dhruv121512 ай бұрын
Mza aa gya
@AMITKUMAR-ds4hp9 ай бұрын
Good morning boss ❤
@VINAYKUMAR-zo4pb9 ай бұрын
Bhaiya Graph and DP kab start hoga174 days ho gaye waise extra time bhi lage toh please kara dena 🤗
@LuckyPanwar_00019 ай бұрын
Sir lectures kb tk nhi aayenge??
@ankushladani4969 ай бұрын
Done Bhaiya... Day 174/180 ✅
@laganmittal74425 ай бұрын
we need tries , segment tree and primary video too
@anupammishra65149 ай бұрын
Good morning brother 🌞❤
@CoderArmy99 ай бұрын
Good Morning
@nonstopcodingcodewithadity82389 ай бұрын
Kha se ho aap?
@gurtegsinghsohi4114 ай бұрын
@@CoderArmy9 Hi , can someone please find logical error in my code .. i even tried to debug with chatgpt and also dry run many times but still error is coming For Input: 54 44 86 43 46 78 88 N N N 50 61 83 N 89 8 46 86 88 61 89 78 54 83 Your Code's output is: Unbalanced BST, inorder traversal : 43 44 50 54 78 83 89 It's Correct output is: 43 44 50 Output Difference Unbalanced BST, inorder traversal : 43 44 50 54 78 83 89 CODE ----------------------- int getheight(Node* root){ if(root==NULL){ return 0; } return root->height; } int check(Node* root){ return getheight(root->left) - getheight(root->right); } Node* rrotate(Node* root){ Node* child = root->left; Node* cr = child->right; child->right = root; root->left = cr; root->height = 1 + max(getheight(root->left),getheight(root->right)); child->height = 1 + max(getheight(child->left),getheight(child->right)); return child; } Node* lrotate(Node* root){ Node* child = root->right; Node* cl = child->left; child->left = root; root->right = cl; root->height = 1 + max(getheight(root->left),getheight(root->right)); child->height = 1 + max(getheight(child->left),getheight(child->right)); return child; } Node* deleteNode(Node* root, int k) { if(!root){ return NULL; } if(root->data > k){ root->left = deleteNode(root->left,k); }else if(root->data < k){ root->right = deleteNode(root->right,k); }else{ if(root->left == NULL && root->right == NULL){ delete root; return NULL; } else if(!root->left && root->right){ Node* temp = root->right; delete root; return temp; }else if(!root->right && root->left){ Node* temp =root->left; delete root; return temp; }else{ Node* temp = root->right; while(temp->left){ temp = temp ->left; } root->data = temp->data; root->right = deleteNode(root->right,temp->data); } root->height = 1 + max(getheight(root->left),getheight(root->right)); int b = check(root); if(b>1){ if(check(root->left)>=0){ return rrotate(root); }else{ root->left = lrotate(root->left); return rrotate(root); } }else if(b < -1){ if(check(root->right)right = rrotate(root->right); return lrotate(root); } }else{ return root; } }
@Aniruddha_Mukherjee9 ай бұрын
Ji bhaiya ji Hume advanced topics sikhna hain. Aap wo bhi hum logo ko sikha dijiye.
@yadiencollection50739 ай бұрын
Ram ram bhaiya ❤
@CoderArmy99 ай бұрын
Ram Ram Bhai
@kartikverma69889 ай бұрын
Yes bhaiya ❤❤
@ayushmaanyadav7229 ай бұрын
Bhaiya c language ke baad c++ chalu kare ya fir sidhe 180 days hard me ghus jai .please reply
@enghimanshu9 ай бұрын
direct 180 karo c++ coverd hai esme
@ayushmaanyadav7229 ай бұрын
@@enghimanshu nahi mai puch raha hu pehle c karne chaie ke usko chodke sidhe c++ kare
@enghimanshu9 ай бұрын
@@ayushmaanyadav722 direct jump to the playlist sab kuch covered h...c ki koi need nahi h
@Ankitakumari-t5q9 ай бұрын
good morning Bhaiya
@CoderArmy99 ай бұрын
Good Morning
@binauralbeats-relaxingmusi43369 ай бұрын
Dsa notes me page no 35 me. Num=0; Cout
@adarsh_kumar_sharma_86389 ай бұрын
whose notes is this from where you get it
@allinonemoviesyt9 ай бұрын
good morning bhaiya ji
@asad_iliyas9 ай бұрын
Bhaiya DSA series kab tak complete ho jayegi?
@kartikverma69889 ай бұрын
Thank you 🎉🎉🎉
@ManmohanTiwari-tm5tt9 ай бұрын
bhaiya ye playlist kab tak khatam hoga please bata dijiye
@SmritiSharma-vv7ib3 ай бұрын
we want tries segment tree pleaseeeee
@rajeshpatel80829 ай бұрын
Bhaiya aur konse konse topic bache hai Love you ❤
@ankushladani4969 ай бұрын
Bhaiya mene try Kiya and I think Mera logic sahi hoga. Let's see in video. 😅
@gurtegsinghsohi4114 ай бұрын
Hi , can someone please find logical error in my code .. i even tried to debug with chatgpt and also dry run many times but still error is coming For Input: 54 44 86 43 46 78 88 N N N 50 61 83 N 89 8 46 86 88 61 89 78 54 83 Your Code's output is: Unbalanced BST, inorder traversal : 43 44 50 54 78 83 89 It's Correct output is: 43 44 50 Output Difference Unbalanced BST, inorder traversal : 43 44 50 54 78 83 89 CODE ----------------------- int getheight(Node* root){ if(root==NULL){ return 0; } return root->height; } int check(Node* root){ return getheight(root->left) - getheight(root->right); } Node* rrotate(Node* root){ Node* child = root->left; Node* cr = child->right; child->right = root; root->left = cr; root->height = 1 + max(getheight(root->left),getheight(root->right)); child->height = 1 + max(getheight(child->left),getheight(child->right)); return child; } Node* lrotate(Node* root){ Node* child = root->right; Node* cl = child->left; child->left = root; root->right = cl; root->height = 1 + max(getheight(root->left),getheight(root->right)); child->height = 1 + max(getheight(child->left),getheight(child->right)); return child; } Node* deleteNode(Node* root, int k) { if(!root){ return NULL; } if(root->data > k){ root->left = deleteNode(root->left,k); }else if(root->data < k){ root->right = deleteNode(root->right,k); }else{ if(root->left == NULL && root->right == NULL){ delete root; return NULL; } else if(!root->left && root->right){ Node* temp = root->right; delete root; return temp; }else if(!root->right && root->left){ Node* temp =root->left; delete root; return temp; }else{ Node* temp = root->right; while(temp->left){ temp = temp ->left; } root->data = temp->data; root->right = deleteNode(root->right,temp->data); } root->height = 1 + max(getheight(root->left),getheight(root->right)); int b = check(root); if(b>1){ if(check(root->left)>=0){ return rrotate(root); }else{ root->left = lrotate(root->left); return rrotate(root); } }else if(b < -1){ if(check(root->right)right = rrotate(root->right); return lrotate(root); } }else{ return root; } }
@Manav001219 ай бұрын
bhaiya logic toh samagh aa gaya hai but code thodi si bda hone ke karan problem aa rhi hai apne se implement karne me
@MdShoaib-nk2im9 ай бұрын
hello bhaiya, after dsa which cource you start
@codewithlarry35589 ай бұрын
Bhaiya web development course KZbin mai ayey ga kya?
@aryachauhan61189 ай бұрын
bhaiya trie aur sliding window bhi pdha dena
@YashSaini0079 ай бұрын
Bhaiya Radhe Radhe 🙏
@CoderArmy99 ай бұрын
Radhe Radhe bhai
@soumilkhanna91779 ай бұрын
bhaiya please teach tries also
@deep_singh019 ай бұрын
Day 174/180 👍👍
@suplexshivam9 ай бұрын
Bhaiya agr thoda aur pehle aa jata ye video to mera exam hogya hota acha😅
@susmoy43859 ай бұрын
148 k bad k assignment kaha hai ???
@saumyachauhan1747 ай бұрын
🔥🔥
@ysh___888 ай бұрын
Bhai I'm starting my coding journey.i have never done this before will it ok if start directly from this or do i need to learn full concept of c++ first
@CoderArmy98 ай бұрын
DSA in C++ wali playlist ko follow karo, Udhr sab starting se hai, C++ bhi basic se padaya hai
@ysh___888 ай бұрын
@@CoderArmy9 thanks bhaiya
@vishalboudhh9 ай бұрын
Bhaiya DSA ki series m aur kitne videos bache hai
@gurtegsinghsohi4114 ай бұрын
Hi , can someone please find logical error in my code .. i even tried to debug with chatgpt and also dry run many times but still error is coming For Input: 54 44 86 43 46 78 88 N N N 50 61 83 N 89 8 46 86 88 61 89 78 54 83 Your Code's output is: Unbalanced BST, inorder traversal : 43 44 50 54 78 83 89 It's Correct output is: 43 44 50 Output Difference Unbalanced BST, inorder traversal : 43 44 50 54 78 83 89 CODE ----------------------- int getheight(Node* root){ if(root==NULL){ return 0; } return root->height; } int check(Node* root){ return getheight(root->left) - getheight(root->right); } Node* rrotate(Node* root){ Node* child = root->left; Node* cr = child->right; child->right = root; root->left = cr; root->height = 1 + max(getheight(root->left),getheight(root->right)); child->height = 1 + max(getheight(child->left),getheight(child->right)); return child; } Node* lrotate(Node* root){ Node* child = root->right; Node* cl = child->left; child->left = root; root->right = cl; root->height = 1 + max(getheight(root->left),getheight(root->right)); child->height = 1 + max(getheight(child->left),getheight(child->right)); return child; } Node* deleteNode(Node* root, int k) { if(!root){ return NULL; } if(root->data > k){ root->left = deleteNode(root->left,k); }else if(root->data < k){ root->right = deleteNode(root->right,k); }else{ if(root->left == NULL && root->right == NULL){ delete root; return NULL; } else if(!root->left && root->right){ Node* temp = root->right; delete root; return temp; }else if(!root->right && root->left){ Node* temp =root->left; delete root; return temp; }else{ Node* temp = root->right; while(temp->left){ temp = temp ->left; } root->data = temp->data; root->right = deleteNode(root->right,temp->data); } root->height = 1 + max(getheight(root->left),getheight(root->right)); int b = check(root); if(b>1){ if(check(root->left)>=0){ return rrotate(root); }else{ root->left = lrotate(root->left); return rrotate(root); } }else if(b < -1){ if(check(root->right)right = rrotate(root->right); return lrotate(root); } }else{ return root; } }
@aaryan51799 ай бұрын
Bhaiya mere ek question hai aapse ki ye DSA course kb tk completre hoga, aap koi approx date bta skte ho kya???
@AkashDeep1271-f9w9 ай бұрын
Maan kr chalo next 2 month Mai complete ho Jaye ga
@AbdurRahimIIITK9 ай бұрын
Hii. Mai C se basic DSA kr rha hu. Mai vacation me C++ se krna cha rha hu.Rohit Bhaiya ka ya babbar bhaiya ka sahi rahega kya ? Anyone plz...
@gopalmalpani19479 ай бұрын
rohit negi is best from all paid courses
@AbdurRahimIIITK9 ай бұрын
@@gopalmalpani1947 which one is best Love babbar Or Rohit bhaiya
@SmritiSharma-vv7ib3 ай бұрын
@@AbdurRahimIIITK depends on your grasping skills try one topic of both then accordingly choose one which suits u more. Its rohit bhaiya for me coz m babbar sir ka course chd k inse pdhne ai thi
@alishagoel1849 ай бұрын
Bhayia logics nahi lag rahi
@kartikverma69889 ай бұрын
🎉🎉🎉
@positivevibes-f2j8 ай бұрын
We need advance dsa
@fire78749 ай бұрын
❤❤
@YashSaini0079 ай бұрын
Day 174/180 #180DaysOfCode
@hiteshsharma50347 ай бұрын
Anyone Who can find my error and inform me...😐😐😐 only 13 Testcases passed.. int get_height(Node* root){ if(!root){ return 0; } return root->height; } //Right Rotation Node* rightRotation(Node* &root){ Node* child=root->left; Node* childRight=child->right; child->right=root; root->left=childRight;//adding right child of middle to updated top left(edge case) root->height=1+max(get_height(root->left),get_height(root->right)); child->height=1+max(get_height(child->left),get_height(child->right)); return child; } //Left Noation Node* leftRotation(Node* &root){ Node* child=root->right; Node* childLeft=child->left; child->left=root; root->right=childLeft; child->height=1+max(get_height(child->left),get_height(child->right)); root->height=1+max(get_height(root->left),get_height(root->right)); return child; } int get_bal(Node* root){ return get_height(root->left)-get_height(root->right); } Node* deleteNode(Node* root, int key) { if(!root) return NULL; //exists if(root->data > key){ root->left=deleteNode(root->left,key); } else if(root->data < key){ root->right=deleteNode(root->right, key); } else{ //when key is equal to root->data, hence we have to delete the node //leaf Node; if(!root->left && !root->right){ delete (root); return NULL; } //only one child else if(!root->left && root->right){ //only right exists Node* temp=root->right; delete (root); return temp; } else if(!root->right && root->left){ //only left exists Node* temp=root->left; delete(root); return temp; } //both childs exits else{ //right se smallest leke aoo Node* temp=root->right; while(temp->left){ temp=temp->left; } root->data=temp->data; root->right=deleteNode(root->right,temp->data); //mine confusion point } } //end of else root->height=1+max(get_height(root->left),get_height(root->right)); int balance=get_bal(root); if(balance>1){ //left side me dikkat hai //LL if(get_bal(root->left)>=0){ return rightRotation(root); } //LR else{ root->left=leftRotation(root->left); return rightRotation(root); } } else if(balanceright)right=rightRotation(root->right); return leftRotation(root); } } else{ return root; } }
@harshitpatil61387 ай бұрын
In left Rotation part try to first update root height then child height and passed root without reference
@hiteshsharma50347 ай бұрын
@@harshitpatil6138 ok Bro thankyou, Let me this Updated solution
@gurtegsinghsohi4114 ай бұрын
@@harshitpatil6138 Hi , can someone please find logical error in my code .. i even tried to debug with chatgpt and also dry run many times but still error is coming For Input: 54 44 86 43 46 78 88 N N N 50 61 83 N 89 8 46 86 88 61 89 78 54 83 Your Code's output is: Unbalanced BST, inorder traversal : 43 44 50 54 78 83 89 It's Correct output is: 43 44 50 Output Difference Unbalanced BST, inorder traversal : 43 44 50 54 78 83 89 CODE ----------------------- int getheight(Node* root){ if(root==NULL){ return 0; } return root->height; } int check(Node* root){ return getheight(root->left) - getheight(root->right); } Node* rrotate(Node* root){ Node* child = root->left; Node* cr = child->right; child->right = root; root->left = cr; root->height = 1 + max(getheight(root->left),getheight(root->right)); child->height = 1 + max(getheight(child->left),getheight(child->right)); return child; } Node* lrotate(Node* root){ Node* child = root->right; Node* cl = child->left; child->left = root; root->right = cl; root->height = 1 + max(getheight(root->left),getheight(root->right)); child->height = 1 + max(getheight(child->left),getheight(child->right)); return child; } Node* deleteNode(Node* root, int k) { if(!root){ return NULL; } if(root->data > k){ root->left = deleteNode(root->left,k); }else if(root->data < k){ root->right = deleteNode(root->right,k); }else{ if(root->left == NULL && root->right == NULL){ delete root; return NULL; } else if(!root->left && root->right){ Node* temp = root->right; delete root; return temp; }else if(!root->right && root->left){ Node* temp =root->left; delete root; return temp; }else{ Node* temp = root->right; while(temp->left){ temp = temp ->left; } root->data = temp->data; root->right = deleteNode(root->right,temp->data); } root->height = 1 + max(getheight(root->left),getheight(root->right)); int b = check(root); if(b>1){ if(check(root->left)>=0){ return rrotate(root); }else{ root->left = lrotate(root->left); return rrotate(root); } }else if(b < -1){ if(check(root->right)right = rrotate(root->right); return lrotate(root); } }else{ return root; } }
@gurtegsinghsohi4114 ай бұрын
Hi , can someone please find logical error in my code .. i even tried to debug with chatgpt and also dry run many times but still error is coming For Input: 54 44 86 43 46 78 88 N N N 50 61 83 N 89 8 46 86 88 61 89 78 54 83 Your Code's output is: Unbalanced BST, inorder traversal : 43 44 50 54 78 83 89 It's Correct output is: 43 44 50 Output Difference Unbalanced BST, inorder traversal : 43 44 50 54 78 83 89 CODE ----------------------- int getheight(Node* root){ if(root==NULL){ return 0; } return root->height; } int check(Node* root){ return getheight(root->left) - getheight(root->right); } Node* rrotate(Node* root){ Node* child = root->left; Node* cr = child->right; child->right = root; root->left = cr; root->height = 1 + max(getheight(root->left),getheight(root->right)); child->height = 1 + max(getheight(child->left),getheight(child->right)); return child; } Node* lrotate(Node* root){ Node* child = root->right; Node* cl = child->left; child->left = root; root->right = cl; root->height = 1 + max(getheight(root->left),getheight(root->right)); child->height = 1 + max(getheight(child->left),getheight(child->right)); return child; } Node* deleteNode(Node* root, int k) { if(!root){ return NULL; } if(root->data > k){ root->left = deleteNode(root->left,k); }else if(root->data < k){ root->right = deleteNode(root->right,k); }else{ if(root->left == NULL && root->right == NULL){ delete root; return NULL; } else if(!root->left && root->right){ Node* temp = root->right; delete root; return temp; }else if(!root->right && root->left){ Node* temp =root->left; delete root; return temp; }else{ Node* temp = root->right; while(temp->left){ temp = temp ->left; } root->data = temp->data; root->right = deleteNode(root->right,temp->data); } root->height = 1 + max(getheight(root->left),getheight(root->right)); int b = check(root); if(b>1){ if(check(root->left)>=0){ return rrotate(root); }else{ root->left = lrotate(root->left); return rrotate(root); } }else if(b < -1){ if(check(root->right)right = rrotate(root->right); return lrotate(root); } }else{ return root; } }
@gurtegsinghsohi4114 ай бұрын
Hi , can someone please find logical error in my code .. i even tried to debug with chatgpt and also dry run many times but still error is coming For Input: 54 44 86 43 46 78 88 N N N 50 61 83 N 89 8 46 86 88 61 89 78 54 83 Your Code's output is: Unbalanced BST, inorder traversal : 43 44 50 54 78 83 89 It's Correct output is: 43 44 50 Output Difference Unbalanced BST, inorder traversal : 43 44 50 54 78 83 89 CODE ----------------------- int getheight(Node* root){ if(root==NULL){ return 0; } return root->height; } int check(Node* root){ return getheight(root->left) - getheight(root->right); } Node* rrotate(Node* root){ Node* child = root->left; Node* cr = child->right; child->right = root; root->left = cr; root->height = 1 + max(getheight(root->left),getheight(root->right)); child->height = 1 + max(getheight(child->left),getheight(child->right)); return child; } Node* lrotate(Node* root){ Node* child = root->right; Node* cl = child->left; child->left = root; root->right = cl; root->height = 1 + max(getheight(root->left),getheight(root->right)); child->height = 1 + max(getheight(child->left),getheight(child->right)); return child; } Node* deleteNode(Node* root, int k) { if(!root){ return NULL; } if(root->data > k){ root->left = deleteNode(root->left,k); }else if(root->data < k){ root->right = deleteNode(root->right,k); }else{ if(root->left == NULL && root->right == NULL){ delete root; return NULL; } else if(!root->left && root->right){ Node* temp = root->right; delete root; return temp; }else if(!root->right && root->left){ Node* temp =root->left; delete root; return temp; }else{ Node* temp = root->right; while(temp->left){ temp = temp ->left; } root->data = temp->data; root->right = deleteNode(root->right,temp->data); } root->height = 1 + max(getheight(root->left),getheight(root->right)); int b = check(root); if(b>1){ if(check(root->left)>=0){ return rrotate(root); }else{ root->left = lrotate(root->left); return rrotate(root); } }else if(b < -1){ if(check(root->right)right = rrotate(root->right); return lrotate(root); } }else{ return root; } }
@4minix6433 ай бұрын
Bro u haven't closed your first else block ... close that first before updating height and rotations
@gurtegsinghsohi4114 ай бұрын
Hi , can someone please find logical error in my code .. i even tried to debug with chatgpt and also dry run many times but still error is coming For Input: 54 44 86 43 46 78 88 N N N 50 61 83 N 89 8 46 86 88 61 89 78 54 83 Your Code's output is: Unbalanced BST, inorder traversal : 43 44 50 54 78 83 89 It's Correct output is: 43 44 50 Output Difference Unbalanced BST, inorder traversal : 43 44 50 54 78 83 89 CODE ----------------------- int getheight(Node* root){ if(root==NULL){ return 0; } return root->height; } int check(Node* root){ return getheight(root->left) - getheight(root->right); } Node* rrotate(Node* root){ Node* child = root->left; Node* cr = child->right; child->right = root; root->left = cr; root->height = 1 + max(getheight(root->left),getheight(root->right)); child->height = 1 + max(getheight(child->left),getheight(child->right)); return child; } Node* lrotate(Node* root){ Node* child = root->right; Node* cl = child->left; child->left = root; root->right = cl; root->height = 1 + max(getheight(root->left),getheight(root->right)); child->height = 1 + max(getheight(child->left),getheight(child->right)); return child; } Node* deleteNode(Node* root, int k) { if(!root){ return NULL; } if(root->data > k){ root->left = deleteNode(root->left,k); }else if(root->data < k){ root->right = deleteNode(root->right,k); }else{ if(root->left == NULL && root->right == NULL){ delete root; return NULL; } else if(!root->left && root->right){ Node* temp = root->right; delete root; return temp; }else if(!root->right && root->left){ Node* temp =root->left; delete root; return temp; }else{ Node* temp = root->right; while(temp->left){ temp = temp ->left; } root->data = temp->data; root->right = deleteNode(root->right,temp->data); } root->height = 1 + max(getheight(root->left),getheight(root->right)); int b = check(root); if(b>1){ if(check(root->left)>=0){ return rrotate(root); }else{ root->left = lrotate(root->left); return rrotate(root); } }else if(b < -1){ if(check(root->right)right = rrotate(root->right); return lrotate(root); } }else{ return root; } }