Answered step by step
Verified Expert Solution
Question
1 Approved Answer
3. Binary search algorithm. Finding a target element x in an increasing ordered sequence of integers ALGORITHM 3 The Binary Search Algorithm. procedure binary search
3. Binary search algorithm. Finding a target element x in an increasing ordered sequence of integers ALGORITHM 3 The Binary Search Algorithm. procedure binary search ( x : integer, a1,a2,,an : increasing integers) i:=1{i is left endpoint of search interval } j:=n{j is right endpoint of search interval } while iamtheni:=m+1elsej:=m if x=ai then location :=i else location :=0 return location \{location is the subscript i of the term ai equal to x, or 0 if x is not found Experiment: Please add a statement to print the variable i,j,m,a[i],a[m] for each iteration 4. Bubble sort algorithm. ALGORITHM 4 The Bubble Sort. procedure bubblesort (a1,,an : real numbers with n2) for i:=1 to n1 for j:=1 to ni if aj>aj+1 then interchange aj and aj+1 {a1,,an is in increasing order } Experiment: Please add a statement to print the variable i,j, and the array a for each iteration Please use the following code as your testing code a =[3,4,5,1,6,8,7,9,2] print("The maximum number in the array is ", max(a)) print("The location of the searched item with linear is ", linearSearch(a, 6)) print("The location of the searched item is ", binarysearch(a, 5)) a =[3,4,5,1,6,8,7,9,2] print("original array is ", a) print("sorted array using bubble sort is ", bubbleSort(a))
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started