Question: Data Structures and Algorithms in Java (LAB 3 - Recursion) Lab3- Recursion You can select and do some questions according to your ability. We would

Data Structures and Algorithms in Java (LAB 3 - Recursion)

Data Structures and Algorithms in Java (LAB 3 - Recursion) Lab3- RecursionYou can select and do some questions according to your ability. Wewould like to note you that the more questions you do the

Lab3- Recursion You can select and do some questions according to your ability. We would like to note you that the more questions you do the better for you in doing final practical and writing exams. Write Java programs to perfom the following tasks: 1) Write a recursive function that computes the sum of all numbers from 1 to n, where n is given as parameter. //return the sum 1+ 2+ 3+ ...+n int sum(int n) 2) Write a recursive function that finds and returns the minimum element in an array, where the array and its size are given as parameters. //return the minimum element in a[] int findmin(int a[], int n) 3) Write a recursive function that computes and returns the sum of all elements in an array, where the array and its size are given as parameters. //return the sum of all elements in a[] int findsum(int a[], int n) 4) Write a recursive function that determines whether an array is a palindrome, where the array and its size are given as parameters. //returns 1 if a[] is a palindrome, 0 otherwise. The string a is palindrome if it is the same as its reverse. int ispalindrome(char a[], int n) 5) Write a recursive function that searches for a target in a sorted array using binay search, where the array, its size and the target are given as parameters. 6) Implement the Greatest Common Divisor algorithm as recursive method GCD. Use recursion. Do NOT use a loop. (m if n == 0 GCD(m,n) GCD(n, m%n) if'n > 0 7) Implement the power function recursively 11 if n = 0 powerx, n) (x power (x, n - 1) if x 21 8) Implement the factorial function recursively as fact (1 if ns1 factn) x fact (n-1) if x > 1 9) Implement Fibonacci recursively as fib (1 if ns2 fib(n) (fibn - 1) + fib(n - 2) if x 21 10)Write recursive method addReciprocals that takes an integer as a parameter and returns the sum of the first n reciprocals. addReciprocals(n) returns (1.0+ 1.0/2.0 + 1.0/3.0 + 1.0/4.0 + ... +1.0). 11)Tree height. Given a labeled binary tree (represented by a pointer to a TreeNode) calculate its height. 12)Tree size. Given a labeled binary tree (represented by a pointer to a TreeNode) calculate its size

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!