Question
Book Icon
Chapter 17, Problem 3P
Program Plan Intro

Recursive Binary Search

Program Plan:

  • Include the required header files.
  • Declare the global variables.
  • Declare the function template.
  • Define main function.
    • Declare the required variables.
    • Get the array of elements.
    • Display the given display.
    • Sort the array in ascending order.
    • Display the sorted array.
    • Call the “search” function with the arguments.
    • If the “found” value is true, display the search element location. Otherwise display, “the element is not found”.
  • Define the “search” function
    • Declare the variable
    • If “first” is greater than “last”, set “found” value as “false”.
    • Otherwise find the “mid” value.
      • If the “key” value is equal to “a [mid]”, set “found” value as “true” and also set “location” as “mid”.
      • If the “key” is less than “a [mid]”, call the “search” function with the arguments.
      • Otherwise, call the “search” function with the arguments.

Blurred answer
Students have asked these similar questions
(This question is for a linked list of the type described on the front page, Item 5). Write a recursive function CountGE60. that receives a linked list (may or may not be empty) and returns the number of nodes (each containing a data item value) greater than or equal to 60.
Write a recursive Java function displayOutIn that displays two items from an array list at one instance from out-to-in. until one or last two items displayed and the process stops. For example, given array A = {15, 74, 106, 10, 9, 86, 34} the displayOutIn function displays the following:          15, 34          74, 86          106, 9          10
Implements clone which duplicates a list. Pay attention, because if there are sublists, they must be duplicated as well. Understand the implementation of the following function, which recursively displays the ids of each node in a list  Develop your solution as follows: First copy the nodes of the current list (self) Create a new list with the copied nodes Loop through the nodes of the new list checking the value field If this field is also a list (use isinstance as in the show_ids function) then it calls clone on that list and substitutes the value. Complete the code: def L4(*args,**kwargs):         class L4_class(L):          def clone(self):              def clone_node(node):                 return <... YOUR CODE HERE ...>              r = <... YOUR CODE HERE...>             return r                     return L4_class(*args,**kwargs)
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning