
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
int[] list = {-35,4,-50,2} and the length= 4
(binary search
![The source code is
Eprivate static int binarySearch (int[] list, int key, int low, int high) {
if (low > high) // The list has been exhausted without a match
return -1;
int mid = (low + high) / 2;
if (key < list [mid])
return binarySearch (list, key, low, mid - 1);
else if (key
return mid;
== list[mid])
else
return binarySearch (list, key, mid + 1, high);
low
high
low>high
mid=(low+high)/2 Call](https://content.bartleby.com/qna-images/question/2ec814c7-90f3-4435-9bb8-fcbab3f733ac/f351f99f-455a-41e8-9c9e-ec3abdfe9b2c/l2pha6g_thumbnail.png)
Transcribed Image Text:The source code is
Eprivate static int binarySearch (int[] list, int key, int low, int high) {
if (low > high) // The list has been exhausted without a match
return -1;
int mid = (low + high) / 2;
if (key < list [mid])
return binarySearch (list, key, low, mid - 1);
else if (key
return mid;
== list[mid])
else
return binarySearch (list, key, mid + 1, high);
low
high
low>high
mid=(low+high)/2 Call
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

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
- def sort and_pop(x: list, i: int) -> list: x.sort() return x.pop(i) # Dan's code lst = [23, 17, 3, 13, 11, 5, 7, 2, 19, 1] lst = sort_and_pop(lst, 5) lst = sort_and_pop(lst, 2) II I| || If you run this code, you'll find that it produces an error. Surprise! According to the type contract, Dan's Code should work. But it doesn't, because the function type contract has faulty type annotations. Correct the function type contract so that it's clear from the type contract that Dan's code will not work. (Dan's Code will and should remain an incorrect use of the function!) TODO: Write a new type contract"" "arrow_forward53: What sorting algorithm is this? void Sort1(string arr[], int beg, int end) { int piv index = subdivision(arr, beg, end); if (piv_index-1 > beg) { Sort1(arr, beg, piv_index-1); } if (piv_ind+1 piv) down--; if (up <= down) { tmp = arr[up]; arr[up] = arr[down]; arr[down] = tmp; up++; down --; } arr[beg] = arr[down]; arr[down] = piv; return down; %3Darrow_forwardInt[] list = {7,14,26,43,46,50,81} and the length= 7 (binary search Algorithm) use the sorted list above and fill out the table for 3 different cases: Search for the value that is in the table. Search for the value that is greater than any value in the list. Search for the value that is smaller than any value in the list.arrow_forward
- odd_list = print(f"odd_list output: {odd_list}") todo_check([ (odd_list==[1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49], 'odd_list does not contain all odd numbers between 1 and 49') ])arrow_forwardLists and strings: Perform the following using the list and string defined below: Mylist = [“orange”,”banana”,”apple”,”grape”] Mystring = “314-800-2346” What does Mylist[2] equal? What does Mystring[2] equal? What does the len(Mylist) equal? What does len(Mystring) equal? Write a for loop that will display the strings in Mylist from last to first. Write a line of code that appends “pear” to Mylistarrow_forwardwrite basic python code adn create a list list_append: adds a new element to the end of the list. then printarrow_forward
- I keep on getting this error g_list.remove(r)ValueError: list.remove(x): x not in listarrow_forwardHere is the code for number 1. def reverse_list(old_list): new_list = [ele for ele in reversed(old_list)] return new_list if __name__ == "__main__": str = input("Enter the elements of the list: ").split() elements = list(map(int, str)) print(reverse_list(elements))arrow_forwardAssuming the following list declaration, which element is at the position 0 after the first iteration of selection sort (Assume list is to be sorted in ascending order)? int list [] = {34, 56, 12, 25, 73, 4, 85, 13, 46, 16}; O None of these O 85 O 56 O 16arrow_forward
- O b. Remove the O. Remove the second element in the list O d. Remove the element before the last element in the list QUESTION 6 The following code inserts an element at the beginning of the list public void insertBegin(T e) { Node temp = new Node (e); head = temp; temp.Next = head; size++; } O True O False QUESTION 7 what does the following code do?arrow_forwardusing python in google colabarrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education