•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,453 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,639 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 827 | Replies: 1
![]() |
•
•
Join Date: Mar 2008
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
Dear all,
I need to find the max width of Binary Search Tree. It means the biggest number of nodes in a level among all levels.
http://www.imgloadtr.com/pics/aca410...5721df328a.jpg
In the figure the maximum width is 4, since level 3 has the biggest number of nodes, which is 4.
I will be grateful, if you help me..
I need to find the max width of Binary Search Tree. It means the biggest number of nodes in a level among all levels.
http://www.imgloadtr.com/pics/aca410...5721df328a.jpg
In the figure the maximum width is 4, since level 3 has the biggest number of nodes, which is 4.
I will be grateful, if you help me..
I can think of two simple solutions off the top of my head:
1) Allocate an array of N, where N is the number of nodes in the tree. Then traverse the tree and save the level of each node in the array as you go. Sort the array and the longest run will be the level with the most nodes.
2) Perform a level-order traversal of the tree and count how many nodes are on each level. Save the largest value as you go down, and when you get to the end, you'll have the level with the most nodes.
1) Allocate an array of N, where N is the number of nodes in the tree. Then traverse the tree and save the level of each node in the array as you go. Sort the array and the longest run will be the level with the most nodes.
2) Perform a level-order traversal of the tree and count how many nodes are on each level. Save the largest value as you go down, and when you get to the end, you'll have the level with the most nodes.
I'm here to prove you wrong.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
adsense adult advertising biometrics blogging bomb book business coding copyright cult of the dead cow data development engine environment failure forum google hacking internet legal malware marketing mcafee microsoft monetization msn news operating pagerank people-powered phishing photo privacy publishing revenue search security seo sex silverlight software spyware support system technical web webmaster wiki yahoo
- Previous Thread: can't find the problem after checking my similar programs
- Next Thread: how to code ATM for banks



Linear Mode