• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 2 fuera de 5 páginas
Examen

Hw4-Soln Cs 161|All You Need

Document preview thumbnail
Vista previa 2 fuera de 5 páginas

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


Información del documento

Subido en
16 de noviembre de 2022
Número de páginas
5
Escrito en
2022/2023
Tipo
Examen
Contiene
Preguntas y respuestas
$8.99

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
Abbyy01
3.5
(13)
Vendido
98
Seguidores
33
Artículos
1332
Última venta
2 meses hace



Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes

Ups! No podemos cargar tu documento ahora. Inténtalo de nuevo o contacta con soporte.