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 statement correctly explains why televisions became less bulky?
REY [17]

Answer:

The old cathode Ray tube technology was replaced by the less bulkier and more modern liquid crystal display and LED technology.

Explanation:

The old cathode ray tube uses the principle of electrical discharge in gas. Electrons moving through the gas, and deflected by magnetic fields, strike the screen, producing images and a small amount of X-rays. The tube required more space, and consumed more electricity, and was very bulky. The modern technologies are more compact and consume less power, and can been designed to be sleek and less bulky.

3 0
3 years ago
When you are making multiples of a brownie recipe, you cannot - without great difficulty - use a fraction of an egg. The calcula
Lera25 [3.4K]
The answer is one ☝️ question for the poll of a vote
5 0
2 years ago
You are troubleshooting an issue where a PC can reach some hosts on the Internet (using either DNS name or IP address), while se
wolverine [178]

The options are missing from the question,below are the options to choose from;

A) incorrect (or missing) routes in a routers routing table

B) incorrect DNS configuration on the PC

C) incorrect default gateway configuration on the PC

D) duplicate IP addresses on your LAN

Answer: The correct answer to the question is option A

INCORRECT (OR MISSING) ROUTES IN A ROUTERS ROUTING TABLE.

Explanation: When it is possible for a PC to ping some devices but not actually all,we can then make an assumption that either it has a wrong subnet that is configured or the router from the path to the remote device actually has an incorrect or a missing routes to the device.

5 0
3 years ago
Name the types of computer used in hospital for computer​
disa [49]

Answer: These are all the computers they use All.

All In One Computers.

Medical Grade Computers.

Medical Tablets.

Medical Box PCs.

Medical Box PCs.

Displays & Monitors.

Medical Grade Monitors.

5 0
3 years ago
Traditional methods of collecting systems requirements include: a. rapid application development. b. prototyping. c. interviews.
diamong [38]

Answer:

interviews

Explanation:

because the designer gets to directly interact with the customer who knows exactly what they want.

3 0
1 year ago
Other questions:
  • Yet another variation: A better packet switched network employs the concept of acknowledgment. When the end user’s device receiv
    11·1 answer
  • Who invented the machine known as colossus?
    9·2 answers
  • What is application software used for
    13·1 answer
  • Which processor family is most likely found on recent gaming laptops (Gaming laptops require a lot of computational power)?
    11·1 answer
  • Witch icon allows you to see paragraph formatting feature
    6·1 answer
  • All cells in row 2 through 5 are referred as 2:5 true or false
    10·1 answer
  • The while loop and the do loop are equivalent in their expressive power; in other words, you can rewrite a while loop using a do
    6·1 answer
  • Describe the layout of an article on Wikipedia​
    7·1 answer
  • Alexander studies sitting on the edge of his bed with his laptop on his lap. he complains of a sore neck. how can he best improv
    6·1 answer
  • If you anticipate running a particular query often, you can improve overall performance by saving the query in a special file ca
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!