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

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/A

lgorithm to search the heavy orange, in how many steps would you be able to find it out?
Computers and Technology
1 answer:
aalyn [17]3 years ago
7 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:

You might be interested in
During the maintenance phase of the sdlc, the team must _____ if a system's objectives are not being met
Darya [45]

During the maintenance phase of the sdlc, the team must take the correct action if a system's objectives are not being met

<h3>What are the 5 phases of the traditional SDLC Software Development process)?</h3>

Software process is the set of activities that constitute the development of a computer system. These activities are grouped into phases, such as: requirements definition, analysis, design, development, testing and deployment.

The main focus of this phase of the SDLC is to ensure that the needs continue to be met and that the system continues to function as per the specification mentioned in the first phase.

See more about SDLC at brainly.com/question/14096725

#SPJ1

8 0
2 years ago
You should always be afraid to use the internet<br><br> True or false?
ch4aika [34]

Answer:

false

Explanation:

you should be but in the same time no

7 0
3 years ago
Need the answer ASAP!!!
Vlad1618 [11]

Answer: type and create of the software

Explanation:

pls mark brainliest

6 0
3 years ago
How do you copy a file​
trasher [3.6K]

Answer:

right click and press control c

8 0
3 years ago
All who are interested in forex trading and bitcoin mining follow me for account management to all who are busy with work so i c
masya89 [10]

I am very interested but too young just 10

8 0
3 years ago
Other questions:
  • A boolean variable named rsvp an int variable named selection, where 1 represents "beef", 2 represents "chicken", 3 represents "
    14·1 answer
  • How to reply to text from unknown number?
    11·1 answer
  • What are the coordinates of (3 comma space 8 )relative to the basis open curly brackets space (1 comma space 1 )comma space (0 c
    15·1 answer
  • The ability to anticipate and determine upcoming driving hazards and conditions are adversely affected
    14·1 answer
  • Explain why it is important to follow a course or a program in keeping with your value system​
    13·1 answer
  • Which of the following are causes of a run-time error. Choose all that apply.
    13·1 answer
  • PLZ HELP ASAP
    13·1 answer
  • The Curiosity Rover has recently landed on Mars and likes to send Twitter updates on its progress. If a tweet is posted 10 minut
    6·1 answer
  • What do you call a collection of pre-programmed commands and functions used in programs?
    10·1 answer
  • What is the name for data generated by a computer using an algorithm?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!