Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need to solve recurrence t(n)=t(n-1)+n, for n>1, t(1)=a; where a is some constant of type double Enter a and n 1. Find t(a, n) using

need to solve recurrence t(n)=t(n-1)+n, for n>1, t(1)=a; where a is some constant of type double Enter a and n

1. Find t(a, n) using recursion What is complexity of your solution, when you use recursion?

2. find t(a,n)==f(a,n) in O(1) complexity Provide code for both solutions. for n<1, t(a,n) is not defined, so throw exception if user enters not number, and throw exception if user enters number less than 1 catch both exceptions and ask user to re-enter n value

Intended output:

You need to solve recurrence t(n)=t(n-1)+n, for n>1, t(1)=a;

where a is some constant of type double

Enter a and n 1. Find t(a, n) using recursion

What is complexity of your solution, when you use recursion?

2. find t(a,n)==f(a,n) in O(1) complexity

Provide code for both solutions.

for n<1 t(a,n) is not defined, so throw exception if user enters

not number, and throw exception if user enters numberless than 1

catch both exceptions and ask user to re-enter n value

t(1)=a Enter constant double a = w

you entered not double type value

t(1)=a Enter constant double a = r

t(1)=a Enter constant double a = 0.5

Enter int n =0

you entered 0 number is less than 1

t(1)=a Enter constant double a = 4

Enter int n =-3

you entered -3 number is less than 1

t(1)=a Enter constant double a = 0.5

Enter int n =8

recursive t(0.5,8)=35.5

complexity O(1) f(0.5,8)=35.5

Do you want to repeate? y/n: y

t(1)=a Enter constant double a = r

t(1)=a Enter constant double a = 1

Enter int n =5

recursive t(1,5)=15

complexity O(1) f(1,5)=15

Do you want to repeat? y/n: n

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spomenik Monument Database

Authors: Donald Niebyl, FUEL, Damon Murray, Stephen Sorrell

1st Edition

0995745536, 978-0995745537

More Books

Students also viewed these Databases questions

Question

=+How do they differ from an HR point-of-view?

Answered: 1 week ago

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago