6 Pages

ps1sol

Course: COMS 12100, Fall 2009
School: East Los Angeles College
Rating:
 
 
 
 
 

Word Count: 1773

Document Preview

to Introduction Algorithms Massachusetts Institute of Technology Professors Erik D. Demaine and Charles E. Leiserson September 30, 2005 6.046J/18.410J Handout 8 Problem Set 1 Solutions Problem 1-1. Asymptotic Notation For each of the following statements, decide whether it is always true, never true, or sometimes true for asymptotically nonnegative functions f and g. If it is always true or never true, explain...

Register Now

Unformatted Document Excerpt

Coursehero >> California >> East Los Angeles College >> COMS 12100

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
to Introduction Algorithms Massachusetts Institute of Technology Professors Erik D. Demaine and Charles E. Leiserson September 30, 2005 6.046J/18.410J Handout 8 Problem Set 1 Solutions Problem 1-1. Asymptotic Notation For each of the following statements, decide whether it is always true, never true, or sometimes true for asymptotically nonnegative functions f and g. If it is always true or never true, explain why. If it is sometimes true, give one example for which it is true, and one for which it is false. (a) f (n) = O(f (n)2 ) Solution: Sometimes true: For f (n) = n it is true, while for f (n) = 1/n it is not true. (The statement is always true for f (n) = (1), and hence for most functions with which we will be working in this course, and in particular all time and space complexity functions). (b) f (n) + g(n) = (max (f (n), g(n))) Solution: Always true: max(f (n), g(n)) f (n) + g(n) 2 max(f (n), g(n)). (c) f (n) + O(f (n)) = (f (n)) Solution: Always true: Consider f (n) + g(n) where g(n) = O(f (n)) and let c be a constant such that 0 g(n) < cf (n) for large enough n. Then f (n) f (n) + g(n) (1 + c)f (n) for large enough n. (d) f (n) = (g(n)) and f (n) = o(g(n)) (note the little-o) Solution: Never true: If f (n) = (g(n)) then there exists positive constant c and n such that for all n > n , cg(n) f (n). But if f (n) = o(g(n)), then for any positive constant c, there exists no (c) such that for all n > no (c), f (n) < cg(n). If f (n) = (g(n)) and f (n) = o(g(n)), we would have that for n > max(n , no (c )) it should be that f (n) < c g(n) f (n) which cannot be. (e) f (n) = O(g(n)) and g(n) = O(f (n)) Solution: Sometimes true: For f (n) = 1 and g(n) = n sin(n) it is true, while for any f (n) = O(g(n)), e.g. f (n) = g(n) = 1, it is not true. 2 Problem 1-2. Recurrences Handout 8: Problem Set 1 Solutions Give asymptotic upper and lower bounds for T (n) in each of the following recurrences. Assume that T (n) is constant for n 3. Make your bounds as tight as possible, and justify your answers. (a) T (n) = 2T (n/3) + n lg n Solution: By Case 3 of the Master Method, we have T (n) = (n lg n). (b) T (n) = 3T (n/5) + lg2 n Solution: By Case 1 of the Master Method, we have T (n) = (nlog5 (3) ). (c) T (n) = T (n/2) + 2n Solution: Case 3 of masters theorem, (check that the regularity condition holds), (2n ). (d) T (n) = T ( n) + (lg lg n) Solution: Change of variables: let m = lg n. Recurrence becomes S(m) = S(m/2) + (lg m). Case 2 of masters theorem applies, so T (n) = ((lg lg n)2 ). (e) T (n) = 10T (n/3) + 17n1.2 Solution: Since log3 9 = 2, so log3 10 > 2 > 1.2. Case 1 of masters theorem applies, (nlog3 10 ). (f) T (n) = 7T (n/2) + n3 Solution: By Case 3 of the Master Method, we have T (n) = (n3 ). (g) T (n) = T (n/2 + n) + 6046 Solution: By induction, T (n) a monotonically increasing function. Thus, for large is enough n, T (n/2) T (n/2 + n) T (3n/4). At each stage, we incur constant cost 6046, but we decrease the problem size to atleast one half and at most three-quarters. Therefore T (n) = (lg n). Handout 8: Problem Set 1 Solutions (h) T (n) = T (n 2) + lg n Solution: T (n) = (n log n). This is T (n) = i=1 lg 2i i=1 lg i (n/4)(lg n/4) = (n lg n). For the upper bound, note that T (n) S(n), where S(n) = S(n1)+lg n, which is clearly O(n lg n). (i) T (n) = T (n/5) + T (4n/5) + (n) Solution: Masters theorem doesnt apply here. Draw recursion tree. At each level, do (n) work. Number of levels is log5/4 n = (lg n), so guess T (n) = (n lg n) and use the substitution method to verify guess. In the f (n) = (n) term, let the constants for (n) and O(n) be n0 , c0 and c1 , respectively. In other words, let for all n n0 , we have c0 n f (n) c1 n. First, we show T (n) = O(n). For the base case, we can choose a sufciently large constant d1 such that T (n) < d1 n lg n. For the inductive step, assume for all k < n, that T (k) < d1 n lg n. Then for k = n, we have T (n) T 4n n +T + c1 n 5 5 n 4n n 4n d1 lg + d1 lg + c1 n 5 5 5 5 4d1n 5 d1 n + c1 n lg 5 lg = d1 n lg n 5 5 4 lg 5 + 4 lg(5/4) = d1 n lg n n d 1 c1 . 5 n/2 n/2 3 The residual is negative as long as we pick d1 > 5c1 /(lg 5+4 lg(5/4)). Therefore, by induction, T (n) = O(n lg n). To show that T (n) = (n), we can use almost the exact same math. For the base case, we choose a sufciently small constant d0 such that T (n) > d0 n lg n. For the inductive step, assume for all k < n, that T (k) > d0 n lg n. Then, for k = n, we have T (n) T n 4n +T + c0 n 5 5 4n n 4n n + d0 lg + c0 n d0 lg 5 5 5 5 lg 5 + 4 lg(5/4) d0 . d0 = n lg n + n c0 5 4 Handout 8: Problem Set 1 Solutions The residual is positive as long as d0 < 5c0 /(lg 5 + 4 lg(5/4)). Thus, T (n) = (n lg n). (j) T (n) = n T ( n) + 100n Solution: Masters theorem doesnt apply here directly. Pick S(n) = T (n)/n. The recurrence becomes S(n) = S( n) + 100. The solution of this recurrece is S(n) = (lg lg n). (You can do this by a recursion tree, or by substituting m = lg n again.) Therefore, T (n) = (n lg lg n). Problem 1-3. Unimodal Search An array A[1 . . n] is unimodal if it consists of an increasing sequence followed by a decreasing sequence, or more precisely, if there is an index m {1, 2, . . . , n} such that A[i] < A[i + 1] for all 1 i < m, and A[i] > A[i + 1] for all m i < n. In particular, A[m] is the maximum element, and it is the unique locally maximum element surrounded by smaller elements (A[m 1] and A[m + 1]). (a) Give an algorithm to compute the maximum element of a unimodal input array A[1 . . n] in O(lg n) time. Prove the correctness of your algorithm, and prove the bound on its running time. Solution: Notice that by the denition of unimodal arrays, for each 1 i < n either A[i] < A[i + 1] or A[i] > A[i + 1]. The main idea is to distinguish these two cases: 1. By the denition of unimodal arrays, if A[i] < A[i + 1], then the maximum element of A[1..n] occurs in A[i + 1..n]. 2. In a similar way, if A[i] > A[i + 1], then the maximum element of A[1..n] occurs in A[1..i]. This leads to the following divide and conquer solution (note its resemblance to binary search): 1 a, b 1, n 2 while a < b 3 do mid (a + b)/2 4 if A[mid] < A[mid + 1] 5 then a mid + 1 6 if A[mid] > A[mid + 1] 7 then b mid 8 return A[a] Handout 8: Problem Set 1 Solutions The precondition is that we are given a unimodal array A[1..n]. The postcondition is that A[a] is the maximum element of A[1..n]. For the loop we propose the invariant The maximum element of A[1..n] is in A[a..b] and a b. When the loop completes, a b (since the loop condition failed) and a b (by the loop invariant). Therefore a = b, and by the rst part of the loop invariant the maximum element of A[1..n] is equal to A[a]. We use induction to prove the correctness of the invariant. Initially, a = 1 and b = n, so, the invariant trivially holds. Suppose that the invariant holds at the start of the loop. Then, we know that the maximum element of A[1..n] is in A[a..b]. Notice that A[a..b] is unimodal as well. If A[mid] < A[mid + 1], then the maximum element of A[a..b] occurs in A[mid + 1..b] by case 1. Hence, after a mid + 1 and b remains unchanged in line 4, the maximum element is again in A[a..b]. The other case is symmetric. To complete the proof, we need to show that the secon...

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

Canisius College - CSC - 253
; %let X = ^ Y NOT Y STD X; %let X = &lt; Z LOD Z SHL STD X; %let X = &gt; Z LOD Z SHR STD X; %let X = &gt; _A SHR STD X; %let _A = &lt; _A SHL; %
Toledo - CSB - 452
High-affinity salicylic acid-binding protein 2 is required for plant innate immunity and has salicylic acid-stimulated lipase activityDhirendra Kumar and Daniel F. Klessig*Boyce Thompson Institute for Plant Research, Tower Road, Ithaca, NY 14853 Co
Canisius College - CSC - 253
0: ; This tests out every instruction 0: ; 0: LOD 1000 1: ADD 1001 2: ADD 1002 3: STD 1003 4: A2S 5: LDI 1001 6: S2A 7: ; 7: ; Now test out loading indirectly thro
Canisius College - CSC - 253
LOD XSTD Y
Canisius College - CSC - 253
LDI 17 SHL STD X NOP HLTX: NUM 44
Toledo - CSB - 452
Methyl Salicylate Is a Critical Mobile Signal for Plant Systemic Acquired Resistance Sang-Wook Park, et al. Science 318, 113 (2007); DOI: 10.1126/science.1147113 The following resources related to this article are available online at www.sciencemag.o
Toledo - CSB - 452
The Plant Cell, Vol. 18, 20822093, August 2006, www.plantcell.org 2006 American Society of Plant BiologistsDistinct Domains in the ARC Region of the Potato Resistance Protein Rx Mediate LRR Binding and Inhibition of ActivationWGregory J. Rairda
CSU LA - INSTRUCTIO - 301
Chapter 1 THE INFORMATION AGE IN WHICH YOU LIVE Changing the Face of BusinessMcGrawHill 2008 The McGrawHill Companies, Inc. All rights reserved.STUDENT LEARNING OUTCOMES1. 2. 3.4.Describe MIS and the 3 important organizational resources wi
Toledo - CSB - 452
Vol 448 | 19 July 2007 | doi:10.1038/nature05966LETTERSA bacterial E3 ubiquitin ligase targets a host protein kinase to disrupt plant immunityTracy R. Rosebrock1,2, Lirong Zeng1, Jennifer J. Brady1, Robert B. Abramovitch1,2, Fangming Xiao1 &amp; Greg
CSU LA - INSTRUCTIO - 301
Extended Learning Module A COMPUTER HARDWARE AND SOFTWAREMcGrawHill 2008 The McGrawHill Companies, Inc. All rights reserved.STUDENT LEARNING OUTCOMES1. 2. 3.Define IT and its two basic categories: hardware and software. Describe the categori
CSU LA - INSTRUCTIO - 301
ObjectiveThe Mission of CIS 301 (Management Information Systems): School of Business and Economics is set up to educate and train business professionals namely business analyst and managers of all levels. As a business analyst or as a manger, at any
CSU LA - INSTRUCTIO - 301
Chapter 2 MAJOR BUSINESS INITIATIVES Gaining Competitive Advantage with ITMcGrawHill 2008 The McGrawHill Companies, Inc. All rights reserved.STUDENT LEARNING OUTCOMES1.2.3.Define supply chain management (SCM) systems and describe their s
W. Alabama - CS - 349
CS349: l15.fm June 8, 2005Properties of ComponentsComponents encapsulate dialogues, which are threads of conversation Threads have two participants turn taking protocols Multi-threaded conversations modality1/4CS349: l15.fm June 8, 2005The
Toledo - CSB - 452
The Plant Journal (2007) 52, 8293doi: 10.1111/j.1365-313X.2007.03213.xA RanGAP protein physically interacts with the NB-LRR protein Rx, and is required for Rx-mediated viral resistanceMelanie A. Sacco1, Shahid Mansoor2 and Peter Moffett1,* 1 Boy
CSU LA - INSTRUCTIO - 301
Extended Learning Module B THE WORLD WIDE WEB AND THE INTERNETMcGrawHill 2008 The McGrawHill Companies, Inc. All rights reserved.STUDENT LEARNING OUTCOMES1.2. 3.Define the relationships among Web site, Web site address, domain name, Web pa
CSU LA - INSTRUCTIO - 301
Relationship of MIS and your Professional Business EducationMohammad B. Ayati, Ph.D.06/05/09 1http:/www.latimes.com/news/nationworld/world/la-040209-fg-obama_g20-g,0,2581281.graphicApril 4,200906/05/092http:/www.latimes.com/news/nationwo
CSU LA - INSTRUCTIO - 301
Chapter 3 DATABASES AND DATA WAREHOUSES Building Business IntelligenceMcGrawHill 2008 The McGrawHill Companies, Inc. All rights reserved.STUDENT LEARNING OUTCOMES1. 2. 3. 4. 5. 6.List and describe the key characteristics of a relational data
CSU LA - INSTRUCTIO - 301
Extended Learning Module C DESIGNING DATABASES AND ENTITYRELATIONSHIP DIAGRAMMINGMcGrawHill2008TheMcGrawHillCompanies,Inc.Allrightsreserved.STUDENT LEARNING OUTCOMES1. 2. 3.Identify how databases and spreadsheets are both similar and differe
CSU LA - INSTRUCTIO - 301
http:/www.asrs.net/aft_asrs_srf_motion_1.phpINPUT CONVEYOR TO SRF.JPGhttp:/www.westfaliausa.com/products/ASRS/asrs-overview.html?gclid=CI3e_q7C94wCFQIPYwodexiMhwAutomated Storage &amp; Retrieval SystemsPractice: C o m p a re a nd c o ntra s t
CSU LA - INSTRUCTIO - 301
Have you ever paid attentions to the shelves? Shelves themselves, not the content ?Why should I ?H ow l ea r ni ng hi gher l evel model s (a bstr a cts) a r e useful :Learning a New Discipline:Concepts vs. InformationA Warehouse Analogy Wa
CSU LA - INSTRUCTIO - 301
DECISION SUPPORT AND ARTIFICIAL INTELLIGENCEChapter 4Brainpower for Your BusinessMcGrawHill 2008 The McGrawHill Companies, Inc. All rights reserved.STUDENT LEARNING OUTCOMES1. 2. 3.Compare and contrast decision support systems and geogra
CSU LA - INSTRUCTIO - 301
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;Error&gt;&lt;Code&gt;NoSuchKey&lt;/Code&gt;&lt;Message&gt;The specified key does not exist.&lt;/Message&gt;&lt;Key&gt;dd5433b73e5c49b1fedcbb1b77791bb7e66f175b.ppt&lt;/Key&gt;&lt;RequestId&gt;7 62C7546D5EE34DF&lt;/RequestId&gt;&lt;HostId&gt;nAG3rOGoXWAMK6kbgSun1f0gtnb
CSU LA - INSTRUCTIO - 301
Chapter 5 ELECTRONIC COMMERCE Strategies for the New EconomyMcGrawHill 2008 The McGrawHill Companies, Inc. All rights reserved.STUDENT LEARNING OUTCOMES1. 2.3.Define and describe the 9 major e-commerce business models. Identify the differe
CSU LA - INSTRUCTIO - 301
Extended Learning Module J IMPLEMENTING A DATABASE IN MICROSOFT ACCESSMcGrawHill 2008 The McGrawHill Companies, Inc. All rights reserved.STUDENT LEARNING OUTCOMES1.2.3.Identify the steps necessary to implement the structure of a relation
CSU LA - INSTRUCTIO - 301
Extended Learning Module E NETWORK BASICSMcGrawHill 2008 The McGrawHill Companies, Inc. All rights reserved.STUDENT LEARNING OUTCOMES1.2.Identify and describe the four basic concepts on which networks are built and describe what is needed
CSU LA - INSTRUCTIO - 301
Appendix A: A Quick Excursion into Systems ApproachDefine &quot;system&quot;. The following are alternative and equivalent definitions: Partsinteracting .achieving a goal, producing a phenomenon-a result, an working together ..&quot;.producing a phenomenon-a re
CSU LA - INSTRUCTIO - 301
Chapter 6 SYSTEMS DEVELOPMENT Phases, Tools, and TechniquesMcGrawHill 2008 The McGrawHill Companies, Inc. All rights reserved.STUDENT LEARNING OUTCOMES1.2. 3.Define the traditional systems development life cycle (SDLC) and describe the 7 m
CSU LA - INSTRUCTIO - 301
Ayati, CSULAAny alternative computer systems or methods of acquiring information system should be evaluated based on the following criteria:Alternative 1 Alternative 2 Alternative 3Benefit side: (What the users,general managers and IS managers
CSU LA - INSTRUCTIO - 301
Shipping a laboratory From Los Angeles8 pin RJ-45 jack for 10Base-TJumpers to enable/disable media interfacesBNC connector for 10Base-2 (thin coax Ethernet) DB-15 AUI AUI or transceiver cableDB-15 AUI connector for 10Base-5 (thick coax Ethern
CSU LA - INSTRUCTIO - 301
The system model for any Information System environmentProcessxxxxxxx xxxxxxx xxxxxxx xxxxxxx xxxxxxx xxxxxxx xxxxxxx xxxxxxx xxxxxxx xxxxxxx xxxxxxx xxxxxxxPartsOther InputProcess (Assembly)Storagexxxxxxx xxxxxxx xxxxxxx xxxxxxx xxxxxxx xx
CSU LA - INSTRUCTIO - 301
Chapter 7 ENTERPRISE INFRASTRUCTURE, METRICS, AND BUSINESS CONTINUITY PLANNING Building and Sustaining the Dynamic EnterpriseMcGrawHill 2008 The McGrawHill Companies, Inc. All rights reserved.STUDENT LEARNING OUTCOMES1.2. 3. 4.Describe how
CSU LA - INSTRUCTIO - 301
Extended Learning Module F BUILDING A WEB PAGE WITH HTMLMcGrawHill 2008 The McGrawHill Companies, Inc. All rights reserved.STUDENT LEARNING OUTCOMES1. 2. 3.Define an HTML document and describe its relationship to a Web site. Describe the pur
CSU LA - INSTRUCTIO - 301
Extended Learning Module G OBJECT-ORIENTED TECHNOLOGIESMcGrawHill 2008 The McGrawHill Companies, Inc. All rights reserved.STUDENT LEARNING OUTCOMES1.2. 3.Explain the primary difference between the traditional technology approach and the ob
CSU LA - INSTRUCTIO - 301
Chapter 8 PROTECTING PEOPLE AND INFORMATION Threats and SafeguardsMcGrawHill 2008 The McGrawHill Companies, Inc. All rights reserved.STUDENT LEARNING OUTCOMES1.2. 3. 4.Define ethics and describe the two factors that affect how you make a d
CSU LA - INSTRUCTIO - 301
Extended Learning Module H COMPUTER CRIME AND DIGITAL FORENSICSMcGrawHill 2008 The McGrawHill Companies, Inc. All rights reserved.STUDENT LEARNING OUTCOMES1.2. 3.Define computer crime and list three types of computer crime that can be perp
CSU LA - INSTRUCTIO - 301
Extended Learning Module I BUILDING AN E-PORTFOLIOMcGrawHill2008TheMcGrawHillCompanies,Inc.Allrightsreserved.STUDENT LEARNING OUTCOMES1. 2. 3. 4.Describe the types of electronic resumes and when each is appropriate. Discuss networking strate
CSU LA - INSTRUCTIO - 301
The principles of Database(Copyright: M. B. Ayati, Professor of Information Systems, CSULA) This is a lesson on Database management. The business description here is a mock scenario to simplify and illustrate database issues. The Scenario: There are
CSU LA - INSTRUCTIO - 301
Chapter 9 EMERGING TRENDS AND TECHNOLOGIES Business, People, and Technology TomorrowMcGrawHill2008TheMcGrawHillCompanies,Inc.Allrightsreserved.STUDENT LEARNING OUTCOMES1. 2. 3.4.Describe emerging trends and technologies that will impact th
CSU LA - INSTRUCTIO - 301
Extended Learning Module J IMPLEMENTING A DATABASE IN MICROSOFT ACCESSMcGrawHill 2008 The McGrawHill Companies, Inc. All rights reserved.STUDENT LEARNING OUTCOMES1.2.3.Identify the steps necessary to implement the structure of a relation
CSU LA - INSTRUCTIO - 301
Player(s) 1:Player(s) 2:Player(s) 3:Player(s) 4:Traditional Systems Development: group, Business &amp; developing an Information System (e.g. IS Consultants an integrated Accounts Payable) in comparison with developing a building (e.g. a hospital
Canisius College - CSC - 253
0: ; This algorithm is Euclid's algorithm for computing the GCD 0: ; of two ints. r1=A, r2=B 0: ; 0: 0: ; %while a != b 0: WHILE1: NOP 1: LOD A 2: SUB B 3: JZ ENDWHILE1 4: ; %if a &gt; b
Canisius College - CSC - 253
; This algorithm is Euclid's algorithm for computing the GCD; of two ints. r1=A, r2=B;; %while a != bWHILE1: NOP LOD A SUB B JZ ENDWHILE1; %if a &gt; bIF1: NOP LOD A SUB B JN ELSE1 J
Canisius College - CSC - 253
Run MakeHelp here and then copy HelpWindow.java up one level. javac MakeHelp.java java MakeHelp helpinput &gt; HelpWindow.java cp HelpWindow.java .
CSU LA - INSTRUCTIO - 490
MANAGING INFORMATION TECHNOLOGYFIFTH EDITION CHAPTER 3COMPUTER SOFTWAREE. Wainright Martin Carol V. Brown Daniel W. DeHayes Jeffrey A. Hoffer William C. PerkinsEVOLUTION OF COMPUTER PROGRAMMINGFirst and Second Generation Languages1. Machi
CSU LA - INSTRUCTIO - 490
Chapter Goals Describe the functions and layers of an operating system List the resources allocated by the operating system and describe the complexities of the application process Explain how an operating system manages processes and threadsSys
Toledo - CSB - 452
CSB 452H1F PLANT-MICROORGANISM INTERACTIONSLecture: Monday 5-7 pm Total 13 lectures including students' presentationPLANT-MICROORGANISM INTERACTIONSIntroduction of &quot;PLANT-MICROORGANISM INTERACTIONS &quot;Prof. K.Yoshioka Prof. D. Desveaux(Departme
CSU LA - INSTRUCTIO - 490
Managing Data Resources7-1Chapter 7 Managing Data ResourcesTrue-False Questions1. Political resistance is one challenge in changing the current DBMS or going to a new one. Answer: True 2. Difficulty: Easy Reference: p. 220Most organizations h
Canisius College - CSC - 253
0: LOD X 1: A2S 2: LDS 3: HLT 4: 4: X: NUM 6000
Canisius College - CSC - 253
LOD X A2S LDS HLTX: NUM 6000
Toledo - CSB - 452
Requirement of salicylic acid for the induction of systemicScience; Aug 6, 1993; 261, 5122; Research Library pg. 754Reproduced with permission of the copyright owner. Further reproduction prohibited without permission.Reproduced with permission