Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

AVL-Tree Balancefactor

Name: cyan 2008-07-10 14:49

ok, to calculate the balancefactor of a binary tree you have to subtract the height of the right subtree from the left subtree...

normally you do something like this:
//tree structure

struct node{
   int val;
   struct node * left, * right;
};

struct node * root = NULL;

//Inserting some numbers
void insert(int a[]){
blablabla;
}

//function returning the height of the tree with root p)
int height(struct node *p){
blablabla;
}

int balancefactor(struct node *p){
   if(!p) return 0;
   return height(p->right)-height(p->left);
}

now check this out:
i have to write a recursive function "balancefactor2" that calculates the balancefactor without calling another function.
How to do it /prog/?

Name: Anonymous 2008-07-10 14:54

int SICP(){
    read;
}

Name: Anonymous 2008-07-10 14:56

I suggest doing bad things to everyone who doesn't use code tags. Ever though I want to help you, I can't, because my eyes are burning :(

Name: Anonymous 2008-07-10 14:57

>>2

forgive me anon... im new to /prog/ and don't know how to format code =(

Name: Anonymous 2008-07-10 15:00

>>4
-kr -nut

Name: Anonymous 2008-07-10 15:06

<code>
//tree structure

struct node{
   int val;
   struct node * left, * right;
};

struct node * root = NULL;

//Inserting some numbers
void insert(int a[]){
   blablabla;
}

//function returning the height of the tree with root p)
int height(struct node *p){
   blablabla;
}

int balancefactor(struct node *p){
   if(!p) return 0;
   return height(p->right)-height(p->left);
}
</code>

Name: Anonymous 2008-07-10 15:08

//tree structure

struct node{
   int val;
   struct node * left, * right;
};

struct node * root = NULL;

//Inserting some numbers
void insert(int a[]){
blablabla;
}

//function returning the height of the tree with root p)
int height(struct node *p){
blablabla;
}

int balancefactor(struct node *p){
   if(!p) return 0;
   return height(p->right)-height(p->left);
}


Fuck code tags

Name: Anonymous 2008-07-10 16:24

>>3
Surely you mean [m] tags... [code] tags have eye-burning built in.

Name: Anonymous 2008-07-10 16:39

Listen up, dipshit. You don't ``calculate'' the balance factor of a node in an AVL tree, you keep track of it while inserting and deleting so you can just look it up.

>>8
Only if you have jabbascript on.

Name: Anonymous 2008-07-10 17:03

>>9

heyho, mr. smartguy. I'm aware that there are better solutions then calculating it with a rec function.
But that's from a CS test and therefore i don't really have an option here, do i?

Name: Anonymous 2008-07-10 17:59

>>3
DON'T HELP HIM!

Name: Anonymous 2008-07-11 23:12

Create your own stack? You could probably even get away with using an array for a stack since the tree is balanced. An array of n node pointers can deal with a tree of size up to 2n + 1 - 1 or something.

Name: Anonymous 2009-02-25 6:49


Wsh createobject msxml2 xml   while 1 a?

Name: Anonymous 2009-08-16 22:57

Lain.

Name: Sgt.Kabuⵕꋪkiman걘ㄑ 2012-05-24 10:28

All work and no play makes Jack a dull boy
Allɳᱼ work and no play makesȥ䯼 Jack a dull敝以 boy
All⍭ᡁ work and no play makes貍泊 Jack a dull㨟窡 boy
All㔤 work and no play makesⰖ湊 Jack a dull㩽갡 boy
All縹ᖝ work and no play makes븆㰽 Jack a dull醴䩾 boy
All이 work and no play makes Jack a dull훂붌 boy
Allӭ work and no play makes輜鼵 Jack a dull뺛栄 boy

Name: bampu pantsu 2012-05-29 4:06

bampu pantsu

Name: Anonymous 2013-01-19 14:23

/prog/ will be spammed continuously until further notice. we apologize for any inconvenience this may cause.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List