
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
![AIM: Write a program to do Binary Search using a given Search Key in a Sorted
Linear Array 'A' which has N values in it.
Description: The binary search algorithm can only be used with sorted array
and eliminates one half of the elements in the array being searched after each
comparison. The binary search algorithm applied to our array A works as follows:
Algorithm: (Binary Search)
Here A is a sorted Linear Array with N elements stored in it in sorted order
and SKEY is a given item of information to search. This algorithm finds the
location of SKEY in A and if successful, it returns its location otherwise it returns
-1 for unsuccessful.
BinarySearch (A, N, SKEY)
[Initialize segment variables.]
1. Set START=0, END=N-1 and MID=int((START+END)/2).
2. Repeat Steps 3 and 4 while START ≤ END and A[MID]+SKEY.
3.
If SKEY< A[MID] Then
Set END=MID-1.
Else Set START=MID+1.
[End of If Structure.]
4.
Set MID=int((START +END)/2).
[End of Step 2 loop.]
5. If A[MID] = SKEY then Set LOC= MID
Else
Set LOC = -1
[End of IF structure.]
6. return LOC and End](https://content.bartleby.com/qna-images/question/1d836947-d561-49e4-a412-f70686684495/2b668141-1131-4ad6-894d-8a1f84f577f4/i921nnp_thumbnail.png)
Transcribed Image Text:AIM: Write a program to do Binary Search using a given Search Key in a Sorted
Linear Array 'A' which has N values in it.
Description: The binary search algorithm can only be used with sorted array
and eliminates one half of the elements in the array being searched after each
comparison. The binary search algorithm applied to our array A works as follows:
Algorithm: (Binary Search)
Here A is a sorted Linear Array with N elements stored in it in sorted order
and SKEY is a given item of information to search. This algorithm finds the
location of SKEY in A and if successful, it returns its location otherwise it returns
-1 for unsuccessful.
BinarySearch (A, N, SKEY)
[Initialize segment variables.]
1. Set START=0, END=N-1 and MID=int((START+END)/2).
2. Repeat Steps 3 and 4 while START ≤ END and A[MID]+SKEY.
3.
If SKEY< A[MID] Then
Set END=MID-1.
Else Set START=MID+1.
[End of If Structure.]
4.
Set MID=int((START +END)/2).
[End of Step 2 loop.]
5. If A[MID] = SKEY then Set LOC= MID
Else
Set LOC = -1
[End of IF structure.]
6. return LOC and End
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 3 steps with 3 images

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
- Prompt: In Python language, write a function that applies the logistic sigmoid function to all elements of a NumPy array. Code: import numpy as np import math import matplotlib.pyplot as plt import pandas as pd def sigmoid(inputArray): modifiedArray = np.zeros(len(inputArray)) #YOUR CODE HERE: return(modifiedArray) def test(): inputs = np.arange(-100, 100, 0.5) outputs = sigmoid(inputs) plt.figure(1) plt.plot(inputs) plt.title('Input') plt.xlabel('Index') plt.ylabel('Value') plt.show() plt.figure(2) plt.plot(outputs,'Black') plt.title('Output') plt.xlabel('Index') plt.ylabel('Value') plt.show() test()arrow_forwardDESIGN YOUR OWN SETTING Task: Devise your own setting for storing and searching the data in an array of non-negative integers redundantly. You may just describe the setting without having to give an explicit algorithm to explain the process by which data is stored. You should explain how hardware failures can be detected in your method. Once you have described the setting, include the following to your answer: Write a pseudocode function to describe an algorithm where the stored data can be searched for a value key: if the data is found, its location in the original array should be returned; -1 should be returned if the data is not found; -2 should be returned if there is a data storage error Include a short commentary explaining why your pseudocode works Describe the worst-case and best-case inputs to your search algorithm Derive the worst-case and best-case running times for the search algorithm Derive the Theta notation for the worst-case and best-case running timesarrow_forward1. (100 points) Write a Java program that ● ● ● Define an integer array with length of 10. Populate the array with random integer numbers. Sort this array into non-decreasing/decreasing order based on three sorting algorithms. bubble sort selection sort O insertion sort Test these 3 sorting methods Give a big-Oh characterization, in terms of n, of the running time of these three algorithms. Improve the bubble sort so that the time complexity of them are O(N) for the best case (extraarrow_forward
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