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
lara31 [8.8K]
3 years ago
9

For this problem, you may not look at any other code or pseudo-code (even if it is on the internet), other than what is on our w

ebsite or in our book. You may discuss general ideas with other people. Assume A[1. . . n] is a heap, except that the element at index i might be too large. For the following parts, you should create a method that inputs A, n, and i, and makes A into a heap.
Engineering
1 answer:
sergiy2304 [10]3 years ago
8 0

Answer:

(a)

(i) pseudo code :-

current = i

// assuming parent of root is -1

while A[parent] < A[current] && parent != -1 do,

if A[parent] < A[current] // if current element is bigger than parent then shift it up

swap(A[current],A[parent])

current = parent

(ii) In heap we create a complete binary tree which has height of log(n). In shift up we will take maximum steps equal to the height of tree so number of comparison will be in term of O(log(n))

(b)

(i) There are two cases while comparing with grandparent. If grandparent is less than current node then surely parent node also will be less than current node so swap current node with parent and then swap parent node with grandparent.

If above condition is not true then we will check for parent node and if it is less than current node then swap these.

pseudo code :-

current = i

// assuming parent of root is -1

parent is parent node of current node

while A[parent] < A[current] && parent != -1 do,

if A[grandparent] < A[current] // if current element is bigger than parent then shift it up

swap(A[current],A[parent])

swap(A[grandparent],A[parent])

current = grandparent

else if A[parent] < A[current]

swap(A[parent],A[current])

current = parent

(ii) Here we are skipping the one level so max we can make our comparison half from last approach, that would be (height/2)

so order would be log(n)/2

(iii) C++ code :-

#include<bits/stdc++.h>

using namespace std;

// function to return index of parent node

int parent(int i)

{

if(i == 0)

return -1;

return (i-1)/2;

}

// function to return index of grandparent node

int grandparent(int i)

{

int p = parent(i);

if(p == -1)

return -1;

else

return parent(p);

}

void shift_up(int A[], int n, int ind)

{

int curr = ind-1; // because array is 0-indexed

while(parent(curr) != -1 && A[parent(curr)] < A[curr])

{

int g = grandparent(curr);

int p = parent(curr);

if(g != -1 && A[g] < A[curr])

{

swap(A[curr],A[p]);

swap(A[p],A[g]);

curr = g;

}

else if(A[p] < A[curr])

{

swap(A[p],A[curr]);

curr = p;

}

}

}

int main()

{

int n;

cout<<"enter the number of elements :-\n";

cin>>n;

int A[n];

cout<<"enter the elements of array :-\n";

for(int i=0;i<n;i++)

cin>>A[i];

int ind;

cout<<"enter the index value :- \n";

cin>>ind;

shift_up(A,n,ind);

cout<<"array after shift up :-\n";

for(int i=0;i<n;i++)

cout<<A[i]<<" ";

cout<<endl;

}

Explanation:

You might be interested in
How to design a solar panel<br>​
artcher [175]

Answer:

#1) Find out how much power you need

#2 Calculate the amount of batteries you need.

#3 Calculate the number of solar panels needed for your location and time of year.

#4 Select a solar charge controller.

#5 Select an inverter.

#6 Balance of system

Explanation: To design solar panel, consider the following steps

1.) Find the power consumption demands

The first step in designing a solar PV system is to find out the total power and energy consumption of all loads that need to be supplied by the solar PV system as follows:

Calculate total Watt-hours per day for each appliance used.

 Add the Watt-hours needed for all appliances together to get the total Watt-hours per day which must be delivered to the appliances.

Calculate total Watt-hours per day needed from the PV modules.

Multiply the total appliances Watt-hours per day times 1.3 (the energy lost in the system) to get the total Watt-hours per day which must be provided by the panels.

2. Size the PV modules

Different size of PV modules will produce different amount of power. To find out the sizing of PV module, the total peak watt produced needs. The peak watt (Wp) produced depends on size of the PV module and climate of site location. We have to consider panel generation factor which is different in each site location. For Thailand, the panel generation factor is 3.43. To determine the sizing of PV modules, calculate as follows:

2.1 Calculate the total Watt-peak rating needed for PV modules

Divide the total Watt-hours per day needed from the PV modules (from item 1.2) by 3.43 to get the total Watt-peak rating needed for the PV panels needed to operate the appliances.

Calculate the number of PV panels for the system

Divide the answer obtained in item 2.1 by the rated output Watt-peak of the PV modules available to you. Increase any fractional part of result to the next highest full number and that will be the 

number of PV modules required.

Result of the calculation is the minimum number of PV panels. If more PV modules are installed, the system will perform better and battery life will be improved. If fewer PV modules are used, the system may not work at all during cloudy periods and battery life will be shortened.

3. Inverter sizing

An inverter is used in the system where AC power output is needed. The input rating of the inverter should never be lower than the total watt of appliances. The inverter must have the same nominal voltage as your battery.

For stand-alone systems, the inverter must be large enough to handle the total amount of Watts you will be using at one time. The inverter size should be 25-30% bigger than total Watts of appliances. In case of appliance type is motor or compressor then inverter size should be minimum 3 times the capacity of those appliances and must be added to the inverter capacity to handle surge current during starting.

For grid tie systems or grid connected systems, the input rating of the inverter should be same as PV array rating to allow for safe and efficient operation.

4. Battery sizing

The battery type recommended for using in solar PV system is deep cycle battery. Deep cycle battery is specifically designed for to be discharged to low energy level and rapid recharged or cycle charged and discharged day after day for years. The battery should be large enough to store sufficient energy to operate the appliances at night and cloudy days. To find out the size of battery, calculate as follows:

     4.1 Calculate total Watt-hours per day used by appliances.

     4.2 Divide the total Watt-hours per day used by 0.85 for battery loss.

     4.3 Divide the answer obtained in item 4.2 by 0.6 for depth of discharge.

     4.4 Divide the answer obtained in item 4.3 by the nominal battery voltage.

     4.5 Multiply the answer obtained in item 4.4 with days of autonomy (the number of days that you need the system to operate when there is no power produced by PV panels) to get the required Ampere-hour capacity of deep-cycle battery.

Battery Capacity (Ah) = Total Watt-hours per day used by appliancesx Days of autonomy

(0.85 x 0.6 x nominal battery voltage)

5. Solar charge controller sizing

The solar charge controller is typically rated against Amperage and Voltage capacities. Select the solar charge controller to match the voltage of PV array and batteries and then identify which type of solar charge controller is right for your application. Make sure that solar charge controller has enough capacity to handle the current from PV array.

For the series charge controller type, the sizing of controller depends on the total PV input current which is delivered to the controller and also depends on PV panel configuration (series or parallel configuration).

According to standard practice, the sizing of solar charge controller is to take the short circuit current (Isc) of the PV array, and multiply it by 1.3

Solar charge controller rating = Total short circuit current of PV array x 1.3

5 0
3 years ago
Viscous effects are negligible outside of the hydrodynamic boundary layer. (3 points) a. True b. False
Valentin [98]

Answer:

I would say false but I am not for sure

8 0
2 years ago
Explain how use of EGR is effective in reducing NOx emissions 4. In most locations throughout the U.S., the octane number of reg
TiliK225 [7]

Answer:please see attached file

Explanation:

3 0
3 years ago
What is the net force acting on a car cruising at a constant velocity of 70 km/h (a) on a level road and (b) on an uphill road?
ElenaW [278]

Answer:

a) zero b) zero

Explanation:

Newton's first law tells us that a body remains at rest or in uniform rectilinear motion, if a net force is not applied on it, that is, if there are no applied forces or If the sum of forces acting is zero. In this case there is a body that moves with uniform rectilinear motion which implies that there is no net force.

4 0
2 years ago
Tech A says that the brake pedal uses leverage to multiply foot pressure. Tech B says that when braking hard while moving
Nikolay [14]

Tech- A is correct

Explanation:

  • Leverage is defined as using a tool to gain mechanical influence. The measure of the benefit gained depends on what kind of lever is used and how it is utilized.
  • Leverage is designed in such a way that it can reproduce the force from your leg many times before any force is transferred to brake fluid.
  • The brake pedal size and the measure of leverage received depends on the overall design of the brake system.
  • The second-order lever is used in the brake pedal. The brake pedal applies leverage to populate the force employed to the master cylinder. The effort needed to drive a load depends on the corresponding distance of the load and the work from the fulcrum. The proportion of load and work is known as mechanical advantage.
7 0
3 years ago
Other questions:
  • A 12-mm-diameter cylindrical jet of water discharges vertically into the ambient air. Due to surface tension the pressure inside
    14·1 answer
  • Consider the circuit below where R1 = R4 = 5 Ohms, R2 = R3 = 10 Ohms, Vs1 = 9V, and Vs2 = 6V. Use superposition to solve for the
    15·1 answer
  • An inventor claims to have developed a power cycle operating between hot and cold reservoirs at 1175 K and 295 K, respectively,
    9·1 answer
  • What is the connection between the air fuel ratio and an engine running rich/poor? please give clear examples and full sentances
    9·1 answer
  • A motor driven water pump operates with an inlet pressure of 96 kPa (absolute) and mass flow rate of 120 kg/min. The motor consu
    7·1 answer
  • The compression ratio of most small gasoline engines falls between_______and________.
    13·2 answers
  • What should you use to keep battery terminals from corroding
    12·1 answer
  • The driver should be able to see the ground within _____ to the front?
    14·1 answer
  • A composite plane wall consists of a 5-in.-thick layer of insulation (ks = 0.029 Btu/h*ft*°R) and a 0.75-in.-thick layer of sidi
    11·1 answer
  • Write down the tracking error such that the adaptive cruise control objective is satisfied.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!