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
Natalie wants to create a database to collect information about sales transactions. She would like to use the database to look u
Lynna [10]

Answer:

Customer Table

  1. Customer name
  2. Customer id

Product Table

  1. Product id/number (primary key, auto increment)
  2. Product name
  3. Product sale price

Transactions Table

  1. Transaction Id
  2. Customer Id
  3. Product id
  4. Quantity
  5. Price
  6. Date

Explanation:

Natalie wants to fetch following information from database

  1. Look up customer name and sale price
  2. Sort items in db by product number

To lookup customer name and sale price perform a join on Transactions table and Customer table.Assuming database is build in mysql the query to fetch required results would be

select transction.productId,transaction.customerid,customer.customername from transactions join customer ON

customer.customerid=transcation.customerid

where productid="user provided product id of returned product"

For sorting products by number set produc number in product table a auto increment primary key

7 0
3 years ago
Various gabs in the digital divide​
Alisiya [41]

Answer:

factors such as low literacy and income level Geographical restriction lack of motivation motivation of the technology lack of motivation to use technology and digital illiteracy and contribute to the digital device

4 0
2 years ago
A puppy weighed 6 ounces at birth. After two weeks, the puppy weighed 14 ounces. How much did the puppy gain? Model the equation
ivann1987 [24]
+8 ounces ...don't know what an alrebra tile so I just subtracted :)
7 0
2 years ago
Read 2 more answers
Pat is listing the parts of a computer. Which is the best option to use when formatting the list?
Zina [86]
If you mean a web page ten the bet option would be elements, where gives you an unordered list and give you an order list
5 0
3 years ago
Rock, Paper, Scissors is a two-player game in which each player chooses one of three items. If both players choose the same item
mezya [45]

Answer:

The answer is c

Explanation:

7 0
3 years ago
Other questions:
  • the task is to ask the user for three numbers and find the average which pseudocode gives you the comment outline for task​
    10·1 answer
  • When does state law require drivers to use their headlights (6)
    11·2 answers
  • Two powerboats are about to cross paths. what should the boat on the starboard (right) do?
    11·1 answer
  • Which of the following is not an advanced strategy you may use to help you conduct a search on the Internet?
    12·1 answer
  • Write a complete Java method that returns an integer. The method declares a Scanner object, then prompts the user for a series o
    12·1 answer
  • Please help. will give u brainliest!! khan academy computers and the internet!!
    12·1 answer
  • In a black box model are the customers told that they should be expecting to be haxked?
    13·1 answer
  • Alice recently purchased a new cell phone. After her vacation, Alice wanted to transfer her holiday photos to her computer to do
    8·1 answer
  • In cell b12 create a formula using max f7nction to calculate maximum value in B4:B9
    7·1 answer
  • write a function named get majority last name that accepts as its parameter a dictionary from strings to strings the keys of the
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!