Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9116483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:41:01+00:00 2026-06-17T04:41:01+00:00

I want to traverse a Binary Tree with minimum cost, where cost of each

  • 0

I want to traverse a Binary Tree with minimum cost, where cost of each edge is 1.
Traversal is complete when each node of the tree is visited.

For instance, the minimum cost of the traversal of following tree is 13.

       *
      / \
     *   *
    / \   \
   *   *   *
  /   /     \
 *   *       *

the minimum cost of the traversal of following tree is 12.

        *
       / \
      *   *
     / \   \
    *   *   *
   /     \
  *       *
 /
*
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:41:02+00:00Added an answer on June 17, 2026 at 4:41 am

    The cost of traversing the tree is n-1 where n is the number of nodes.

    This is true because every tree has exactly n-1 edges – and you need to use all of them in order to visit all the nodes.


    To be exact it is known that the next 3 statements are equivalent for a graph T with n nodes:

    1. T is a tree (connected without cycles)
    2. T is connected and has n-1 edges
    3. T has no cycle and has n-1 edges

    From the above we can conclude, that in a tree, in order to get to all nodes we must use all edges (because there are no cycles, so no redundant edges) – and there are EXACTLY n-1 of those.


    EDIT:

    From your example it seems you are also counting the times you go back from each edge (i.e. some edges are counted twice).

    Well, in this case the optimal solution will be:

    cost = (n-1)*2 - height
    

    Explanation/proof guidelines:

    There are n-1 edges exactly in the tree. Each of them is traversed exactly twice except those that leads from the root to the deepest node.

    You must use each edge (except the mentioned) exactly twice, because with exception of the last branch – you go back from each node.

    Since there are exactly height edges in the last branch, you get total of cost = (n-1)*2 - height

    Note that it is basically the same as you got:

    height + 2*(n-1-height) = height + 2(n-1) -2height = 2(n-1) - height
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am currently implementing a binary tree in c++ and i want to traverse
I have the following tree: 1-[HAS]->2-[HASSUBPAGE]->3-[HASSUBPAGE]->4 Now I want to traverse this tree starting
I'm having the following issue - I want to traverse all the xml files
I want to traverse a DOM tree from a resultText string of document.documentElement.innerHTML using
In the following code I want to traverse an NSMutableArray (self.codes) which contains NSMutableDictionary
I'm making a View with customized traversal. I want to traverse to next object
I am using javascript and want to traverse the HTML tree, getting all the
I made a simple program in C# to add a node in binary tree.
I want to traverse through each file in the SD card inside all the
Okay. I have a binary tree, and this is what I want to do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.