Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 1 : Recursion, Linked Lists, Stacks, and Queues Harmonic number Create a recursive solution for computing the n t h Harmonic number, defined as

Assignment 1: Recursion, Linked Lists, Stacks, and Queues
Harmonic number
Create a recursive solution for computing the nth Harmonic number, defined as Hn=k=1n1k.
Product of two numbers
Create a recursive solution to compute the product of two positive integers, m and n, using only addition and subtraction.
Find a bit in a binary string
You are given two positive integers i and n. The binary string Sn is formed using the following formula:
S1="1"
Sn=Sn-1+"0"+ invert reverse (Sn-l)) for n>1
Where + denotes the concatenation operation, reverse (str) should return the reversed of string str, and invert (str) inverts all the bits in str (0 changes to 1 and 1 changes to 0). For example, the first four strings in the above sequence are:
S1=1
S2=100
S3=1000110
S4=100011001001110
Return the iin bit in Sn. Assume that i is valid for the given n.
Example 1:
Input: n=3,i=1
Output: "1"
Explanation: S is "1000110".
The 1-bit is "1".
Example 2:
Input: n=4,i=11
Output: "0"
Explanation: Sis "100011001001110".
image text in transcribed

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

Step: 3

blur-text-image

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

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago