3 Pages

ex4-sol

Course: COMP 524, Fall 2008
School: UNC
Rating:
 
 
 
 
 

Word Count: 795

Document Preview

524--Spring Comp 2009 Exercise 4 Solutions Due at 3:30 PM (on paper), March 26, 2009. 1. (20 pts) Ex. 7.19, p. 401. Hint: Due to alignment constraints, there is padding between array elements. Show your work. Each member of the 2D array is a struct containing an int and a char. The int is 4 Bytes long and the char is 1 Byte long but we must pad with an additional 3 Bytes for alignment. Thus, each element is 8...

Register Now

Unformatted Document Excerpt

Coursehero >> North Carolina >> UNC >> COMP 524

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.
524--Spring Comp 2009 Exercise 4 Solutions Due at 3:30 PM (on paper), March 26, 2009. 1. (20 pts) Ex. 7.19, p. 401. Hint: Due to alignment constraints, there is padding between array elements. Show your work. Each member of the 2D array is a struct containing an int and a char. The int is 4 Bytes long and the char is 1 Byte long but we must pad with an additional 3 Bytes for alignment. Thus, each element is 8 Bytes. To reach element A[3][7], we pass through three full rows and seven elements of one partial row. Since each row consists of ten elements, the space requirement for a row is 10 * 8B = 80B. Thus the address for A[3][7] can be found as follows: Array start address: 1000B + preceding rows space: + (3 * 80B) + preceding elements space: + (7 * 8B) -----------------------------------------------------------Total: 1296B 2. (10 pts) Ex. 7.28, parts a and b, p.403. We can regard objects as useless at some point in the code if they are never accessed after that point. These objects will not reclaimed by the garbage collector as long as there is a chain of references from the stack that can be followed to reference them. In order to determine that such objects are useless, the compiler and/or run-time system would have to confirm that they are not used in paths of program execution yet to be taken. While this is possible for some (simple) programs, in the general case this is not possible. The problem is depends on the halting problem: It is undecidable whether a program will even halt on a finite input. Thus it is also not possible to determine which paths it will take nor which variables will be used. Intuitively, consider the difficulty of the problem when user input directs the path taken by the program. 3. (20 pts) Ex. 6.14, p. 300. Note: The figure is on p. 281. We are asked to modify the code to implement in-order rather than pre-order enumeration. Here is one possible solution: pub li c c la ss TreeNode<T> im pl em en ts Iterable<T> { TreeNode<T> left; TreeNode<T> right; T val; pub li c Iterator<T> iterator() { ret ur n n ew TreeIterator(th is); } pri va te cl as s TreeIterator i mp le me nt s Iterator<T> { pri va te Stack<TreeNode<T>> s = ne w Stack<TreeNode<T>>(); TreeIterator(TreeNode<T> n) { TreeNode<T> currNode = n; // leftmost node is first in enumeration whi le (currNode != nu ll) { s.push(currNode); currNode currNode.left; = } } pub li c b oo le an hasNext() { ret ur n !s.empty(); } pub li c T next() { if (!hasNext()) { thr ow ne w NoSuchElementException(); } TreeNode<T> n = s.pop(); TreeNode<T> currNode = n; if (currNode.right != n ul l) { currNode = currNode.right; // proceed to leftmost node in right subtree do { s.push(currNode); currNode = currNode.left; } whi le (currNode != nu ll); } ret ur n n.val; } pub li c v oi d remove() { thr ow ne w UnsupportedOperationException(); } } } 4. (20 pts) Ex. 6.22, p. 301. Write your alternative in Java. Contrast it with Rubin's code in a well-written paragraph. Which is has fewer LOC (lines of code)? Which is more intuitive? Examples of possible solutions are given in the paper aptly titled, "'"GOTO Considered Harmful" Considered Harmful' Considered Harmful?'" http://www.ecn.purdue.edu/ParaMount/papers/acm_may87.pdf Djikstra penned his own response later since he didn't feel that the paper above expressed his thinking on the matter. You can read that very formal paper here: http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1009.html I would add from my own point of view that LOC, though widely used, is an imperfect measure of code size. It is most useful when the code to be compared uses a standard coding style (especially important in free-form languages) and as an asymptotic measure of code size, i.e. O(1000) LOC. Many people argue that the structured sol...

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:

Stanford - HRBFA - 1033
US District Court Civil Docket as of 11/16/2005 Retrieved from the court on Thursday, February 09, 2006U.S. District Court California Northern District (San Francisco)CIVIL DOCKET FOR CASE #: 3:04-cv-04848-MHPBennett et al v. H&amp;R Block Financial
UNC - COMP - 524
Lecture 17: Objects ContinuedCOMP 524 Programming Language Concepts Stephen Olivier April 7, 2009Based on slides by A. Block, notes by N. Fisher, F. Hernandez-Campos, and D. StottsThe University of North Carolina at Chapel HillBindingclass pe
UNC - COMP - 524
Comp 524-Spring 2009Exercise 5Due at 3:30 PM (on paper), April 16, 2009. Please type your answersThe questions below refer to the following database: :- dynamic pop/2. capital(france,paris). capital(uk,london). capital(peru,lima). capital(chile,
Washington University in St. Louis - CSE - 547
CSE 547 Lecture 12Jeremy Buhler February 23 20091Are Regular Languages Context-Free?So far, we've seen that CFGs can represent languages that are not regular. But can they represent all regular languages? YES! Defn: a regular grammar G is a g
Washington University in St. Louis - CSE - 547
CSE 547 Lecture 11Jeremy Buhler February 18 2009And now for something completely dierent.1Are Finite Automata Good Enough?Hard as it is to believe, this course had a purpose: inquiring as to what computers can do. So far: one model, namely
Stanford - PUBS - 20186
Macro Patterns in the Use of Traditional Biomass FuelsNadejda M. Victor &amp; David G. VictorWorking Paper #10November 2002The paper was first presented at the Rural Energy Transitions conference, jointly convened by PESD and the Tata Energy Resea
Stanford - PUBS - 20268
Political Economy and the Hydrogen RevolutionDavid G. Victor, Thomas C. Heller, Nadeja M. VictorWorking Paper # 17September 2003The Program on Energy and Sustainable Development at Stanford University is an interdisciplinary research program fo
Stanford - PUBS - 22226
MEASURING THE CLEAN DEVELOPMENT MECHANISMS PERFORMANCE AND POTENTIALMichael Wara*The Clean Development Mechanism (CDM) of the Kyoto Protocol is the first global attempt to address a global environmental public goods problem with a market-based me
Stanford - PUBS - 20678
The Polish Electricity Market Investment ContextJoshua C. HouseWorking Paper #31August 2004The Program on Energy and Sustainable Development at Stanford University is an interdisciplinary research program focused on the economic and environment
Stanford - PUBS - 20603
geopolitics of gas working paper seriesTHE BELARUS CONNECTION: EXPORTING RUSSIAN GAS TO GERMANY AND POLANDdavid victor and nadejda makarova victorThe Belarus Connection: Exporting Russian Gas to Germany and PolandDavid G. Victor and Nadejda Mak
Stanford - DAVISFUNDS - 1033
US District Court Civil Docket as of 12/8/2004 Retrieved from the court on Friday, December 17, 2004US District Court for the Southern District of New York1:04cv4186 Alexander Ira v. Davis Investments, LLC et al Date Filed: 06/03/2004 Assigned To:
UNC - COMP - 290
NeonGraphics AcceleratorAnselmoLastraTheUNIVERSITYofNORTHCAROLINAatCHAPELHILLHistoryAproposedDECproduct Neversold,asfarasIknow TheywereboughtbyCOMPAQLaterHPPaperat1998GraphicsHardwareTakeintoaccountthatthiswasinthedaysof3dfx VoodooNottoom
Minnesota - MATH - 2263
MATH 2263, Midterm 2, Spring 2005, March 24 Problems and Solutions 1. Use Lagrange multipliers to nd the maximum and minimum values of f (x, y) = x + 2y subject to the constraint g(x, y) = x2 + y 2 = 5. Solution. By the method of Lagrange multipliers
UNC - CS - 290
The WarpEngine: An Architecture for the Post-Polygonal AgeVoicu Popescu, John Eyles, Anselmo Lastra, Joshua Steinhurst, Nick England, Lars Nyland University of North Carolina at Chapel HillABSTRACTWe present the WarpEngine, an architecture design
Minnesota - MATH - 8583
Math 8583: Theory of Partial Dierential Equations: Fall 2007 Announcement: Problems for Final Exam will be given on Wednesday, December 5. Solutions are due till 1:30 pm on Wednesday, December 19, 2007. Homework Assignment 4 (due on Wednesday, Decemb
Minnesota - MATH - 4512
MATH 4512. Dierential Equations with Applications. Midterm Exam #1. March 4, 2009.60 points are distributed between 5 problems, 12 points each. You have 50 minutes to work on these problems. No books, notes, and calculators. 1. Solve the initial val
Minnesota - MATH - 8583
Math 8583: Theory of Partial Differential Equations: Fall 2007 Information and some problems for in-class Midterm Exam The Midterm Exam is scheduled on Wednesday, November 7, 2007, during the class time: 10:10 am - 11:00 am, VinH 211, Books, notes, a
Stanford - CS - 347
Network partitions CS 347: Distributed Databases and Transaction Processing Notes 09: Network PartitionsHector Garcia-Molina Groups of nodes may be isolated or nodes may be slow in respondingPNetPCS347Notes091CS347Notes092 Where
Minnesota - MATH - 1297
Math 1297 Calculus II Spring Semester 2009Instructor: Diana Colt Office: MWAH 157 Email: dcolt1@d.umn.edu Phone: 726-6353 Office hours: MW: 2 - 4:00, F: 2 - 3:00, and by appointmentWebpage: http:/www.d.umn.edu/~dcolt1 Text: Calculus, Early Transc
Minnesota - MATH - 3280
Math 3280: Differential Equations &amp; Linear AlgebraInstructor: Diana Colt Office: MWAH 157 Email: dcolt1@d.umn.edu Phone: 726-6353Office hours: MW: 2 - 4:00, F: 2 3:00, and by appointmentWebpage: http:/www.d.umn.edu/~dcolt1 Lecture: MWF 9-9:50 K
Minnesota - MATH - 3355
Math 3355 Discrete Mathematics Spring Semester 2009Instructor: Diana Colt Office: MWAH 157 Email: dcolt1@d.umn.edu Phone: 726-6353 Office hours: MW: 2 - 4:00, F: 2 3:00, and by appointmentWebpage: http:/www.d.umn.edu/~dcolt1 Text: Discrete Mathe
Washington University in St. Louis - CSE - 260
CSE 260 Digital Computers: Organization and Logical DesignProblem Set 8Jon Turner1. Write a VHDL module that defines a sequential circuit implementing each of the state diagrams in the posted solutions for problem 8 of Problem Set 9. Write thes
Washington University in St. Louis - CSE - 260
CS/EE 260 Digital Computers: Organization and Logical DesignDesign Problem 5 SolutionJon Turner 4/16/02In this assignment, you have a choice of two problems you may do. The first involves extending the simple processor that has been discussed i
Washington University in St. Louis - CSE - 577
CS/EE 577 Homework 3 Solutions1. Suppose you are required to design an ATM network to support 4096 users, but that the only switches available have just 32 ports. Give a diagram of a network similar to the one on page 3-2 of the notes, with 1:1 co
Allan Hancock College - MATH - 3062
School of Mathematics and Statistics The University of Sydney MATH3062 NUMBER THEORY AND ALGEBRA LECTURE 14Squares in Z - Quadratic Residues. p Consider the following table:p: 3 5 7 11 13 17 19 231 1 1 1 1 1 1 14 2 3 3 2 4 24 4 4 4 6 35 9
Allan Hancock College - MATH - 3062
School of Mathematics and Statistics The University of Sydney MATH3062 NUMBER THEORY AND ALGEBRATutorial 520091. Write down the values of the Legendre symbol 1 a, p 11.a p, for every relevant value of a, p witha 2. Write down the square
Allan Hancock College - MATH - 3062
School of Mathematics and Statistics The University of Sydney MATH3062 NUMBER THEORY AND ALGEBRA LECTURE 15Proof of Theorem 24 continued Suppose that x Sp and so Hence xp-1 2x p= 1. If g Zp is a generator, x = g 2r for some integer r. g 2r
Purdue - FLL - 1989
FICTIONS OF MOTHERHOOD: THREE SHORT STORIES BY LUISA VALENZUELA Mary K. Addis The College of Wooster Both Luisa Valenzuela's narrative practice and her theorizing in several recent essays share with the linguistically radical French feminists a conce
Purdue - FLL - 1989
FEMINISM AND BUUEL: POINTS OF CONTACT Virginia Higginbotham University of Texas at Austin Buuel's women are fabulous masochists. They love being maimed, tortured, and degraded. How it comes about that the feminist movement seems not to question Buuel
Allan Hancock College - MATH - 3062
School of Mathematics and Statistics The University of Sydney MATH3062 NUMBER THEORY AND ALGEBRATutorial 420091. Write 5.13.73 as a sum of two squares in at least three dierent ways. Solution (1 + 22 )(22 + 32 ) = (1.2 2.3)2 + (1.3 + 2.2)2 = 4
Minnesota - IE - 5080
Lagrangian RelaxationsUn-Capacitated Facility Location STSP Generalized Assignment ProblemBranch and Bound MethodBharath RangarajanFeb 12, 2009B. RangarajanBranch and Bound Method02/12/091/8UFL formulationMinimize CostLagrangian Rel