Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
Document preview thumbnail
Voorbeeld 2 van de 5 pagina's
Tentamen (uitwerkingen)

hw4-soln CS 161|ALL YOU NEED

Document preview thumbnail
Voorbeeld 2 van de 5 pagina's

CS161 Homework 4 Due: 15 May 2015 Submit on Scoryst Handed out: 8 May 2015 Instructions: Please answer the following questions to the best of your ability. If you are asked to show your work, please include relevant calculations for deriving your answer. If you are asked to explain your answer, give a short (∼ 1 sentence) intuitive description of your answer. If you are asked to prove a result, please write a complete proof at the level of detail and rigor expected in prior CS Theory classes (i.e. 103). When writing proofs, please strive for clarity and brevity (in that order). Cite any sources you reference. 1 (18 points) Carry Heaps In this problem, we will develop a data structure, which we call a “Carry Heap”, H that stores a set S of at most n elements that have integer key values and supports two operations: • H.FindMin: return the element in S of minimum key and • H.Insert(x, k): insert x into H with key k. H is implemented as follows. H contains an array A of length 1 + log n. For each index i, A[i] is either NIL or is a rooted tree on 2i nodes. Assume that A is augmented such that it can access, for any nonNIL A[i], the next non-NIL entry of A after A[i] in constant time 1 . The elements of S are stored in the nodes of the trees stored in A. Every tree T stored in A is min-heap ordered, i.e. for every node x of T, key(x) ≥ key(parent(x)). To insert an element x with key k into H, we create a new singleton carry heap Hx as follows. To create Hx, we will create an all-NIL array Ax in constant time, and then set Ax[0] to be a tree with a single node x with key k. Then, we call a subroutine, meld(H, Hx) called on two carry heaps. The meld operation merges two arbitrary H and H0 and stores the answer into H. It works as follows. Let carry be a variable initially set to NIL, and let A and A0 be the arrays of H and H0 , respectively. Starting with i = 0, while i ≤ log n, consider the variables carry, A[i], and A0 [i]. • If at least two of the three variables are non-NIL, i.e. at least two are trees of size 2i , call these two T, T 0 and call the remaining one Q (which may be a tree of size 2i or NIL). Then, set A[i] = Q. If key(T.root) key(T 0 .root) merge T and T 0 into a new tree T + with root T.root by adding an edge from T.root and T 0 .root. Otherwise, mer


Documentinformatie

Geüpload op
16 november 2022
Aantal pagina's
5
Geschreven in
2022/2023
Type
Tentamen (uitwerkingen)
Bevat
Vragen en antwoorden
$8.99

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kan je een ander document kiezen. Je kan het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Seller avatar
De reputatie van een verkoper is gebaseerd op het aantal documenten dat iemand tegen betaling verkocht heeft en de beoordelingen die voor die items ontvangen zijn. Er zijn drie niveau’s te onderscheiden: brons, zilver en goud. Hoe beter de reputatie, hoe meer de kwaliteit van zijn of haar werk te vertrouwen is.
Abbyy01
3.5
(13)
Verkocht
98
Volgers
33
Items
1337
Laatst verkocht
2 weken geleden



Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via Bancontact, iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo eenvoudig kan het zijn.”

Alisha Student

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen

Oeps! We kunnen je document nu niet laden. Probeer het nog eens of neem contact op met support.