Question: 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".
 Assignment 1: Recursion, Linked Lists, Stacks, and Queues Harmonic number Create

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!