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

  • SEARCH
  • Home
  • 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 8521323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:47:28+00:00 2026-06-11T06:47:28+00:00

I have a expression like ((2+8)*8)-(5*(5+2)) Or + 2 + 1 1 . And

  • 0

I have a expression like ((2+8)*8)-(5*(5+2)) Or + 2 + 1 1 . And I want to make a binary tree in that .

  +
 / \
2   +
   / \
  1   1

How can I Make this Binary tree?

  • 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-11T06:47:30+00:00Added an answer on June 11, 2026 at 6:47 am

    I had a similar project, and this is how I did it:

    1. Tokenize the string. See what each symbol is. For example, the list may contain:

      '(' Open parantheses
      '11' Number
      '+' Operator etc
    2. Convert the expression to postfix (or prefix if you want) notation. One algorithm that can do that is called the Shunting Yard algorithm. The advantage of postfix notation is that you can evaluate the expression much easier, using a stack-based method (or binary tree if you want).

    3. Evaluate the postfix expression. You can do it in two ways, a binary tree and stack.

    Stack evaluation:

    Your example expression converted in postfix notation will look like this:

    2 8 + 8 * 5 5 2 + * -
    

    Evaluating works like this: When you encounter a number, push it on the stack. When you encounter an operator, pop 2 items from the stack, make the calculation, and push the result on the stack. In the end, you should be left with the final result.

    For the example above, this is what we will do:

    Push 2 [Stack content: 2]
    Push 8 [2 8]
    Pop 2 and 8 []
    Push 2+8 [10]
    Push 8 [10 8]
    Pop 10 and 8 []
    Push 10*8 [80]
    Push 5 [80 5]
    Push 5 [80 5 5]
    Push 2 [80 5 5 2]
    Pop 2 and 5 [80 5]
    Push 2 + 5 [80 5 7]
    Pop 7 and 5 [80]
    Push 7 * 5 [80 35]
    Pop 80 and 35 []
    Push 80 - 35 [45]
    Final result is 45.
    

    Binary tree

    This is how I would do it: just like the stack based approach, use a stack of nodes. When you encounter an operator, you pop 2 items from the stack, but instead of evaluating, you create a node with the operator, and make it the parent of the 2 popped items. Then you push the node back on the stack.

    The disadvantage of this approach is that you have an additional step: creating the tree.

    Final notes

    This is the method I would use. Maybe there are more efficient methods than this, but this is how I would do it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I have something like this in NHibernate: Expression.Like(property, value, MatchMode.Anywhere) and that
I have a data that looks like this 1:SRX000566 Submitter: WoldLab Study: RNASeq expression
So I have a set of data that can look like this (sample line-by-line):
I have a string like that : 0d(Hi)i(Hello)4d(who)i(where)540d(begin)i(began) And i want to make it
I have a nHibernate query like this ICriteria query = session.CreateCriteria(typeof(MyResult)) .Add(Expression.Eq(ResultTypeId, myResult.ResultTypeId)) Problem
I have a GridView what I fill through a LINQ expression. Something like this:
I have a XAML file that I exported from Expression Design. I would like
Suppose I have a few lines out of wikipedia XML that looks like this:
I have a regular expression to match filenames which look like this: name -
Suppose I have an HTML page that looks something like this: <html><body> 00123 <input

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.