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
Which of the following accurately describes one way that individual goods
Sladkaya [172]
I just did this problem and it is d people can be excluded from using individual goods if they don’t pay
3 0
3 years ago
What is the protocol in the web search at the bottom?
klasskru [66]
(D) HTTP, or hyper-text transfer protocol, is the standard or set of rules that governs how web pages are sent over the internet.
3 0
3 years ago
What does Al stand for?
prohojiy [21]
AI stands for Artificial Intelligence
5 0
3 years ago
Privacy Group of answer choices must be respected if we are to function as complete, self-governing agents is an absolute value
ElenaW [278]
Privacy group in article 3 in constitution section 3 too
8 0
3 years ago
For how long should a media piece hold the user's attention?
Nastasia [14]

Answer:

C) until the message has been communicated

5 0
3 years ago
Read 2 more answers
Other questions:
  • Liz will use a CD-R compact disk to write to more than once. Carlo will use a CD-RW compact disk to write to more than once. Who
    8·2 answers
  • Which is true about POP3 and IMAP for incoming email?
    6·1 answer
  • The major difference between a calculator and a computer, when performing calculations, is that a
    10·1 answer
  • What is the purpose of exporting your public key to the directory services server?
    11·1 answer
  • An attacker compromises the Washington Post's web server and proceeds to modify the homepage slightly by inserting a 1x1 pixel i
    12·1 answer
  • Apple's macOS and Microsoft Windows are examples of ________ software. utility application communication operating system
    13·1 answer
  • Short notes on Supply chain Management System (SCMS)
    12·1 answer
  • Why can it be helpful to perform mathematical calculations using programming? Choose the best answer.
    11·1 answer
  • Can somebody please help me with these few questions?
    11·1 answer
  • What is the action of extracting data fragments and then reassembling them in order to recover a file?.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!