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
For some transformation having kinetics that obey the Avrami equation, the parameter n is known to have a value of 2. If, after
kotegsom [21]

This question is incomplete, the complete question is;

For some transformation having kinetics that obey the Avrami equation, the parameter n is known to have a value of 2. If, after 100 s, the reaction is 40% complete, how long (total time in seconds) will it take the transformation to go to 95% completion

y = 1 - exp( -ktⁿ )

Answer: the time required for 95% transformation is 242.17 s

Explanation:

First, we calculate the value of k which is the dependent variable in Avrami equation

y = 1 - exp( -ktⁿ )

exp( -ktⁿ ) = 1 - y

-ktⁿ = In( 1 - y )

k = - In( 1 - y ) / tⁿ

now given that; n = 2, y = 40% = 0.40, and t = 100 s

we substitute

k = - In( 1 - 0.40 ) / 100²

k = - In(0.60) / 10000

k = 0.5108 / 10000

k = 0.00005108 ≈ 5.108 × 10⁻⁵

Now calculate the time required for 95% transformation

tⁿ = - In( 1 - y ) / k

t = [- In( 1 - y ) / k ]^1/n

n = 2, y = 95% = 0.95 and k = 5.108 × 10⁻⁵

we substitute our values

t = [- In( 1 - 0.95 ) / 5.108 × 10⁻⁵ ]^1/2

t = [2.9957 / 5.108 × 10⁻⁵]^1/2

t = [ 58647.22 ]^1/2

t = 242.17 s

Therefore the time required for 95% transformation is 242.17 s

8 0
3 years ago
Which of the following explains the main reason to cut a piece of wood on the outside of the measurement mark?
maks197457 [2]
I think it’s D ?? I’m not completely sure tho
4 0
3 years ago
2. When it comes to selling their crop, what are 3 options a farmer has when harvesting their grain?
tiny-mole [99]

Answer:

Sell his crop, use his crop as food, and sell his crop

Explanation:

6 0
3 years ago
Design a plate and frame heat exchanger for the following problem:
qwelly [4]

Answer:

See explaination and attachment.

Explanation:

Iteration method is a repetitive method applied until the desired result is achieved.

Let the given equation be f(x) = 0 and the value of x to be determined. By using the Iteration method you can find the roots of the equation. To find the root of the equation first we have to write equation like below

x = pi(x)

Let x=x0 be an initial approximation of the required root α then the first approximation x1 is given by x1 = pi(x0).

Similarly for second, thrid and so on. approximation

x2 = pi(x1)

x3 = pi(x2)

x4 = pi(x3)

xn = pi(xn-1).

please go to attachment for the step by step solution.

8 0
3 years ago
Where does Mr. Teller work? What do they do there?
natulia [17]

Most business owners begin his business in order to increase profit and to expand.

<h3>What are Business Practices?</h3>

This refers to the various ways in which a business owner decides to organize his business and the policies which guides it.

With this in mind, we can see that Mr X believes that it is a good business practice to <em>prioritize the work</em> that seems the most difficult and the most likely to kill their projects but this is not a good business practice because it can put the entire business in jeopardy.

Please note that your question is incomplete so I gave you a general overview so that you could get a better understanding of the concept.

Read more about business practises here:
brainly.com/question/1343903

7 0
2 years ago
Other questions:
  • If you know that the change in entropy of a system where heat was added is 12 J/K, and that the temperature of the system is 250
    10·1 answer
  • Pascal's law tells us that, pressure is transmitted undiminished throughout an open container. a)- True b) False
    9·1 answer
  • The four strokes in a four stroke cycle engine in proper order.
    7·1 answer
  • A square loop of wire surrounds a solenoid. The side of the square is 0.1 m, while the radius of the solenoid is 0.025 m. The sq
    6·1 answer
  • List the three main methods employed in dimensional analysis
    6·1 answer
  • An incompressible fluid flows along a 0.20-m-diameter pipe with a uniform velocity of 3 m/s. If the pressure drop between the up
    15·1 answer
  • Before accurate distance standards, a cubit was the length of whose forearm?
    5·1 answer
  • Which of the following parts tells the transmission how fast or slowly a vehicle is going? A) pump
    5·1 answer
  • What speeds did john j montgomerys gliders reach
    12·1 answer
  • Question 2: (a) In your own words, clearly distinguish and differentiate between Ethics in Engineering and Ethics in Computing (
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!