8 votes 8 votes Construct the Max Heap assuming the following set of integers were inserted into it in given order 20, 32, 1, 3, 4, 5, 6, 7, 10, 23, 45 Postorder traversal of the resultant max heap was stored in a array A with an index variable inorder (Starting from 0). Similarly level order traversal was stored in the array B using index variable j in order (Starting from 0). For particular element, respective i and j location values from A and B were obtained and |i – j| is calculated. What could be the maximum possible value for |i – j|? DS data-structures binary-heap numerical-answers + – kallu singh asked Aug 20, 2017 recategorized Jul 7, 2022 by Lakshman Bhaiya kallu singh 2.6k views answer comment Share Follow See all 2 Comments See all 2 2 Comments reply Shubhanshu commented Aug 20, 2017 reply Follow Share 10?? 0 votes 0 votes Reenakhanna commented Oct 29, 2020 reply Follow Share I am confused what is this line means I and j location values which mean [i] value stored in i th location 0 votes 0 votes Please log in or register to add a comment.
4 votes 4 votes according to ques array A for postorder traversal of the resultant max heap. and level order traversal was stored in the array B A 7 3 10 20 4 23 32 5 1 6 45 B 45 32 6 10 23 5 1 7 3 20 4 from arrays A and B as shown above we can clearly find max value of |i-j| . in array A 45 is in index 10 whereas in array B 45 is in index 0 so max value of |i-j| is 10-0=10 rajoramanoj answered Aug 20, 2017 rajoramanoj comment Share Follow See all 4 Comments See all 4 4 Comments reply sourav. commented Aug 25, 2017 reply Follow Share answer will be 10 , but your solution is incorrect . Resultant max heap/Level order traversal will be -: $45,32,6,10,23,5,1,7,3,20,4$ and Post order traversal of resultant max heap will be -: $7,3,10,20,4,23,32,5,1,6,45$ maximum size of $| i-j |=10$(for $45$) https://visualgo.net/en/heap 0 votes 0 votes rajoramanoj commented Aug 25, 2017 reply Follow Share thank u @ sourav.for point out my mistake now it is correct you can check 0 votes 0 votes arun yadav commented Sep 22, 2020 reply Follow Share your postorder and level order is wrong. 0 votes 0 votes Ronak.e3 commented May 25, 2021 reply Follow Share Both the postorder and level order is wrong but the answer is 10 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes postorder : 3,7,10,4,20,23,32,1,5,6,45 Levelorder :45,32,6,10,23,1,5,3,7,4,20 i-j = 10-0= 10 Ronak.e3 answered May 25, 2021 Ronak.e3 comment Share Follow See all 0 reply Please log in or register to add a comment.