11147 - KuPellaKeS BST

All about problems in Volume 111. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
ziliang
New poster
Posts: 19
Joined: Sat Sep 30, 2006 2:50 pm

11147 - KuPellaKeS BST

Post by ziliang »

anyone help..
不鸣则已,一鸣惊人.
rushel
Learning poster
Posts: 67
Joined: Sat Jan 22, 2005 5:57 am

Post by rushel »

read the description carefully. U have to print each node. worst case running time is O(n^2)
joeluchoa
New poster
Posts: 28
Joined: Sat Jul 31, 2004 12:11 am
Location: Brasil

Post by joeluchoa »

There is some special test case for this problem?
I got WA!
Some hint?
Please!
http://acm.uva.es/problemset/usersnew.php?user=47903

All men are like grass,and all their
glory is like the flowers of the field;
the grass withers and the flowers fall,
but the word of the Lord stands forever.
[1 Peter 1:24-25]
emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Post by emotional blind »

I think there is no special Case..
Problem Description is very much clear;

One hint I can give you from Problem description:
# If a node has a left child, all values in the left subtree are less than or equal to the value of the value of the node itself.
# If a node has a right child, all values in the right subtree are strictly greater than the value of the node itself.
sm_hosein
New poster
Posts: 3
Joined: Sat Oct 28, 2006 11:39 am
Contact:

Some TestCases

Post by sm_hosein »

Try it:

8
1
0
6
0 0 0 0 0 0
2
-1 1
4
-1 1 -1 1
5
-10 2 2 3 3
6
3 3 2 1 1 -10
9
-4 -3 -2 -1 0 1 2 3 4
10
5 4 3 2 1 -1 -2 -3 -4 -5

My AC Code's Answer:

Case #1: 0
Case #2: 0(0(0(0(0(0)))))
Case #3: -1(1)
Case #4: 1(-1(-1,1))
Case #5: 3(3(-10(2(2))))
Case #6: 3(3(-10(1(1,2))))
Case #7: -4(4(-3(3(-2(2(-1(1(0))))))))
Case #8: -5(5(-4(4(-3(3(-2(2(-1(1)))))))))
little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post by little joey »

I don't get it. From the description
The difference between sum of all values in the left subtree and sum of all values in the right subtree is minimum.
In your case 4, your answer is 1(-1(-1,1)): sum of left subtree = -1, sum of right subtree = 0, so difference = -1 - 0 = -1.
But for this BST: -1(-1,(1(1))) the sum of left subtree = -1, sum of right subtree = 2, so difference = -1 - 2 = -3, which is smaller than your solution.
And for the first sample I also can get a better solution than the one given... :-?
Ilham Kurnia
New poster
Posts: 31
Joined: Sat Nov 17, 2001 2:00 am
Contact:

Post by Ilham Kurnia »

little joey wrote:I don't get it. From the description
The difference between sum of all values in the left subtree and sum of all values in the right subtree is minimum.
In your case 4, your answer is 1(-1(-1,1)): sum of left subtree = -1, sum of right subtree = 0, so difference = -1 - 0 = -1.
But for this BST: -1(-1,(1(1))) the sum of left subtree = -1, sum of right subtree = 2, so difference = -1 - 2 = -3, which is smaller than your solution.
And for the first sample I also can get a better solution than the one given... :-?
I think the intended meaning is that the absolute difference of the two subtrees is as small as possible.
joeluchoa
New poster
Posts: 28
Joined: Sat Jul 31, 2004 12:11 am
Location: Brasil

Re: Some TestCases

Post by joeluchoa »

sm_hosein wrote:Try it:

8
1
0
6
0 0 0 0 0 0
2
-1 1
4
-1 1 -1 1
5
-10 2 2 3 3
6
3 3 2 1 1 -10
9
-4 -3 -2 -1 0 1 2 3 4
10
5 4 3 2 1 -1 -2 -3 -4 -5

My AC Code's Answer:

Case #1: 0
Case #2: 0(0(0(0(0(0)))))
Case #3: -1(1)
Case #4: 1(-1(-1,1))
Case #5: 3(3(-10(2(2))))
Case #6: 3(3(-10(1(1,2))))
Case #7: -4(4(-3(3(-2(2(-1(1(0))))))))
Case #8: -5(5(-4(4(-3(3(-2(2(-1(1)))))))))
in the third case, could it be 1(-1)???
http://acm.uva.es/problemset/usersnew.php?user=47903

All men are like grass,and all their
glory is like the flowers of the field;
the grass withers and the flowers fall,
but the word of the Lord stands forever.
[1 Peter 1:24-25]
joeluchoa
New poster
Posts: 28
Joined: Sat Jul 31, 2004 12:11 am
Location: Brasil

Post by joeluchoa »

I got AC now, however I continue with doubts! :-?
http://acm.uva.es/problemset/usersnew.php?user=47903

All men are like grass,and all their
glory is like the flowers of the field;
the grass withers and the flowers fall,
but the word of the Lord stands forever.
[1 Peter 1:24-25]
joeluchoa
New poster
Posts: 28
Joined: Sat Jul 31, 2004 12:11 am
Location: Brasil

Post by joeluchoa »

Now I understood my mistake! :D
The third case can't be 1(-1) because the left subtree sum must be maximal! :wink:

Silly error! :oops:
http://acm.uva.es/problemset/usersnew.php?user=47903

All men are like grass,and all their
glory is like the flowers of the field;
the grass withers and the flowers fall,
but the word of the Lord stands forever.
[1 Peter 1:24-25]
TimeString
New poster
Posts: 26
Joined: Mon Nov 13, 2006 3:53 am

Re: Some TestCases

Post by TimeString »

sm_hosein wrote:Try it:

4
-1 1 -1 1

My AC Code's Answer:

Case #4: 1(-1(-1,1))
sort input -1 1 -1 1 -> -1 -1 1 1
does it means root=1, and left subtree={-1,-1,1}, and right subtree={<empty>}, and then left sum=-1 , right sum=0, difference=1?

but my solution is:
parent=-1 , left subtree={<empty>} , right subtree={-1,1,1}, and then left sum=0 , and right sum=1, which difference is also 1, but the sum of left subtree is bigger than above.

did i misunderstand something??
neno_uci
Experienced poster
Posts: 104
Joined: Sat Jan 17, 2004 12:26 pm
Location: Cuba

Post by neno_uci »

If a node has a right child, all values in the right subtree are strictly greater than the value of the node itself.

So you can't have -1 as root and then -1 in it's right subtree.
sclo
Guru
Posts: 519
Joined: Mon Jan 23, 2006 10:45 pm
Location: Vancouver, BC, Canada
Contact:

Post by sclo »

I don't know of any special case. I think the sample input is good enough.
Post Reply

Return to “Volume 111 (11100-11199)”