C++ How to Program (10th Edition)
10th Edition
ISBN: 9780134448237
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 20, Problem 20.8E
(Recursive Linear Search) Modify Fig. 20.2 to use recursive function recursiveLin-earsearch to perform a linear search of the array. The function should receive the array, the search key and starting index as arguments. If the search key is found, return its index in the array; other wise, return -1. Each call to the recursive function should check one element value in the array.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
(Recursive Greatest Common Divisor) The greatest common divisor of integers x and y isthe largest integer that evenly divides both x and y. Write a recursive function gcd that returns thegreatest common divisor of x and y. The gcd of x and y is defined recursively as follows: If y is equalto 0, then gcd(x, y) is x; otherwise gcd(x, y) is gcd(y, x % y), where % is the remainder operator.
(Recursive Binary Search) Write a recursive method RecursiveBinarySearch to perform abinary search of the array. The method should receive the search key, starting index, endingindex and array A as arguments. If the search key is found, return its index in the array. If thesearch key is not found, return -1.int RecursiveBinarySearch(int search, int start, int end, int[] A)
(GREATEST COMMON DIVISOR) The greatest common divisor of integers
x and y is the largest integer that evenly divides into both x and y. Write and
test a recursive function gcd that returns the greatest common divisor of x
and y. The gcd of x and y is defined recursively as follows: If y is equal to 0,
then gcd (x, y) is x; otherwise, gcd (x, y) is gcd (y, x % y), where % is the
remainder operator.
Chapter 20 Solutions
C++ How to Program (10th Edition)
Ch. 20 - (Bubble Sort) Implement the bubble sort algorithm-...Ch. 20 - Prob. 20.6ECh. 20 - (Bucket Sort) A bucket sort begins with a...Ch. 20 - (Recursive Linear Search) Modify Fig. 20.2 to use...Ch. 20 - (Recursive Binary Search) Modify Fig. 20.3 to use...Ch. 20 - (Quicksort) The recursive sorting technique called...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- 4. CodeW X For func X C Solved b Answer x+ https://codeworkou... ... [+) CodeWorkout X271: Recursion Programming Exercises: Minimum of array For function recursiveMin, write the missing part of the recursive call. This function should return the minimum element in an array of integers. You should assume that recursiveMin is initially called with startIndex = 0. Examples: recursiveMin({2, 4, 8}, 0) -> 2 Your Answer: 1 public int recursiveMin(int numbers[], int startIndex) { numbers.length - 1) { if (startIndex 2. return numbers[startIndex]; } else { return Math. min(numbers[startIndex], >); 5. { 1:11 AM 50°F Clear 12/4/2021arrow_forwardProgramming Language C Note:No Need for Detailed Explanation. The Answer is Enough For Me.Solve according to this information. (No: 2012010206083)arrow_forward2, Towers of Hanoi Problem. (10 points) 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. Answer the following questions. (1) Determine a state representation for this problem. (4points) (2) What is the size of the state space? (3 points) (3) Supposing K=3, N=4, what is the start state by using your proposed state representation method and what is the goal state? (3 points)arrow_forward
- (Towers of Hanoi: Iterative Solution) Any program that can be implemented recursivelycan be implemented iteratively, although sometimes with considerably more difficulty and considerably less clarity. Try writing an iterative version of the Towers of Hanoi. If you succeed, compareyour iterative version with the recursive version you developed in Exercise 5.36. Investigate issuesof performance, clarity, and your ability to demonstrate the correctness of the programs.arrow_forward(the use of dynamic array) *please explain the use of dynamic array and why it was used here. Use reference photo*arrow_forward2: - Write a recursive function that takes an array and a callback function and returns True if any value of that array returns True from that callback function otherwise returns False. As a callback funtion for this problem, assume that the callback function is used to check if a given input is an even number. Anals, the running time of the algorithm 3: Recursive Linear Searcharrow_forward
- (C Language) Write a recursive function called DigitCount() that takes a non-negative integer as a parameter and returns the number of digits in the integer. Hint: The digit count increases by 1 whenever the input number is divided by 10.arrow_forward(Recursive Selection Sort) A selection sort searches an array looking for the smallest elementin the array. When that element is found, it’s swapped with the first element of the array. The process is then repeated for the subarray, beginning with the second element. Each pass of the arrayresults in one element being placed in its proper location. This sort requires processing capabilitiessimilar to those of the bubble sort—for an array of n elements, n – 1 passes must be made, and foreach subarray, n – 1 comparisons must be made to find the smallest value. When the subarray beingprocessed contains one element, the array is sorted. Write a recursive function selectionSort toperform this algorithmarrow_forwardInformation to solve question: Use "a" for loop to calculate the sum of squares of values in this list: 1, 7, 8, 6, 11. (The answer should be 271) Create a recursive function to do the same calculation a in the previous question. (The function input will be the list. Each recursion, you are going to send a sub-list with one less item from the list) ----------------------------------------------------------------------------------- (1) Create a function to perform bubble sorting in python? The algorithm should stop when there are no swaps in the last iteration.arrow_forward
- (C Language) Write a recursive function called DrawTriangle() that outputs lines of '*' to form a right side up isosceles triangle. Function DrawTriangle() has one parameter, an integer representing the base length of the triangle. Assume the base length is always odd and less than 20. Output 9 spaces before the first '*' on the first line for correct formatting. Hint: The number of '*' increases by 2 for every line drawn.arrow_forwardProblem 2 -- Recursive Palindrome (Grey + Scarlet) Write a recursive method, isPalindrome, which takes a String as a parameter, and returns true if the String is a palindrome. For the purposes of this method, you may assume Strings with a length of o or 1 are palindromes.arrow_forward(IN PYTHON) Problem 2 Write a function count_8s(string) that performs the following actions: Receives a single parameter called string that we expect to be a string. If we receive something that is NOT a string, raise a TypeError with the message “Non-string input received.” Uses recursion to count the number of eights in the string. Use a string of length 0 as your base case. Otherwise, determine if the first character in string is “8” or not, and call count_8s() again with the rest of the string as an argument. Returns the number of eights found in the string. NOTE: You are not to use a while or for loop in your code.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
1.1 Arrays in Data Structure | Declaration, Initialization, Memory representation; Author: Jenny's lectures CS/IT NET&JRF;https://www.youtube.com/watch?v=AT14lCXuMKI;License: Standard YouTube License, CC-BY
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License