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
When might an lcd monitor experience distorted geometry?
horsena [70]

The time when an LCD monitor is experiencing distorted geometry is when there is a presence of the screen into having a display that is not set on the resolution that is supposed to be in native, this is indicative that it is experiencing distorted geometry.

7 0
3 years ago
A device that is connected to the Internet is known as<br> a. Nexus. Backbone. Node. Link.
ikadub [295]
A device connected to the internet is known as a Node.
3 0
3 years ago
Read 2 more answers
Why is it preferable to code web pages in html format?
Ronch [10]
Depends on what you are working on.

If you are working on a website I recommend Adobe Dreamweaver CC.

if its small assignments that doesnt involve major work, I'd use something like notepad++
8 0
3 years ago
Read 2 more answers
A template class is a class in which ___________.
Romashka [77]

Answer: (A) At least one type is parameterized

Explanation:

 A template class is the type of class in which the one type are parameterized atleast in each template class. The template class mainly provide the various type of specifications so that it can generate the class based on the different types of parameters.

A template class is basically initialized by passing the template argument in the given types. In this type of class atleast one type is defined as the generic type.

Therefore, Option (A) is correct.

6 0
3 years ago
Read 2 more answers
How do you take a picture with this app
Troyanec [42]
You have to be answering someone and to the left of the answer button there will be a camera. Click it and you can take a picture.
7 0
3 years ago
Read 2 more answers
Other questions:
  • What is one difference between a web page and a web application? Web pages provide information, while web applications allow the
    8·1 answer
  • How does a hard drive work
    15·1 answer
  • Rachel wants to post content from digital cameras on the web. Which online tool will help Rachel to post and edit content on a w
    5·1 answer
  • How do you change a account on an iPod generation 5
    10·1 answer
  • In 4-bit sign magnitude representation, what is the binary encoding of the number -5?
    15·1 answer
  • Write: In a five-paragraph essay that is two to three pages in length, address the
    13·1 answer
  • ¿porque y como surge la informatica y las computadoras
    13·1 answer
  • What are the 5 font/typography families
    14·1 answer
  • The most widely used computer device​
    6·2 answers
  • Which keyboard shortcut would you press to copy cells that are selected in a spreadsheet?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!