O(n^2) ???

The Gateway to Computer Science Excellence

0 votes

0 votes

We can solve it by tree method.

T(n) = T(n/3) + T(n/9) + n

n =======> n

/ \

n/3 n/9 =======> 4/9n

/ \ / \

n/9 n/27 n/27 n/81 ====> $(4/9)^{2}*n$

.................................................................

T(1) ....................................................T(1)

Total work done will be = n + (4/9)n + $(4/9)^{2}*n $ + .........................k (times)

Here n = $(4/9)^{k}$

We can write it like n* [ 1 + 4/9 + 4/9^2 +------------------------]

So, it will be.

= 9/5 *n

= O(n)

T(n) = T(n/3) + T(n/9) + n

n =======> n

/ \

n/3 n/9 =======> 4/9n

/ \ / \

n/9 n/27 n/27 n/81 ====> $(4/9)^{2}*n$

.................................................................

T(1) ....................................................T(1)

Total work done will be = n + (4/9)n + $(4/9)^{2}*n $ + .........................k (times)

Here n = $(4/9)^{k}$

We can write it like n* [ 1 + 4/9 + 4/9^2 +------------------------]

So, it will be.

= 9/5 *n

= O(n)

- All categories
- General Aptitude 1.9k
- Engineering Mathematics 7.5k
- Digital Logic 2.9k
- Programming and DS 4.9k
- Algorithms 4.3k
- Theory of Computation 6.2k
- Compiler Design 2.1k
- Databases 4.1k
- CO and Architecture 3.4k
- Computer Networks 4.1k
- Non GATE 1.5k
- Others 1.5k
- Admissions 595
- Exam Queries 576
- Tier 1 Placement Questions 23
- Job Queries 72
- Projects 17

50,645 questions

56,616 answers

195,897 comments

102,353 users