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
zalisa [80]
3 years ago
8

If you have 128 oranges all the same size, color, and weight except one orange is heavier than the rest. Write down a C++ Code t

o search the heavy orange, in how many steps would you be able to find it out in worst case?
Computers and Technology
1 answer:
dangina [55]3 years ago
3 0

Answer:

#include <iostream>

using namespace std;

void Search_heavy_orange(int arr[], int l, int r, int x)

{

int count = 0, m = 0;

while (l <= r) {

 m = l + (r - l) / 2;

 // Check if x is present at mid

 if (arr[m] == x) {

  count++;

 }

 // If x greater, ignore left half

 if (arr[m] < x) {

  l = m + 1;

  count++;

   

 }

 

 // If x is smaller, ignore right half

 else {

  r = m - 1;

  count++;

 }

}

cout << "............For Worst Case......." << endl;

cout << "Orange with heavy weight is present at index " << m << endl;

cout << "Total number of step performed : " << count << endl;

}

int main()

{

// Assuming each orange is 100 gm and the weight of heavy

// orange is 150 gm

int orange_weight[128];

for (int i = 0; i < 127; i++) {

 orange_weight[i] = 100;

}

// At worst case the heavy orange should be at last position

// inside the basket : 127

orange_weight[127] = 150;

// We will pass array , start index , last index and the search element

// as the parameters in the function Search_heavy_orange

Search_heavy_orange(orange_weight, 0, 127, 150);

return 0;

}

Explanation:

this is it. it display for the worst case

You might be interested in
again assume that each of the resistors in the circuit shown above has a resistance value of 100k(question in the picture above)
Svetllana [295]
Statement A is true. R4 is not part of the circuit since it has one terminal not connected. The other resistors are in series, so the same current flows through them. Hence they will dissipate equal power.
4 0
3 years ago
In what ways are computers being used to improve our quality of life
serg [7]

Explanation:

makes info easy to get

improves communication

enhances education

etc

plsss mark me brainliesttt

3 0
3 years ago
Some hardware can be added to the computer without having to restart or power down the computer. After a short period of time th
faltersainse [42]

Answer:

Plug and play technology

Explanation:

Plug and play technology also know as PnP allows user to directly connect devices to a computer and start using inmediatly. Other way user must have to search and install drivers for each component.

Usually PnP comes for regular use devices like: Keyboards, mouses, flashmemories, cameras, and others

8 0
3 years ago
Which type of presentation is best for a presentation about the benefits of aerobic exercise?
insens350 [35]
Let's go with a Microsoft office power point presentation
7 0
3 years ago
How do you level up? I don't have spells on here like I do in w.o.w
umka2103 [35]
You answer questions and complete challenges to get points, and for higher levels, you also have to get enough Brainliest answers.
8 0
3 years ago
Read 2 more answers
Other questions:
  • Which of these is an on-site metric for social media marketing?
    13·1 answer
  • How were the pages made to create the Book of Kells? a. Scribes prepared the papers using a printing press. b. 185 calves were s
    9·1 answer
  • 3. Of the following pieces of information in a document, for which would you most likely insert a mail merge field? A. First nam
    13·2 answers
  • ________ is used for supervisory messages at the internet protocol layer.
    10·1 answer
  • The presentation ____ determines the formatting characteristics of fonts and colors.
    11·2 answers
  • Select each task that may be completed using a word processor.
    8·2 answers
  • Which graphics format works best for desktop publishing and print work? (1 point) .tiff .gif .tga .jpeg?
    11·1 answer
  • What is the function of a bread crumb trial in a website
    11·1 answer
  • What commands does SuperKarel know that regular Karel does not?
    11·1 answer
  • What is the advantage of entering metadata for electronic records that you create
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!