1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Svet_ta [14]
2 years ago
11

Consider a binary-search method in an array that reports whether an object is in the array. The documentation indicates that the

caller must pass in a sorted array or the results are unspecified. According to strict design-by-contract, who is responsible for checking that the array is sorted
Computers and Technology
1 answer:
inn [45]2 years ago
5 0

#include<iostream.h>

#include<conio.h>

void sort(int A[], int N)

{int I,J,tmp;

for(I=0;I<N;I++)

{for(J=0;J<N;J++)

{if(A[J]>A[J+1])

{tmp=A[J];A[J]=A[J+1];A[J+1]=tmp;}}}}

void main()

{int a[15],I,n,l,u,sh,mid,k=0;

clrscr();

cout<<”Enter the array size”;

cin>>n;

l=0;u=n-1;

cout<<”\nEnter the array elements”<<endl;

for(i=0;i<n;i++)

cin>>a[i];

sort(a,n);

cout<<”\nEnter search element”;

cin>>sh;

cout<<”\nNow, applying N=Binary Search”<<endl;

while(l<=u)

{mid=(l+u)/2;

If(a[mid]>sh)

u=mid-1;

if(a[mid]<sh)

l=mid+1;

if(a[mid]==sh){k=1;break;}}

if(k==1)

cout<<”\n Element is present at “<<(mid+1)<<endl;

else

cout<<”\n Element not found”;

getch();

}

<u>Explanation:</u>

Binary Search is a type of search method which is more effective and takes more traversals than the linear search. It compares the each element to the middle element. If the element is found, it gives the position otherwise it will give no result.

You might be interested in
The marketplace for computer hardware:________ 1. has become increasingly concentrated in top firms 2. has expanded to include a
yawa3891 [41]

Answer:

the answer should be 1.

3 0
3 years ago
Read 2 more answers
The ____ algorithm was the first public key encryption algorithm developed (in 1977 and published for commercial use.
Whitepunk [10]
The RSA Algorithm was developed by and named after the initials of: Ron Rivist, Adi Shamir, and Leonard Adleman while they were working at MIT. It was developed in 1977 and published in 1978.  The algorithm uses the exponentiation modulo in encrypt and decrypt information. 
7 0
3 years ago
The purchase of one cup of coffee a day what's going to do
xz_007 [3.2K]
Well if you add it up , if one cup of coffe is $1, then in one year it would be $365 on coffe.
7 0
3 years ago
Read 2 more answers
A software is made from​
andriy [413]

Answer:

Two or more languages are used for making one particular software.

5 0
2 years ago
How long before a speech should you begin practicing?
hichkok12 [17]

Answer:

D

Explanation:

4 0
3 years ago
Read 2 more answers
Other questions:
  • What is tuple and attribute of a relation​
    11·1 answer
  • A culture that emphasizes verbal communication skills is ____________.
    9·2 answers
  • What's the best way to change the font size of all your notes pages at once?
    6·1 answer
  • Digital libraries are often available to students and/or employees at colleges, schools, and BLANK institutions.
    15·1 answer
  • Digital dashboards provide the decision makers with a quick overview of key performance indicators and other key operational sta
    13·1 answer
  • This program outputs a downwards facing arrow composed of a rectangle and a right triangle. The arrow dimensions are defined by
    8·1 answer
  • Fourlotts Corp. provide integrated services that include storing manufactured goods, packaging, and delivering it to the dealers
    13·1 answer
  • What would the internet be like today if there was no World Wide Web?
    9·1 answer
  • Who know's web Design
    12·1 answer
  • 1)What is the hydropower resources/energy?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!