Тёмный
No video :(

Top view of Binary Tree | Bottom view of Binary Tree | Binary Tree Data Structures Java | DSAOne #61 

Anuj Bhaiya
Подписаться 492 тыс.
Просмотров 62 тыс.
50% 1

Hey guys, In this video, We're going to learn how to print the Top View and the Bottom View of a Binary Tree.
Practice here:
practice.geeks...
practice.geeks...
💸 Use coupon code ANUJBHAIYA on GeeksforGeeks to avail discounts on courses!
🥳 Join our Telegram Community:
Telegram channel: telegram.me/re...
Telegram group: telegram.me/ds...
🚀 Follow me on:
Instagram: / anuj.kumar.sharma
Linkedin: / sharma-kumar-anuj
Twitter: / realanujbhaiya
📚 Complete DSA Playlist: • DSA-One Course - The C...
Complete Android Development Playlist: • Android Development Tu...
Hashtags:
#anujbhaiya #dsaone
Tags:
top view of binary tree
bottom view of binary tree
top view of a binary tree
top view
top view binary tree
top view of tree
binary tree in data structure
top view of a tree
binary tree
anuj bhaiya java
left view of binary tree
bottom view of a binary tree
tree in dsa
dsa
tree data structure in java
java anuj bhaiya
java by anuj bhaiya
right view of binary tree
anuj bhai
trees dsa
anuj kumar sharma
binary search tree
binary tree playlists
binary trees
diameter of binary tree
dsp anuj bhaiya
tree dsa
tree traversal in data structure
trees in data structure
vertical order traversal of binary tree
what is binary tree
binary tree data structure
binary tree in java
binary tree playlist
complete binary tree
ishan sharma
love babbar
tree data structure
trees data structure
trees data structures
width of binary tree
aditya verma
akshay saini
arraylist
babbar code help
balanced binary tree
binary search tree in data structure
binary search tree in java
binary search tree java
binary tree c++
binary tree java
binary tree tutorial
bottom view
boundary traversal of binary tree
code help babbar
data structure
diameter of a binary tree
diameter of a tree
diameter of tree
dsa one
dsa sheet
harman singh
invert binary tree
kunal kushwaha
largest bst in bt
longest common subsequence problem
node js
print nodes in top view of binary tree
right side view of a binary tree
seed it solution
top
tree in java
tree topology
treemap
treemap in java
trees in dsa

Опубликовано:

 

21 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 66   
@raghunath4280
@raghunath4280 2 года назад
Nice solution. But i found out a little bit optimization for the above solution. Consider d= horizontal diameter of the tree. Building Treemap takes o(dlogd). Instead of TreeMap use HashMap and maintain two static variables i.e., min and max and update the min and max values as min=Math.min(min,temp.hd); max=Math.max(max,temp.hd); for every iteration. Now traverse the HM from min to max and add those values to a new ArrayList. This will reduce the time complexity from O(n+dlogd) to O(n)
@GhostRider....
@GhostRider.... Год назад
Bro please provide full solution
@yhlive8023
@yhlive8023 Год назад
You're right i been thinking the same bro , use min max and hashmap
@grossHumiliation
@grossHumiliation 9 месяцев назад
bro this is correct? void topView(Node *root, int x, map &m) { if (root == NULL) return; if (m.find(x) == m.end()) { m.insert(make_pair(x, root->data)); } topView(root->left, x - 1, m); topView(root->right, x + 1, m); }
@jerrykodes
@jerrykodes 3 месяца назад
Nice one!
@subhankarpal2800
@subhankarpal2800 2 года назад
Now I can say my Nonlinear Data structure journey has been started with Anuj Bhaiya 🙏🙏🙏🙏🙏 Thank You Sir ❣❣❣❣.
@abdullahirfan3078
@abdullahirfan3078 2 года назад
Never knew that this medium level topic is going to be so easy for me Thank yoy
@Jitendrachouhan1999
@Jitendrachouhan1999 2 года назад
You are Such as Good Mentor 🥰 i really inspired your video when did I watch ❤
@udaychandu3925
@udaychandu3925 Год назад
Very Clean and Neat Explaination,Sir!
@prashantkumarsingh-ui6yp
@prashantkumarsingh-ui6yp 4 месяца назад
, vertical order, top view, bottom view, what an explanation ☺☺☺
@RepublicDay2023
@RepublicDay2023 Год назад
You are genious dude…!!! Applauses 👌👌👌
@tech_wizard9315
@tech_wizard9315 2 года назад
Can you please provide a 60roamdap of important topics for DSA beginner to crack tech giant's like Microsoft linkedin etc
@AnujBhaiya
@AnujBhaiya 2 года назад
This is next in line.. will be coming out soon 😄 stay tuned
@MindsetMotivation75
@MindsetMotivation75 Год назад
Thank you bhaiya , best explanation ever.
@ANJALIGUPTA-vq1cv
@ANJALIGUPTA-vq1cv 2 года назад
awesome bhaiya, thanks for making coding easier
@hangover2.0
@hangover2.0 5 месяцев назад
for implementing the queue method we can define three variables in class third one to store level and in the if condition we will check using or operator that if the level of incoming node is lesser than the already existing node it will replace the node. Please tell me if something is wrong with this approach . Open to other suggestions.
@amanrathour3176
@amanrathour3176 2 года назад
So easily explained 😍. Thanku.
@mma-dost
@mma-dost Месяц назад
Thanks bhaiya
@shreysom2060
@shreysom2060 Год назад
Great explaination
@prannoyroy5312
@prannoyroy5312 2 года назад
Thanks Anuj! Great job bro! 👌
@xerOnn35
@xerOnn35 Год назад
Thanks Sir !
@ImranKhan-mc6vf
@ImranKhan-mc6vf 2 года назад
Not sure if it is the correct logic for bottom view. Consider this example. 7(0) / \ 6 (-1) 2 (1) / \ / \ 5 ( -2 ) 1(0) 8(0) 2 (2) We have 2 0s at bottom, but the map would hold just 1 zero. So your logic would give -> 5, 8, 2 instead of 5,1,8,2. Or am I missing something?
@kumarrohit8311
@kumarrohit8311 2 года назад
See the video at 1:07. He talks about when two elements with same distance are met, we pick the right side one. Hence, 8 is picked up!
@pulkitchausali1354
@pulkitchausali1354 2 года назад
Output will like -> 5, 6, 8, 2, 2
@abhishekanuj8115
@abhishekanuj8115 2 года назад
Few days ago, bhaiya you suggested a youtube channel for learning java from scratch (u told, u also learnt from there) please give that channel link again, I forget that channel name. 🙏🏻
@King-xs4tq
@King-xs4tq 2 года назад
Malum pada bhai
@abhishekanuj8115
@abhishekanuj8115 2 года назад
@@King-xs4tq ni bhai, agr pta chale to btana
@King-xs4tq
@King-xs4tq 2 года назад
@@abhishekanuj8115 Nahi bhai maine to bhaiya ke course se hi pada tha java lekin beginners ke liye utna fayde ka nahi h. Agar aapko malum padey to bataiyega
@saritaprasad4295
@saritaprasad4295 Год назад
amazing with most difficult topic
@GhostRider....
@GhostRider.... Год назад
Nice explanation bhaiya
@harshvardhansingh780
@harshvardhansingh780 2 года назад
Thank you so much bhaiya mai yhi same glti kar rha tha.... thank you
@jeeveshsinghroa3218
@jeeveshsinghroa3218 Год назад
Good Solution!
@anandjaiswal6588
@anandjaiswal6588 Год назад
Maaza aa gaya 😁
@Rorschach_ind
@Rorschach_ind Год назад
This video was helpful!
@militaryink319
@militaryink319 2 года назад
Thanks bhya . I am following you
@lokendrasingh9780
@lokendrasingh9780 2 года назад
Thank You Bhaiya🙏👌
@prateekchauhan5376
@prateekchauhan5376 2 года назад
loveddddd it
@ShivamVerma-gq2sm
@ShivamVerma-gq2sm 2 года назад
wonderful
@madetolaugh3476
@madetolaugh3476 2 года назад
Largest BST
@shivamchaurasiya2004
@shivamchaurasiya2004 2 года назад
Bhaiyaa DevOps par ek video banaiye isme career kaise banaye
@rahulji882
@rahulji882 2 года назад
22nd link
@kanaramjangid8563
@kanaramjangid8563 Месяц назад
❤❤❤
@YashTalks_YT
@YashTalks_YT 2 года назад
many teachers can't even accept their mistakes
@shaileshtiwari9570
@shaileshtiwari9570 Год назад
why we don't take preorder traversal for bottom view , kindly give a tree example where preorder traversal gives wrong answer.
@harishlodha8794
@harishlodha8794 2 года назад
Sir background video recorder app se user Jo video record karta hai kya vo video app Wale ke pass bhi store hota hai kya Kya ye possible hai ki Jo video hum record karte hain vo app Wale ke pass bhi store hota hai kya
@mohakarora8712
@mohakarora8712 5 месяцев назад
can somebody tell me why are we using level order only?
@wizardiors
@wizardiors 2 года назад
did u have a computer science degree??
@sumitchakraborty9451
@sumitchakraborty9451 Год назад
what is the time complexity of this solution
@mastimazawithnature6749
@mastimazawithnature6749 2 года назад
Is dsa course me kya sikhne ko milega
@AnujBhaiya
@AnujBhaiya 2 года назад
You'll learn almost anything there's to learn about Data Structures & Algorithms so that you can crack Top companies technical interviews easily. Many of you have already done it. Best of Luck 🤗
@akashmishra3369
@akashmishra3369 2 года назад
Bhaiya, TreeMap nahi use karke, Map ko sort kardein end me to kaam nahi banega ? :( (Not sure how to implement Treemap in javascript)
@AnujBhaiya
@AnujBhaiya 2 года назад
Ho jaega usse bhi
@lakhanshanker6105
@lakhanshanker6105 2 года назад
static ArrayList topView(Node root) { Map map = new TreeMap(); int i=0; util(root,i,map); ArrayList ans = new ArrayList(); for(Map.Entry m : map.entrySet()){ int x = m.getValue(); ans.add(x); } public static void util(Node root, int i, Map map){ if(root==null) return; if(!map.containsKey(i)){ map.put(i,root.data); } util(root.left,i-1,map); util(root.right,i+1,map); } isme kya galti hai anyone ?
@pratikvishwakarma1599
@pratikvishwakarma1599 2 года назад
ans.add(x); } } you need to close extra } , :P Otherwise check the video again on 04:05, where Anuj Bhaiya explains why normal traversal (preorder) will fail
@lakhanshanker6105
@lakhanshanker6105 2 года назад
@@pratikvishwakarma1599 bhai wo to thek h pr sare test cases pass nhi ho rhe
@harshit4190
@harshit4190 2 года назад
time complexity?
@antibarcelona2123
@antibarcelona2123 Год назад
O(no. of nodes i guess)
@worldpuzzle1031
@worldpuzzle1031 2 года назад
❤️❤️
@RajatGupta-lq3cb
@RajatGupta-lq3cb 2 года назад
Can someone help me. What if we solve it in this way using DFS? class Solution { static int min=0, max=0; static ArrayList topView(Node root) { ArrayList res=new ArrayList(); Map mp=new HashMap(); helper(root, mp, 0, 0); for(int i=min;i vd) { mp.put(hd, new Pair(root.data, vd)); } } else { mp.put(hd, new Pair(root.data, vd)); } helper(root.left, mp, hd-1, vd+1); helper(root.right, mp, hd+1, vd+1); } } class Pair { int val, vd;// vd represents vertical distance from root AKA depth. public Pair(int a, int b) { val=a; vd=b; } }
@yhlive8023
@yhlive8023 Год назад
It will be complicated bro but it's your choice how you want to do 😊
@mastimazawithnature6749
@mastimazawithnature6749 2 года назад
Binary code kya hota hai Kya isse me kya kr sakta hu
@harsh_choudhary5940
@harsh_choudhary5940 2 года назад
@Kumar Chitransh abe😂😂
@yhlive8023
@yhlive8023 Год назад
​@Kumar Chitransh 😂
@manojkhan5639
@manojkhan5639 Год назад
Thanks bhiya
@pinkkitty6553
@pinkkitty6553 Год назад
Thank you bhaiya
Далее
would you eat this? #shorts
00:29
Просмотров 1,1 млн
10.1 AVL Tree - Insertion and Rotations
43:08
Просмотров 1,1 млн
Tree Implementation in Java | DSA
17:03
Просмотров 38 тыс.