CS 541 Algorithms and Programs. Exam 1 Solutions

Similar documents
15-451/651: Design & Analysis of Algorithms January 22, 2019 Lecture #3: Amortized Analysis last changed: January 18, 2019

Math 210 Exam 4 - Practice Problem Solutions. 1. Answer the following questions based on the rooted tree shown below:

TCOM501 Networking: Theory & Fundamentals Final Examination Professor Yannis A. Korilis April 26, 2002

ME 310 Numerical Methods. Differentiation

Spring 2018 Social Sciences 7418 University of Wisconsin-Madison. Transactions and Portfolio Crowding Out

Hardware-Software Cosynthesis of Multi-Mode Multi-Task Embedded Systems with Real-Time Constraints

Production and Supply Chain Management Logistics. Paolo Detti Department of Information Engeneering and Mathematical Sciences University of Siena

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Splay Trees Date: 9/27/16

Fall 2016 Social Sciences 7418 University of Wisconsin-Madison. Transactions and Portfolio Crowding Out

CS 286r: Matching and Market Design Lecture 2 Combinatorial Markets, Walrasian Equilibrium, Tâtonnement

Supplementary Material for Borrowing Information across Populations in Estimating Positive and Negative Predictive Values

Practice Exam 1. Use the limit laws from class compute the following limit. Show all your work and cite all rules used explicitly. xf(x) + 5x.

Parallel Prefix addition

ACC 471 Practice Problem Set # 4 Fall Suggested Solutions

Elements of Economic Analysis II Lecture VI: Industry Supply

Project Management Project Phases the S curve

EXAMINATIONS OF THE HONG KONG STATISTICAL SOCIETY

Calculus I Homework: Four Ways to Represent a Function Page 1. where h 0 and f(x) = x x 2.

Lecture 7. We now use Brouwer s fixed point theorem to prove Nash s theorem.

Applications of Myerson s Lemma

Numerical Analysis ECIV 3306 Chapter 6

Tests for Two Ordered Categorical Variables

A New and Efficient Congestion Evaluation Model in Floorplanning: Wire Density Control with Twin Binary Trees

Economic Design of Short-Run CSP-1 Plan Under Linear Inspection Cost

The study guide does not look exactly like the exam but it will help you to focus your study efforts.

Parsing beyond context-free grammar: Tree Adjoining Grammar Parsing I

SUPPLEMENT TO BOOTSTRAPPING REALIZED VOLATILITY (Econometrica, Vol. 77, No. 1, January, 2009, )

Price and Quantity Competition Revisited. Abstract

Understanding Annuities. Some Algebraic Terminology.

Elton, Gruber, Brown, and Goetzmann. Modern Portfolio Theory and Investment Analysis, 7th Edition. Solutions to Text Problems: Chapter 9

COS 511: Theoretical Machine Learning. Lecturer: Rob Schapire Lecture #21 Scribe: Lawrence Diao April 23, 2013

1 Introducton Opton prcng teory as been te core of modern matematcal nance snce te dervaton of te famous Blac-Scoles (19) formula wc provdes a partal

Sample Survey Design

ECO 209Y MACROECONOMIC THEORY AND POLICY LECTURE 8: THE OPEN ECONOMY WITH FIXED EXCHANGE RATES

Problem Solving Day: Geometry, movement, and Free-fall. Test schedule SOH CAH TOA! For right triangles. Last year s equation sheet included with exam.

On the uniqueness of stable marriage matchings

Elton, Gruber, Brown and Goetzmann. Modern Portfolio Theory and Investment Analysis, 7th Edition. Solutions to Text Problems: Chapter 4

Introduction to PGMs: Discrete Variables. Sargur Srihari

Finance 402: Problem Set 1 Solutions

Heaps

Homework 9: due Monday, 27 October, 2008

Macroeconomic Theory and Policy

UNIVERSITY OF BOLTON WESTERN INTERNATIONAL COLLEGE, RAS AL KHAIMAH BENG(HONS) MECHANICAL ENGINEERING SEMESTER TWO EXAMINATION 2014/2015

iii) pay F P 0,T = S 0 e δt when stock has dividend yield δ.

Supplementary material for Non-conjugate Variational Message Passing for Multinomial and Binary Regression

Dept of Mathematics and Statistics King Fahd University of Petroleum & Minerals

Macroeconomic Theory and Policy

An Example (based on the Phillips article)

II. Random Variables. Variable Types. Variables Map Outcomes to Numbers

Solution of periodic review inventory model with general constrains

Cascade Algorithm Revisited

OPERATIONS RESEARCH. Game Theory

Time Value of Money, Part 2 Future Value aueof a $1 (Single Sum) Learning Outcomes. Future Value

Equilibrium in Prediction Markets with Buyers and Sellers

Number of Municipalities. Funding (Millions) $ April 2003 to July 2003

Outline for this Week

Dept of Mathematics and Statistics King Fahd University of Petroleum & Minerals

In this appendix, we present some theoretical aspects of game theory that would be followed by players in a restructured energy market.

Chapter 3 Student Lecture Notes 3-1

2.1 Rademacher Calculus... 3

Appendix - Normally Distributed Admissible Choices are Optimal

The Integration of the Israel Labour Force Survey with the National Insurance File

Games and Decisions. Part I: Basic Theorems. Contents. 1 Introduction. Jane Yuxin Wang. 1 Introduction 1. 2 Two-player Games 2

Minimizing the number of critical stages for the on-line steiner tree problem

A Correction to: The Structure of General Equilibrium Shadow Pricing Rules for a Tax-Distorted Economy

Binary Search Tree and AVL Trees. Binary Search Tree. Binary Search Tree. Binary Search Tree. Techniques: How does the BST works?

Data Structures. Binomial Heaps Fibonacci Heaps. Haim Kaplan & Uri Zwick December 2013

AMERICAN DEPOSITARY RECEIPTS. ISFP Stephen Sapp

A Data adaptive and Dynamic Segmentation Index for Whole Matching on Time Series

Priority Queues 9/10. Binary heaps Leftist heaps Binomial heaps Fibonacci heaps

Heaps. Heap/Priority queue. Binomial heaps: Advanced Algorithmics (4AP) Heaps Binary heap. Binomial heap. Jaak Vilo 2009 Spring

Fall 2017 Social Sciences 7418 University of Wisconsin-Madison Problem Set 3 Answers

2. Equlibrium and Efficiency

YORK UNIVERSITY Faculty of Science Department of Mathematics and Statistics MATH A Test #2 November 03, 2014

2.17 Tax Expenditures. Introduction. Scope and Objectives

Data Mining Linear and Logistic Regression

ISE High Income Index Methodology

Discrete Dynamic Shortest Path Problems in Transportation Applications

/ Computational Genomics. Normalization

11.1 Average Rate of Change

Single-Item Auctions. CS 234r: Markets for Networks and Crowds Lecture 4 Auctions, Mechanisms, and Welfare Maximization

Mathematical Modeling of Financial Derivative Pricing

Survey of Math: Chapter 22: Consumer Finance Borrowing Page 1

PREFERENCE DOMAINS AND THE MONOTONICITY OF CONDORCET EXTENSIONS

A Comparison of Statistical Methods in Interrupted Time Series Analysis to Estimate an Intervention Effect

Hewlett Packard 10BII Calculator

The Impact of Delaying Retirement on Chinese Employment and Economic Growth under the Background of Aging

Deterministic rendezvous, treasure hunts and strongly universal exploration sequences

Finite Math - Fall Section Future Value of an Annuity; Sinking Funds

The Hiring Problem. Informationsteknologi. Institutionen för informationsteknologi

A Polynomial-Time Algorithm for Action-Graph Games

Task Force on quality of business survey data

Bargaining in Standing Committees with an Endogenous Default

2) In the medium-run/long-run, a decrease in the budget deficit will produce:

332 Mathematical Induction Solutions for Chapter 14. for every positive integer n. Proof. We will prove this with mathematical induction.

Taxation and Externalities. - Much recent discussion of policy towards externalities, e.g., global warming debate/kyoto

Managing and Identifying Risk

Advanced Algorithmics (4AP) Heaps

Facility Location Problem. Learning objectives. Antti Salonen Farzaneh Ahmadzadeh

Final Examination MATH NOTE TO PRINTER

Transcription:

CS 5 Algortms and Programs Exam Solutons Jonatan Turner 9/5/0 Be neat and concse, ut complete.. (5 ponts) An ncomplete nstance of te wgrap data structure s sown elow. Fll n te mssng felds for te adjacency lsts. Insert te edges nto te adjacency lsts so tat te edge numers appear n ncreasng order n eac lst. frstedge a c d e f 5 6 8 9 0 edges l lnext wt rnext r a 6 e d 8 6 5 a c 5 a 8 6 c c 0 9 e 9 8 0 f d 0 0 a e 0 6 0 f 0 0 c - -

. (5 ponts) Let A e a lst n numers. Descre an algortm tat creates a lst of te k smallest values n A and wc runs n O(n) tme so long as k < n/lg n. Explan wy your algortm runs n O(n) tme. Use makeeap to uld a -eap on te set of tems. Ts takes O(n) tme. Ten perform k deletemn operatons. Snce te tme per deletemn s O(log n), te runnng tme for k<n/ lg n deletemn operatons s O(n). - -

. (0 ponts) Te fgure elow sows an ncomplete representaton of an ntermedate state n te executon of Prm s algortm. In partcular, te values of te ceap mappng are not sown. Fll n te correct values for te ceap mappng (you may omt entres for vertces tat are n te tree). Ten sow ow te next step n te executon of te algortm modfes all te data structures. a 5 g 9 c e 8 f d 6 f d a c d e f g ceap a c de ef c 9 a 5 a 5 g 9 c e 8 f d 6 c d ceap a c d e a cf de f g a 5 - -

. (0 ponts) In te worst-case analyss of Prm s algortm, we saw tat te numer of calls to te cangekey procedure was O(m). In ts prolem, you are to sow tat t s also Ω(n ). Frst, sow tat you can assgn edge wegts to te complete grap on 5 vertces so tat Prm s algortm executes te cangekey operaton for every edge n te grap. Generalze ts example to sow tat for eac value of n, tere s a wegted grap wt Ω(n ) edges and tat cangekey s nvoked wen all of tese edges are examned. Te fgure elow sows an assgnment of edge wegts to a complete grap on 5 vertces tat causes Prm s algortm to execute cangekey once for every edge, assumng tat t starts from vertex u. Te generalzaton of ts grap as n vertces u,...,u n and te wegt of te edge from u to u j s equal to j for all and j. If Prm s algortm starts wt vertex u, ten for all, vertex u wll e removed from te eap n step and cangekey wll e nvoked for all edges (u,u j ) wt j>. Tat s, t wll e nvoked for every edge. Snce tere are Ω(n ) edges, cangekey s nvoked Ω(n ) tmes. u u u u u 5 - -

5. (0 ponts) A mn-max eap s an extenson of te eap data structure tat effcently supports access to an tem of maxmum key, as well as access to an tem of mnmum key. One way to mplement a mn-max eap s y extendng te data structure for d-eaps. One dvdes te eap nto levels, wt te root eng n level 0, ts cldren n level and so fort. For every node x on an even-numered level, key(x) key(y) for all descendants y of x. For every node x on an odd-numered level, key(x) key(y) for all descendants y of x. Te correctness of any data structure operaton depends on ts mantanng certan essental propertes of te data structure. Te data porton of te class declaraton for a C++ mplementaton of a mn-max eap data structure s sown elow. To make tngs smpler, you may assume a nary eap (eac node as at most two cldren). Wat propertes of te data must e mantaned y programs tat operate on t? Lst as many as you can tnk of. Hnt: a poston s on an even level f lg s even. Oterwse, s on an odd level. class mnmaxheap { nt N; // max numer of tems n eap nt n; // numer of tems n eap tem *; // {[],...,[n]} s set of tems nt *pos; // pos[] gves poston of n keytyp *kvec; // kvec[] s key of tem... }; n N for n, wt lg odd, kvec[[ / ]] kvec[[]] for n, wt lg even, kvec[[ / ]] kvec[[]] for n, wt lg even, kvec[[ / ]] kvec[[]] for n, wt lg odd, kvec[[ / ]] kvec[[]] for n, [] n, pos[] n and pos[[]] = for <j n, [] [j] and pos[] pos[j] - 5 -

6. (0 ponts) Te fgure elow sows a lazy leftst eap n wc some nodes (te saded ones) ave een marked deleted. Sow te eap after te executon of te operaton, purge(a). a 0, e, g,, f 9,, c 6, 0, j 6, d 5, After te purge we ave. e,,, j 6, d 5, 0, c 6, f 9, - 6 -

. (5 ponts) In te analyss of te round-ron algortm, te executon s dvded nto a seres of passes. Te frst pass ends wen all trees on te queue ntally ave een selected and comned wt oter trees. For a grap wt n vertces and m edges, wat s te largest possle numer of nodes n any of te leftst eaps at te concluson of te frst pass? Explan ow for any n and any m n, one can construct a grap on n vertces and m edges for wc te round-ron algortm as a eap of ts sze at te end of te frst pass. Gve a tgt ound on te tme requred y te round-ron algortm on ts grap, excludng te tme requred for ntalzaton. It s possle to end te frst pase wt a sngle eap tat as m+n nodes. Construct a star on n vertces wt edges of wegt. A star s a tree n wc tere s one central vertex wt an edge to every oter vertex. Now, add m (n ) edges of wegt larger tan etween any artrary pars of vertces. Note tat te orgnal star s a unque mnmum spannng tree for ts grap. If we execute te round ron algortm on ts grap, t wll comne all vertces nto a sngle component n te frst pass, resultng n a sngle eap tat contans all te edges, plus n dummy nodes from lazy melds. Te runnng tme for te round ron algortm on ts grap (excludng te ntalzaton) s O(nα(n,n)), snce none of te fndmns removes any nodes. Consequently, eac teraton takes constant tme, except for te fnd operatons and tese take at most α(n,n) tme eac. - -

8. (0 ponts) Consder an alternatve analyss of te partton data structure n wc te accountng varale det(u) s ncremented f te pat etween u and te root as lengt at least and g ( u) = g( p( u)), were te functon g(x) s defned y g ( x) = lg lg( + rank( x)). In all oter cases, fcredt s ncremented. Sow tat fcredt s ncremented O(log log log n) tmes durng eac top level fnd. Te values of g(x) cannot decrease as you go up te tree, so for every value of, tere s at most one node were g(x)= and g(p(x))>. So te numer of nodes were fcredt gets ncremented s at most plus te numer of dstnct values of g(x). Snce g(x) 0 and rank(x) s at most lg(n), ts s O(log log log n). Sow tat f g(x)= at te end of a sequence of operatons, ten + det ( x). Every tme det(x) s ncremented, te rank(p(x)) ncreases y at least. We only ncrement det(x) wle g(p(x))= and g(p(x))= only so long as rank ( p( x)) <. So, once det(x) s ncremented + tmes, g(p(x))> and det(x) s never ncremented agan. + Sow tat te numer of nodes for wc te fnal value of g(x)= s at most n. If g(x)=, ten rank ( x). Snce te numer of nodes wt rank equal k s at most numer of nodes wt g(x)= s at most n n = + + L = k k n k n / te Sow tat for eac value of, te sum of te det varales for all nodes wose fnal values of g(x)= s O(n). n Te sum s at most <n, so n all cases, t s O(n). + + + = n. For =0 and =, ts s n. For all larger values of t s - 8 -