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
Why must air tanks be drained​
Jobisdone [24]
Water can freeze in cold weather and cause brake failure.
7 0
3 years ago
A cantilever beam of length L = 70 in is made from two side-by-side structural-steel channels of size 3 in weighing 5.0 lbf/ft.
natali 33 [55]

Answer:

of 5 lb/ft and a concentrated service live load at midspan. .... length = 12 feet) to support a uniformly distributed load. Taking ... w 7..'{ 'f.- ~ s-·. 344 ft-kip. Fy : s-o ks I. 299 ft-kip. Li.. ::::- I 2.. }-t-. 150 ft-kip ..... The concrete and reinforcing steel properties are ... Neglecting beam self-weight . and based only on the ...... JI : Lf, 2. l.. ;VI.

Explanation:

6 0
3 years ago
A 1000 kg turbine has a rotating unbalance of 0.1 kg.m. The turbine operates at a speed between 500 to 750 rpm. What is the maxi
raketka [301]

Answer:

maximum isolator stiffness k =1764 kN-m

Explanation:

mean speed of rotation =\frac{N_1 +N_2}{2}

Nm = \frac{500+750}{2} = 625 rpm

w =\frac{2\pi Nm}{60}

  =65.44 rad/sec

F_T = mw^2 e

F_T = mew^2

       = 0.1*(65.44)^2

F_T =428.36 N

Transmission ratio =\frac{300}{428.36} = 0.7

also

transmission ratio = \frac{1}{[\frac{w}{w_n}]^{2} -1}

0.7 =\frac{1}{[\frac{65.44}{w_n}]^2 -1}

SOLVING FOR Wn

Wn = 42 rad/sec

Wn = \sqrt {\frac{k}{m}

k = m*W^2_n

k = 1000*42^2 = 1764 kN-m

k =1764 kN-m

3 0
3 years ago
__________<br> is an accurate way of drawing that shows an object's<br> true size and shape.
Bingel [31]
ANSWER:

Detail drawing
6 0
3 years ago
A person is planning a bungee jump from a 40 meter high bridge. Under the bridge is a river with crocodiles, so the person does
Nonamiya [84]

Answer:

a. l = 19.7m, b. 18.55m, c. Impact Force = 3889.84 N

Explanation:

The total energy of the system when the person is at top of the bridge is

Potential energy = mgh, Kinetic energy = 0

The total energy of the  system when the person reaches just above the surface

Potential energy = 0, Kinetic energy = 0, Spring energy = ½ K X2, where k is the spring constant and X is the deflection

Applying conservation of energy

mgh = 0 + 0 + ½ K X²

80 x 9.81 x 40 = ½ (3600/l) X²

31392 = ½ (3600/l) X²

We can also conclude that

l+ X + 1.75 = 40

l + X = 38.25

a. <u>Substitute the value of x from above into the energy conversion expression</u>

31392 = ½ (3600/l)(38.25 - l)²

31392 x 2/3600 = (38.25 + l² – 2l(38.25))/l

17.44l = l2 – 76.5l + 38.25²

l² – 76.5l – 17.44l +1463.0625 = 0

Solving for l we get

L = 19.7

Hence, length of the rope is 19.7m

b. <u>The deflection is calculated by using the relation between l and X</u>

L + X = 38.25

X = 38.25 – 19.7 = 18.55m

c. <u>The impact force is calculated using the impact force formula which relates the impact force with the deflection</u>

F = KX

F = (3600/l) . X

F = (3600/19.7) . (18.55) = 3889.84 N

Thus, the impact force is 3889.84 N

3 0
3 years ago
Other questions:
  • A rod is 2m long at temperature of 10oC. Find the expansion of the rod, when the temperature is raised to 80oC. If this expansio
    7·1 answer
  • In the contemporary approach to control systems, benefits of continuous monitoring include which one of the following? Multiple
    9·1 answer
  • What Degree Do You Need To Become a Solar Engineer?<br> (2 or more sentences please)
    13·1 answer
  • A force that attempts to decrease the length of a structural member is____
    14·1 answer
  • A multilane highway (two lanes in each direction) is on level terrain. The free-flow speed has been measured at 45 mi/h. The pea
    5·1 answer
  • Steam at 1400 kPa and 350°C [state 1] enters a turbine through a pipe that is 8 cm in diameter, at a mass flow rate of 0.1 kg⋅s−
    15·1 answer
  • You are hired as the investigators to identify the root cause and describe what should have occurred based on the following info
    9·1 answer
  • How many times has the ITU-R revised the CCIR 601 international standard? A. four B. five C. six D. seven
    8·1 answer
  • A cross beam in a highway bridge experiences a stress of 14 ksi due to the dead weight of the bridge structure. When a fully loa
    14·1 answer
  • Define waves as it applies to electromagnetic fields
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!