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]
3 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]3 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
Program MATH_SCORES: Your math instructor gives three tests worth 50 points each. You can drop one of the test scores. The final
Simora [160]

Answer:

import java.util.Scanner;

public class num5 {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       //Prompt and receive the three Scores

       int score1;

       int score2;

       int score3;

       do {

           System.out.println("Enter first Score Enter score between 1 -50");

           score1 = in.nextInt();

       } while(score1>50 || score1<0);

       do {

           System.out.println("Enter second Score.The second score must be between 1 -50");

           score2 = in.nextInt();

       } while(score2>50 || score2<0);

       do {

           System.out.println("Enter Third Score Third score must between 1 -50");

           score3 = in.nextInt();

       } while(score3>50 || score3<0);

       //Find the minimum of the three to drop

       int min, min2, max;

       if(score1<score2 && score1<score3){

           min = score1;

           min2 = score2;

           max = score3;

       }

       else if(score2 < score1 && score2<score3){

           min = score2;

           min2 = score1;

           max = score3;

       }

       else{

           min = score3;

           min2 = score1;

           max = score2;

       }

       System.out.println("your entered "+max+", "+min2+" and "+min+" the min is");

       int total = max+min2;

       System.out.println("Total of the two highest is "+total);

       //Finding the grade based on the cut-off points given

       if(total>=90){

           System.out.println("Grade is A");

       }

       else if(total>=80){

           System.out.println("Grade is B");

       }

       else if(total>=70){

           System.out.println("Grade is C");

       }

       else if(total>=60){

           System.out.println("Grade is D");

       }

       else{

           System.out.println("Grade is F");

       }

   }

}

Explanation:

  • Implemented with Java
  • Use the scanner class to receive user input
  • Use a do.....while loop to validate user input for each of the variables. A valid score must be between 0 and 50 while(score>50 || score<0);  
  • Use if and else to find the minimum of the three values and drop
  • Add the two highest numbers
  • use if/else if /else statements to print the corresponding grade
8 0
3 years ago
You are a solutions architect who works at a large retail company that is migrating its existing infrastructure to AWS. You reco
pantera1 [17]

In this case, there are 251 IP addresses available. They are unique addresses for the Internet Protocol.

<h3>What is an IP address?</h3>

An Internet Protocol (IP) address is a unique address on Internet, which is used to indicate a local network.

The term 'Internet Protocol' indicates the principles associated with the format of the data used by the local network.

An Internet Protocol address is always denoted by a set of numerical tags that indicate the local network.

Learn more about IP address here:

brainly.com/question/24930846

6 0
2 years ago
What came first, the internet or WIFI?
horsena [70]

Answer: wifi

Explanation:

because you can't have the internet if you don't have wifi to power it up

4 0
3 years ago
The four functions of a computer are
ehidna [41]
The four basic functions of a computer are input, processing, output and storage.
6 0
3 years ago
Which of the following can you use to add a picture to your presentation?
Advocard [28]
You can use photo art to help show a product or a certain piece of technology to help give a better idea of a product or thing you're trying to demonstrate to your class or people.
7 0
3 years ago
Other questions:
  • How can I get a refund of my money back
    12·2 answers
  • The operating system is not directly involved in one of these tasks.Immersive Reader
    12·1 answer
  • Jessica is working on a report for her art history class. She is using Microsoft Word for her report so that she can incorporate
    6·2 answers
  • Which of the choices Sean are not true when considering virus behavior
    9·1 answer
  • Design a Ship class with the following members:
    13·1 answer
  • Create a class template for a class named GeneralStackthat holds
    8·1 answer
  • Can somebody tell me the Minecraft command to clear an entire world and destroy every block if u Dunno please don’t answer &gt;-
    13·1 answer
  • What is the most important person and why
    10·1 answer
  • You can enter common data in multiple worksheets by __________.
    14·2 answers
  • One of the many roles of the security compliance committee is to focus on controls that are widely used across a large populatio
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!