A binary heap is a complete binary tree which satisfies the heap ordering property. The diagram...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
A binary heap is a complete binary tree which satisfies the heap ordering property. The diagram below illustrates how we would think of the binary min-heap (like a tree). Additionally, the diagram shows the actual Python list which stores the values. 19 13 0 Test 5 7 6 2 3 The root is stored at index 1 For a node at index position p: left child at index 2p right child at index 2p+1 13. 4 8 22 8 19 5 6 7 Define a function called get_sibling (a_list, index) which takes a binary min-heap represented by a Python list and an integer as parameters. The function should return the value of the sibling of the element specified by the parameter index. The function should return None if the index is not in the valid range. Note: you can assume that the parameter list is not empty. For example: 8 Result print (get_sibling ( [0, 5, 7, 6, 13, 8, 22, 8, 19], 1)) None print(get_sibling ( [0, 5, 7, 6, 13, 8, 22, 8, 19], 4)) 8 print (get_sibling ( [0, 5, 7, 6, 13, 8, 22, 8, 191, 8)) None print (get_sibling ( [0, 5, 7, 6, 13, 8, 22, 8, 19], 9)) None A binary heap is a complete binary tree which satisfies the heap ordering property. The diagram below illustrates how we would think of the binary min-heap (like a tree). Additionally, the diagram shows the actual Python list which stores the values. 19 13 0 Test 5 7 6 2 3 The root is stored at index 1 For a node at index position p: left child at index 2p right child at index 2p+1 13. 4 8 22 8 19 5 6 7 Define a function called get_sibling (a_list, index) which takes a binary min-heap represented by a Python list and an integer as parameters. The function should return the value of the sibling of the element specified by the parameter index. The function should return None if the index is not in the valid range. Note: you can assume that the parameter list is not empty. For example: 8 Result print (get_sibling ( [0, 5, 7, 6, 13, 8, 22, 8, 19], 1)) None print(get_sibling ( [0, 5, 7, 6, 13, 8, 22, 8, 19], 4)) 8 print (get_sibling ( [0, 5, 7, 6, 13, 8, 22, 8, 191, 8)) None print (get_sibling ( [0, 5, 7, 6, 13, 8, 22, 8, 19], 9)) None
Expert Answer:
Answer rating: 100% (QA)
the following algorithm Check if the index is at the beginning or beyond the end of the list If it is then the element has no sibling and we should return None Calculate the parent index for the given ... View the full answer
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these computer network questions
-
With new advances in technology, many credit card companies have made it easier for consumers to use their cards just by waving it in front of a card reader machine and charing their purchases...
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-5. Ivan's grandfather died and left a portfolio of municipal bonds. In 2012, they pay Ivan...
-
You are required to write a Python program that will manage character (heroes and villain) information. Character (hero and villain) information will be stored in a text file that will be read in...
-
41.(6 pointa) In the following balanced reaction, magnesium metal (Mg) reacts with carbon dioxide gas (CO) o form solid magnesium exide (MgO) and solid carbon (C). How many grams of carbon dioxide...
-
Suppose a publishing company wants to hire an intern to help the company catch up with its paperwork over the summer. Who would be affected by this decision? What would be the benefits or harm to...
-
Refer to the data in Brief Exercise 15-16. Given this information, what was (a) the variable overhead spending variance for the year, and (b) the variable overhead efficiency variance for the year?
-
Why is it that techniques for putting financial values on eco-assets are fraught with difficulty?
-
Rockport Municipal Marina is considering adding a new dock to accommodate large yachts. The dock would cost $700,000 and would generate $144,000 annually in new cash inflows. Its expected life would...
-
Case Study # 4: Optimizing Production Mix for Outdoor Furniture Manufacturing at Patio Paradise, Inc. (Total marks: 25) Patio Paradise, Inc. is a manufacturer of outdoor furniture that offers three...
-
Richard and Christine McCarthy have a 19-year-old son (born 10/2/99; Social Security number 555-55-1212), Jack, who is a full-time student at the University of Key West. Years ago, the McCarthys...
-
Abosky ltd, is a new firm, and has the opportunity to invest in its first new project. The new project will require investment of GHS100,000, and is expected to provide net cash flow of GHS40,000 per...
-
What is the key provisions of the pension protection act of 2006 in America and UK ?
-
Dymac Appliances uses the periodic inventory system. Details regarding the inventory of appliances at January 1, purchases invoices during the next 12 months, and the inventory count at December 31...
-
What is cultural exploration and how does it affect hotels and restaurants ?
-
Explain the importance of performance management and why the organizations values performance management. Suggest a performance management system then Explain how to use it in an appropriate way....
-
Logan has a loan that he has to pay $80,000 at the end of the year for 10 years. If Logan wants to pay this loan in monthly terms instead of annual terms and money is worth 15% compounded annually......
-
A long string having a cross-sectional area 0.80 mm and density 125 g cm, is subjected to a tension of 64 N along the X-axis. One end of this string is attached to a vibrator Imoving in transverse...
-
An 8.0 kg crate is pulled 5.0 m up a 30 incline by a rope angled 18 above the incline. The tension in the rope is 120 N, and the crates coefficient of kinetic friction on the incline is 0.25. a. How...
-
In the first card-sorting algorithm in this section, exactly how many sorting passes are needed to sort d-digit decimal numbers in the worst case? How many piles of cards would an operator need to...
-
Prove that the fractional knapsack problem has the greedy-choice property.
-
Professor Sabatier conjectures the following converse of Theorem 23.1. Let G = (V, E) be a connected, undirected graph with a real-valued weight function w defined on E. Let A be a subset of E that...
-
The assumptions are as follows: Company A records an uncertain tax liability of \($50\) million as of the reporting date. Company A expects to settle the amount in the fourth quarter of the...
-
Find the P-value for the following values of the test statistic t, sample size n, and alternate hypothesis H1. If you use Table A.3, you may specify that P is between two values. a. t = 2.584, n =...
-
A company is computing intraperiod tax allocation for the current year and has accumulated the following income and loss items: The tax rate for the current year is 21%. Tax credits of $100,000 are...
Study smarter with the SolutionInn App