Exercise 8.10.1: Recursively computing sums of cubes. About (a) Give a recursive algorithm to compute the sum of the cubes of the first n positive integers. The input to the algorithm is a positive integer n. The output is 1 j3. The algorithm should be recursive, it should not compute the sum using a closed form expression or a loop.
Q: ind gcd(8,13) using the recursive algorithm of GCD (Greatest Common Divisor) you studied in class.…
A: here is the solution to find gcd by using a recursive algorithm.
Q: The Fibonacci numbers are the numbers in the following integer sequence. 0, 1, 1, 2, 3, 5, 8, 13,…
A: #include <iostream>using namespace std;int fibSeries(int n) { if((n==1)||(n==0)) {…
Q: 3. Write a Javascript program to find the gcd of two numbers 2154 and 458 using recursion.
A: function gcd(a ,b){ if(b==0) return a; return gcd(b,a%b);}console.log(gcd(2154,458));
Q: Grade 12 computer science about recursion please write in Java Some conditions * Returns true if…
A: Lets see the solution.
Q: public int numdescendantsmod(int y) without recursion. this m O ethod should return the number of…
A: public int numdescendantsmod(int y) without recursion. this m O ethod should return the number of…
Q: B5. Using recursion, write a program in java to reverse a given string.
A: import java.util.Scanner;public class Main{ public static void strReverse(String a) {…
Q: 8, 21, 34, 55, &89 ... See the pattern? Each element in the series is the sum of the preceding two…
A: NOTE:- As Language is not defined in the question so i am using C lamguage. Recursive:- 1. CODE:-…
Q: 7. Implement a recursive algorithm to find the n-th Fibonacci number using memoization.
A: The solution to the given question is: SIMPLE RECURSIVE CODE IN PYTHON: def fibonacci(n): if n…
Q: A self-avoiding walk in a lattice is a path from one point to another that does not visit the same…
A: Given: A self-avoiding walk in a lattice is a path from one point to another that does not visit the…
Q: 1. Write a program to compute the sum of elements in an array recursively. The elements of the array…
A: Write a program to compute the sum of elements in an array recursively. The elements of the array…
Q: Write a Javascript program to find the gcd of two numbers 458 and 2154 using recursion.
A: Code: <!DOCTYPE html><html><head> <meta charset="utf-8">…
Q: uppose that intArray is an array of integers, and length specifies the number of elements in…
A: Your base case for recursion should be when low becomes greater than high Otherwise, just swap the…
Q: python 3 Write a program that lists all ways people can line up for a photo (all permutations of a…
A: Write a program that lists all ways people can line up for a photo (all permutations of a list of…
Q: 5. Write a program in Java to implement Insertion sort algorithm to sort a given set of elements and…
A: public class Main{ public static int[] sort(int a[]) { int l = a.length; for…
Q: C++ Implement Exercise 8-13 (8-13: Write a program to calculate students’ average test scores and…
A: #include <iostream> #include<fstream> #include<iomanip> using namespace std; class…
Q: complete java program. (3 * 4 = 12 Marks) 1. Implement the following reverseArray() method on…
A: public static int[] reverseArray(int[] A) { int[] newArray = new int[A.length]; for (int i…
Q: Write a program that lists all ways people can line up for a photo (all permutations of a list of…
A: GIVEN: Write a program that lists all ways people can line up for a photo (all permutations of a…
Q: 4. Complete the quick sort method by supplying code for the following methods: a. insertionSort (int…
A: insertsort(int A[]) { int i, j, t; int len = A.length; for (i = 1; i < len; i++) {…
Q: Exercise 20 the string below comes from an alphabet consisting of only characters A and B.…
A: I have provided c++ code in step2.
Q: 23- following code is an example of a recursive algorithm. int myRecursion (int array[], int first,…
A: Function myRecursion() has four function parameters, an array[], first, last and a val. Inside the…
Q: Use the fact that either the first element of a list is the largest or the largest is somewhere in…
A: #recursive method to find maximum element in a non empty listdef maximum(L): #base case…
Q: 1) You need to use JavaScript to modify a repeated element of unknown count on the page that is…
A: Introduction:- Javascript is a programming language that is used to design the website.…
Q: PP 17.7 Design and implement a recursive program to determine and print the Nth line of Pascal's…
A: Given:
Q: R6.3 Consider the following array: int(] a - { 1, 2, 3, 4, 5, 4, 3, 2, 1, 0}; What is the value of…
A: As per our honor code, we are answering the first 3 subparts. (a) Given snippet of code: int total…
Q: jestion 8 Consider a recursive function decTOBin(decimal) that converts a decimal number to a binary…
A: While converting a decimal number to binary number, we divide the number by 2 . This process…
Q: I have issus with this code: void rec(int n) { if(n==1) { cout<<1; return; } cout<<n<<" ";…
A: Given code: void rec(int n) {if(n==1) {cout<<1;return;}cout<<n<<"…
Q: Exercise 1 (Recursive Fibonacci) Make a new Java Project called Lab5. Then create a new class called…
A: In Fibonacci series the next number is the sum of previous two numbers. Example: 0, 1, 1, 2, 3, 5,…
Q: Exercise 8.10.6: Recursively computing the product of two non-negative integers. About (a) Give a…
A: Given Problem:- recursive algorithm that takes as input two non-negative integers x and y and…
Q: Write a program Java to sort the given list of elements using bubble sort: 33, 55, 11, 99, 22, 88,…
A: Bubble Sort: The Bubble sort is used to sort the given list in ascending or descending order. In the…
Q: What does the floowing program do? I Finclude 2 3 unsigned int mystery(unsigned int a, unsigned int…
A: Ans: Code: #include <stdio.h>unsigned int mystery(unsigned int a, unsigned int b);int main(){…
Q: X173: array220 Given an array of int s, compute recursively if the array contains somewhere a value…
A: Here I have created a function named array220(). In this function, I have used conditional…
Q: To better understand the concept of recursion, let’s look at an example that’s quite familiar to…
A: Program Screenshot for Indentation Reference: Sample Output:
Q: 1. Write a program Java to compute the sum of elements in an array recursively. The elements of the…
A: Main logic function:- static int MySum(int A[], int N) { if (N <= 0) return…
Q: 1. The sorted values array contains 16 integers 5, 7, 10, 13, 13, 20, 21, 25, 30, 32, 40, 45, 50,…
A: Answer:)
Q: Q#2 Write a recursive function zeroCount ( int a[ ], int s, int e) that receives an array of…
A: Given: Write a recursive function zeroCount ( int a[ ], int s, int e) that receives an array of…
Q: define and initialize and array X of length 8. You need implement following and write outcomes with…
A: Given: int X[]={1, 2, 3, 4, 5, 6, 7, 8}; ⇒X[0]=1, X[1]=2, X[2]=3, X[3]=4, X[4]=5, X[5]=6, X[6]=7…
Q: Write a new method called removeDuplicates( int[ ] A ) that removes all duplicate elements in an…
A: Introduction : Here we have to write a new method called removeDuplicates(int [] A) that removes all…
Q: create a recursive decent parse that read ( 1 + 2 ) / 3 from a txt file import java.io.File; import…
A: public class KeywordSearch{//method for searching the keywordpublic void search(String keyword)…
Q: 11.10 LAB: All permutations of names C++ Write a program that lists all ways people can line up…
A: C++ code is given in which The program will read a list of one word names until -1 , and use a…
Q: 10. Write a recursive program in JAVA to multiply two numbers recursively without using…
A: Write a recursive program in JAVA to multiply two numbers recursively without using the…
Q: Consider the following recursive algorithm: Int active(Int lst [1.int lowerindex, Int upperindex)…
A: As per our guidelines, we are supposed to answer only one question. Kindly repost the remaining…
Q: What is the complexity of the following code segment (assume all the libraries are included)? int x…
A: The correct option is
Q: JAVA The following code for InsertionSort is given to us by the textbook. Trace the code step by…
A: ANSWER :
Q: program that lists all ways people
A: Executable Code:def all_permutations(permList, nameList): # Define the function to create a list…
Q: Q#8, Recursive letter: Given the following recursive function: 1 def love_letter(n): 2 ifn<1: 3…
A: This is a recursive problem. Recursive function is a function which calls itself again and again.…
Q: 19- java. Which of the following is a drawback of using recursion? It may be less efficient…
A: The drawbacks of recursion are: 1. Recursive functions are generally slower than non-recursive…
Q: 12.10 LAB: All permutations of names- Java Write a program that lists all ways people can line…
A: Providing code below:
Q: Write a program that replaces words in a sentence. The input begins with word replacement pairs…
A: Program code: #Define main() function def main(): #Read data from the user replace_pairs =…
Q: Write a recursive function to compute the following series: m(i) = 1/3 + 2/ 5 + 3/7 + 4/ 9 + 5/11…
A: Given: Write a recursive function to compute the following series: m(i) = 1/3 + 2/ 5 + 3/7 + 4/ 9…
discrete math
Trending now
This is a popular solution!
Step by step
Solved in 3 steps
- Q#2 Write a recursive function zeroCount ( int a[ ], int s, int e) that receives an array of integers a [], a start index s, and an end index e. The function should return the number of zeros in that array between s and e. int zeroCount ( int a[ ], int s, int e); Trace your function given the following array and function call. Draw your steps. int a[ ] = {1, 0, 0, 5}; int zeros = zeroCount(a, 0, 3); language c++Artificial Intelligence (Part - 2) ==================== The Towers of Hanoi is a famous problem for studying recursion incomputer science and searching in artificial intelligence. We start with N discs of varying sizes on a peg (stacked in order according to size), and two empty pegs. We are allowed to move a disc from one peg to another, but we are never allowed to move a larger disc on top of a smaller disc. The goal is to move all the discs to the rightmost peg (see figure). To solve the problem by using search methods, we need first formulate the problem. Supposing there are K pegs and N disk. (2) What is the size of the state space?1. The sorted values array contains 16 integers 5, 7, 10, 13, 13, 20, 21, 25, 30,32, 40, 45, 50, 52, 57, 60. Indicate the sequence of recursive calls that are made tobinaraySearch, given an initial invocation of binarySearch(32, 0, 15).show only the recursive calls. For example, initial invocation is binarySearch(45,0,15)where the target is 45, first is 0 and last is 15.
- The Fibonacci algorithm is a famous mathematical function that allows us to create a sequence of numbers by adding together the two previous values. For example, we have the sequence:1, 1, 2, 3, 5, 8, 13, 21…Write your own recursive code to calculate the nth term in the sequence. You should accept a positive integer as an input, and output the nth term of the sequence.Once you have created your code, add comments describing how the code works, and the complexity of any code you have created.Artificial Intelligence (Part - 1) ==================== The Towers of Hanoi is a famous problem for studying recursion in computer science and searching in artificial intelligence. We start with N discs of varying sizes on a peg (stacked in order according to size), and two empty pegs. We are allowed to move a disc from one peg to another, but we are never allowed to move a larger disc on top of a smaller disc. The goal is to move all the discs to the rightmost peg (see figure). To solve the problem by using search methods, we need first formulate the problem. Supposing there are K pegs and N disk. (1) Propose a state representation for the problem?The Tower of Hanoi is a puzzle where n disks of different sizes arestacked in ascending order on one rod and there are two other rods with nodisks on them. The objective is to move all disks from the first rod to thethird, such that:- only one disk is moved at a time- a larger disk can never be placed on top of a smaller oneWrite a recursive function that outputs the sequence of steps needed tosolve the puzzle with n disks.Write a test program in C++ that allows the user to input number of disks andthen uses your function to output the steps needed to solve the puzzle.Hint: If you could move up n−1 of the disks from the first post to thethird post using the second post as a spare, the last disk could be moved fromthe first post to the second post. Then by using the same technique you canmove the n−1 disks from the third post to the second post, using the firstdisk as a spare. There! You have the puzzle solved. You only have to decidewhat the nonrecursive case is, what the recursive…
- 12.10 LAB: All permutations of names- Java Write a program that lists all ways people can line up for a photo (all permutations of a list of Strings). The program will read a list of one word names (until -1), and use a recursive method to create and output all possible orderings of those names, one ordering per line. When the input is: Julia Lucas Mia -1 then the output is (must match the below ordering): Julia Lucas Mia Julia Mia Lucas Lucas Julia Mia Lucas Mia Julia Mia Julia Lucas Mia Lucas JuliaDo not use static variables to implement recursive methods. USING JAVA USING: // P4 public static int min(int [] a, int begin, int end) { } Implement a recursive method min that accepts an array and returns the minimum element in the array. The recursive step should divide the array into two halves and find the minimum in each half. Demonstrate the output of min on the array int [] a = { 2, 3, 5, 7, 11, 13, 17, 19, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 23, 29, 31, 37, 41, 43 }JAVA The following code for InsertionSort is given to us by the textbook. Trace the code stepby step using the array[55, 22, 77, 99, 66, 33, 11]on a piece of paper or using a Word document. If the code has errors, correct it and make itwork.public static void insertionSort(double[] list) {for (int i = 1; i < list.length; i++) {/** insert list[i] into a sorted sublist list[0..i-1] so thatlist[0..i] is sorted. */double currentElement = list[i];int k;for (k = i - 1; k >= 0 && list[k] > currentElement; k--) {list[k + 1] = list[k];}// Insert the current element into list[k+1]list[k + 1] = currentElement;}}
- Can i get help with this missing code, java 1 class QuicksortTester2 {34 /**5 * Quicksort algorithm (driver)6 */78 public void quicksort( int [ ] a )9 {10 quicksort( a, 0, a.length - 1 );11 }1213 /**14 * Internal quicksort method that makes recursive calls.15 * Uses median-of-three partitioning and a cut-off.16 */17public void quicksort( int [ ] a, int low, int high )19 {20 if( low + CUTOFF > high )21 insertionSort( a );22 else23 { // Sort low, middle, high24 int middle = ( low + high ) / 2;25 if( a[ middle ].compareTo( a[ low ] ) < 0 )26 swapReferences( a, low, middle );27 if( a[ high ].compareTo( a[ low ] ) < 0 )28 swapReferences( a, low, high );29 if( a[ high ].compareTo( a[ middle ] ) < 0 )30 swapReferences( a, middle, high );3132 // Place pivot at position high - 133 swapReferences( a, middle, high - 1 );34 int pivot = a[ high - 1 ];3536 // Begin partitioning37 int i, j;38 for( i = low, j = high - 1; ; )39 {40 while( a[ ++i ].compareTo( pivot ) < 0 )41 ;42 while(…Written in Dr Racket: Write a recursive function that takes a list of numbers as input and returns a list of the numbers in ascending order.Use the quicksort algorithmUse ( 20 13 74 5 12 9 22 95 22 6 101 72 3 53 33 21 96) as input. To do that, calculate the average value of a sublist before dividing it.(quicksort ‘( 20 13 74 5 12 9 22 95 22 6 101 72 3 53 33 21 96))returns ‘(3 5 6 9 12 13 20 21 22 22 33 53 72 74 95 96 101) Do not use sort, quicksort, set!, or mean.19- java. Which of the following is a drawback of using recursion? It may be less efficient than an iterative version. It may have fewer lines of code than an iterative version. It uses lesser memory stack than an iterative version. It runs faster than an iterative version.