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 144915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:19:49+00:00 2026-05-11T08:19:49+00:00

I’m doing a unit called Data Structures and Algorithms. We’ve just started and my

  • 0

I’m doing a unit called Data Structures and Algorithms. We’ve just started and my professor has just taught us the basics of what Algebraic Semantics is and what Axioms are etc. Till now, I’ve just used Trees in the form of arrays. Not using the signature for pre-ordered tree as tree(value, tree, tree) where value is the value in the node, left node is the first tree and right node is the second tree.

Now that i’m defining my tree as either tree(value, tree, tree) or Nil, I can’t figure out how to go about defining the algebra for addNode(value, tree).

It just gets more and more complicated with each level, plus, I can’t possibly think of anyway to scan through one level as once, been trying since like an hour now. The algebra just branches out into more and more if-elses as we go down the tree. Am I doing it right? Can you point me in the right direction? Or trees cannot be implemented as tree(value, tree, tree)?

It’s a part of my tutorial(not worth any marks, in the additional questions), but I’m not looking for an instant answer, I like the subject, and would like to learn more.

Edit 1: I checked out Wikipedia, and I don’t want to use the textbook for the clear answer, I’m just looking for a hint towards the right direction, whether my approach is right or it’s completely impossible to define a tree as tree(value, tree, tree). I know you can represent a tree ADT in form a list. But I wanted to really think about it. Hope it makes sense. Thanks a lot guys!

Edit 2: Uhmm, it’s hard to explain over the internet. Let’s say I’m defining a new data structure called ‘tree’. I can define it any way I want, and it must behave like a balanced binary tree(though, values of parents and children dont matter) So I define it as tree : tree(value, tree, tree) OR nil It’s not programming code, it’s just how I define it. Tree is a value + 2 other trees or Tree is nil. Now addNode(value, tree) adds a node to tree while still keeping it balanced. It’s not programming code, it’s just algebraic semantics. I don’t know if I can explain it properly. But I got to a solution that I can achieve using Queues or Stacks, but that’s another ADT I’ll have to define, which is not valid.

Edit 3: Seems like I had assumed many things that made the problem harder than it really was supposed to be. First of all, from the little explanation I gave, Gamecat’s answer was perfect. But I agree with the comments, it’s perfectly valid to include other ADTs. In fact, when we build anything that uses an Int, we’re using an ADT for that structure. I thought each ADT had to be unique. Anyways, thanks a lot guys for your answers!

  • 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. 2026-05-11T08:19:50+00:00Added an answer on May 11, 2026 at 8:19 am

    If you want to add a node to a tree, you can use a recursive function.

    I assume the tree is ordered. So you should get something like this:

    AddNode(value, tree)  if tree is empty, create a new tree with value as node and no subtrees. if value lesser than the treenode, call AddNode on the left branch. else call AddNode on the right branch. (if duplicates are allowed). 

    Be sure to update the subtrees if they are changed!

    You can convert this to a non recursive function by:

    if tree is empty, return a new tree with value as node and no subtrees. if value is lesser than treenode, and there is no left subtree, create a new left subtree with value as node and no subtrees. if value is lesser that treenode, and there is a left subtree, try again with the left subtree. if value is greater or equal than treenode, and there is no right subtree, create a new right subtree with value as node and no subtrees. if value is greater or equal than treenode, and there is a right subtree, try again with the right subtree. 

    If the tree needs to be balanced. You need to store get a balance weight (which can be -1, 0 or 1). If you need to add a node on a ‘heavy’ site, you need to reshuffle this. For example if the left side has one node more than the right side and you need to add one more node to the left. You need to get the node with the highest value from the left subtree and promote that to the current top. The previous top is added to the right subtree. Be sure to keep the subtrees balanced too.

    Example: add the nodes 0,1,2,3,4

    Add(0)           0  Add(1)           0                   \                    1  Add(2)           0 (2)  =>      1 (2) =>  1                   \            /         / \                    1          0         0   2  Add(3)           1                 / \                0   2                     \                       3  Add(4)           1 (4)     => 2 (4)  =>      2                 / \          / \            / \                0   2        1   3          1   3                     \      /              /     \                      3    0              0       4 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 74k
  • Answers 74k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You can try Meld. It is a wonderful visual diff… May 11, 2026 at 2:31 pm
  • added an answer You'll probably have to make your own fla for it… May 11, 2026 at 2:31 pm
  • added an answer Here is the resulting generated XHTML from your current code:… May 11, 2026 at 2:31 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.