# BSTs, time complexity

Page 1 of 1

## 1 Replies - 233 Views - Last Post: 07 February 2019 - 01:44 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=414801&amp;s=bd74d0e3dd7244aceda5918662d7fdfc&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 miller72

• New D.I.C Head

Reputation: 0
• Posts: 1
• Joined: 06-February 19

# BSTs, time complexity

Posted 06 February 2019 - 03:11 PM

Hi everyone!

I've been recently asked by one of my friends to help him out with these two following questions.

1.Find the time complexity of this two piece of code and write which one is bigger?

```for( int i=2 ; i<= n; i=i*i )
for( int j=2 ; j <= i; j=j*j )
print(j);

while ( n>1 ){
print(n);
n=n/2;
}
```

what I think so far for 1st question:
for the first case,
line 1, we can write a sigma from i=2 to root of n
but for the 2nd line Im not sure if still i'm allowed to use SIGMA cause (j) is LESS than or equal to i, and also the value of j depends on (I) from line 1. so that's why I think I should not use sigma for the 2nd line.

for the second code:
line 2nd and 3rd both execute 1 time so I think, O(1), right?

2.An algorithm that takes the roots of two same Binary Search Trees. if the roots are same return TRUE and if not return FALSE.
(corresponding nodes have the same values.)

for this question I have no clue and dont know where to start from, and 've searched a lot so far, but not successful yet...

Is This A Good Question/Topic? 0

## Replies To: BSTs, time complexity

### #2 andrewsw

• Stealth IT

Reputation: 6737
• Posts: 27,746
• Joined: 12-December 12

## Re: BSTs, time complexity

Posted 07 February 2019 - 01:44 AM

What assistance is your friend offering?

For reference, also posted at stackexchange and sitepoint