100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

hw4-soln CS 161|ALL YOU NEED

Rating
-
Sold
-
Pages
5
Grade
A+
Uploaded on
16-11-2022
Written in
2022/2023

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

Show more Read less
Institution
De Anza College
Course
CS 161









Whoops! We can’t load your doc right now. Try again or contact support.

Document information

Uploaded on
November 16, 2022
Number of pages
5
Written in
2022/2023
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
Abbyy01 Exam Questions
View profile
Follow You need to be logged in order to follow users or courses
Sold
91
Member since
3 year
Number of followers
33
Documents
1121
Last sold
1 week ago

3.5

13 reviews

5
5
4
2
3
3
2
1
1
2

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions