95 questions shown
Java · Predict output · Textbook concept What does this print? In the textbook’s memory model, describe the two local reference variables, the heap object, and whether the object is reachable after the assignment. Chapter 14, §§14.3–14.5, printed pp. 240–264 (PDF pp. 262–286) Java · Compare concepts · Original practice Explain the difference between method overloading and overriding. Which choice is made from argument types, and which depends on the actual receiver object? Java · Find and explain an error · Original practice Why does the marked line fail to compile, and what is one sensible way to fix it? Java · Predict output · Original practice Read the program aloud in execution order. Which letters print, and why is one line skipped? Java · Find and explain an error · Original practice Identify the error and explain what the type parameter protects us from. Prolog · Code interpretation · Original practice What answers can this query produce? Explain how the rule uses its shared variable. Prolog · Compare concepts · Original practice Compare the results of X = 2+3 and X is 2+3. Why are they different? Cost models · Short problem solving · Original practice For a known list of n elements, compare putting x at the front with putting x at the end using append. Name the work you count. Cost models · Code interpretation · Original practice Both rules are logically equivalent for these pure goals. Which can avoid more wasted search, and under what kind of data? Java · Compare concepts · Textbook concept Compare pass by value, pass by reference, and copy-in/copy-out. When does a change to the formal affect the caller’s variable? Chapter 18, §§18.3–18.6, printed pp. 359–371 (PDF pp. 381–393) Java · Short conceptual question · Original practice What does a Java class define, what does an interface require, and why might a class implement an interface? Java · Predict output · Original practice What prints, and why does the declared type of the variable not force the superclass implementation? Java · Predict output · Original practice What prints? Explain why changing a field and reassigning the parameter have different effects. Java · Find and explain an error · Original practice Assume readFile declares throws IOException. Why does this method fail to compile, and name two valid fixes. Prolog · Code interpretation · Original practice Trace the first successful proof of this query. Which clause is tried at each stage? Prolog · Short problem solving · Original practice Given parent(ava, ben) and parent(ava, cara), say a rule for distinct siblings aloud, then give the answer to sibling(ben, Who). Prolog · Code interpretation · Original practice When [H|T] matches [red,blue,green], what are H and T? What happens for an empty list? Cost models · Short problem solving · Original practice A simple reverse repeatedly appends one element to the end of a growing partial result. An accumulator reverse adds at the front. Explain their time costs for n elements without just naming the growth classes. Java · Code interpretation · Textbook concept There are two roots: left points to A and right points to B. A points to B; B points to C; D has no incoming link. After right is set to null, which objects are reachable, and which are eligible for collection? Chapter 14, §14.5, printed pp. 257–264 (PDF pp. 279–286) Java · Code interpretation · Textbook exercise adaptation In a fictional language, x starts at 2 and a routine receives x as p. The body sets p = 5, prints x, then returns. What prints and what is the final x under value, reference, and value-result? Chapter 18, Exercise 6(a–c), printed p. 381 (PDF p. 403) Prolog · Short conceptual question · Textbook concept What is an atom in Prolog? Give two examples and explain how it differs from a variable. Chapter 19, §19.2, printed pp. 383–384 (PDF pp. 405–406) Prolog · Short conceptual question · Textbook concept What is a Prolog variable, and what does it mean for one to become bound during a query? Chapter 19, §19.2, printed p. 384 (PDF p. 406) Prolog · Short conceptual question · Textbook concept What is a compound term? Explain the functor and arity of parent(ava, ben). Chapter 19, §19.2, printed p. 384 (PDF p. 406) Prolog · Compare concepts · Textbook concept Distinguish a fact, a rule, and a query using a small family example. Chapter 19, §§19.2–19.4, printed pp. 384–390 (PDF pp. 406–412) Prolog · Short conceptual question · Textbook concept What does it mean for two Prolog terms to unify? Give one successful and one failed example. Chapter 20, §20.2, printed pp. 415–417 (PDF pp. 437–439) Prolog · Short conceptual question · Textbook concept What does the underscore mean in a Prolog pattern such as [Head|_]? Chapter 19, §19.8, printed pp. 403–404 (PDF pp. 425–426) Prolog · Code interpretation · Textbook concept If [H|T] unifies with [red, blue, green], what are H and T? Why does the same pattern fail on []? Chapter 19, §19.8, printed pp. 399–403 (PDF pp. 421–425) Prolog · Short conceptual question · Textbook concept What is backtracking in Prolog, and when does it happen? Chapter 20, §20.3, printed pp. 418–420 (PDF pp. 440–442) Java · Short conceptual question · Textbook concept What is the difference between a Java class and an object? What does new create? Chapter 13, §§13.2 and 13.4, printed pp. 206–229 (PDF pp. 228–251) Java · Short conceptual question · Textbook concept What is a constructor in Java, and when is it used? Chapter 13, §13.4, printed pp. 223–229 (PDF pp. 245–251) Java · Short conceptual question · Textbook concept What is a Java interface, and why might two different classes implement the same one? Chapter 15, §15.2, printed pp. 269–274 (PDF pp. 291–296) Java · Short conceptual question · Textbook concept What is method overloading? Give a pair of valid overloads and one invalid attempt. Chapter 15, §15.3 and Chapter 8, §8.2, printed pp. 274–281 and 119–123 Java · Short conceptual question · Textbook concept What is method overriding, and which version runs when a superclass variable refers to a subclass object? Chapter 15, §§15.3–15.4, printed pp. 274–281 (PDF pp. 296–303) Java · Compare concepts · Textbook concept Compare private and protected members in a Java superclass. Chapters 13 and 15, class-definition sections, printed pp. 223–229 and 274–281 Java · Short conceptual question · Textbook concept What happens when Java throws an exception inside a try block? Chapter 17, §§17.2–17.4, printed pp. 319–330 (PDF pp. 341–352) Java · Short conceptual question · Textbook concept What does it mean that Java passes arguments by value, even when an argument is an object reference? Chapter 18, §18.3, printed pp. 359–362 (PDF pp. 381–384) Java · Short conceptual question · Textbook concept What does the type argument in List<String> tell the compiler? Chapter 15, §15.6, printed pp. 283–288 (PDF pp. 305–310) Cost models · Short conceptual question · Textbook concept What is a cost model, and what assumptions must you state before saying an operation is O(n)? Chapter 21, §21.1, printed pp. 445–446 (PDF pp. 467–468) Cost models · Short conceptual question · Textbook concept What makes a recursive call a tail call, and what kind of cost can optimization change? Chapter 21, §21.3, printed pp. 451–456 (PDF pp. 473–478) Cost models · Short conceptual question · Textbook concept Why can the cost of finding Prolog's first answer differ from the cost of finding all answers? Chapter 21, §21.4, printed pp. 456–463 (PDF pp. 478–485) Java · Short conceptual question · Textbook concept In a call change(x) to change(int p), which is the actual argument and which is the formal parameter? Why does that distinction matter? Chapter 18, §18.1, printed pp. 357–359 (PDF pp. 379–381) Java · Short conceptual question · Textbook concept Define pass by value. If x is 4 and a routine changes its formal p to 7, when does x change? Chapter 18, §18.3, printed pp. 359–362 (PDF pp. 381–384) Java · Short conceptual question · Textbook concept What is pass by result, also called copy-out? May the routine read its formal before assigning it? Chapter 18, §18.4, printed pp. 362–364 (PDF pp. 384–386) Java · Compare concepts · Textbook concept What is pass by value-result, or copy-in/copy-out? How does it differ from pass by value? Chapter 18, §18.5, printed pp. 364–366 (PDF pp. 386–388) Java · Compare concepts · Textbook concept What does pass by reference mean? How can you distinguish it from copy-in/copy-out during a call? Chapter 18, §18.6, printed pp. 366–371 (PDF pp. 388–393) Java · Compare concepts · Textbook concept Compare pass by name and pass by need when the actual expression has a side effect and the formal is used twice. Chapter 18, §§18.8–18.9, printed pp. 374–378 (PDF pp. 396–400) Prolog · Short conceptual question · Textbook concept What does negation as failure mean in Prolog? Is \+ parent(ava,cara) proof that ava is not cara’s parent in real life? Chapter 19, §19.9, printed pp. 404–406 (PDF pp. 426–428) Prolog · Code interpretation · Textbook concept Why can \+ (X = Y) fail when X and Y are unbound, even though two different people exist? Chapter 19, §19.9, printed pp. 405–406 (PDF pp. 427–428) Prolog · Compare concepts · SWI-Prolog extension When X and Y are not yet bound, how does dif(X,Y) differ from \+ (X = Y)? SWI-Prolog dif/2 documentation; related Chapter 19, §19.9, printed pp. 405–406 (PDF pp. 427–428) Prolog · Short conceptual question · Textbook concept Why should you state which arguments are already known before predicting a Prolog predicate’s behavior? Chapters 19–20, procedural and list-relation sections, printed pp. 399–405 and 418–425 Prolog · Short conceptual question · Textbook concept What are the generator and the test in a generate-and-test Prolog solution? Chapter 22, §22.3, printed pp. 478–488 (PDF pp. 500–510) Cost models · Compare concepts · Textbook concept How do “find one,” “find all,” and “find the best” change a Prolog search problem? Chapters 21–22, §§21.4 and 22.3, printed pp. 456–463 and 478–488 Java · Short conceptual question · Textbook concept What is encapsulation in object-oriented programming? Give a Java example. Chapter 16, §16.3, printed pp. 306–310 (PDF pp. 328–332) Java · Short conceptual question · Textbook concept What does polymorphism mean in the Java interface or inheritance examples from class? Chapter 16, §16.3, printed pp. 306–310 (PDF pp. 328–332) Java · Compare concepts · Textbook concept What is the difference between an instance field and a static field in Java? Chapter 13, §13.4, printed pp. 223–229 (PDF pp. 245–251) Java · Compare concepts · Textbook concept What is the key lifetime difference between a stack activation record and a heap object? Chapter 14, §§14.3–14.4, printed pp. 240–245 (PDF pp. 262–267) Java · Short conceptual question · Textbook concept What is an activation record, and why does recursion need more than one? Chapter 14, §14.3, printed pp. 240–244 (PDF pp. 262–266) Java · Compare concepts · Textbook concept Compare first-fit and best-fit heap allocation on a free list. Chapter 14, §14.4, printed pp. 244–250 (PDF pp. 266–272) Java · Short conceptual question · Textbook concept How can a heap allocation fail when total free memory exceeds the requested size? Chapter 14, §14.4, printed pp. 250–255 (PDF pp. 272–277) Java · Code interpretation · Textbook concept A root points to A; A points to B; a separate object C has no path from a root. Which objects are reachable, and why? Chapter 14, §14.5, printed pp. 257–260 (PDF pp. 279–282) Java · Compare concepts · Textbook concept How do mark-and-sweep and copying collection differ? Chapter 14, §14.5, printed pp. 261–264 (PDF pp. 283–286) Java · Short conceptual question · Textbook concept Why can plain reference counting fail to reclaim two objects that point only to each other? Chapter 14, §14.5, printed pp. 263–264 (PDF pp. 285–286) Java · Short conceptual question · Textbook concept Does setting a Java reference variable to null immediately destroy the object it named? Chapter 14, §14.5, printed pp. 261–264 (PDF pp. 283–286) Prolog · Short conceptual question · Textbook concept In plays(ahmed,guitar), what are the predicate name, the two arguments, and the arity? Is plays itself an argument? Chapter 19, §19.2, printed pp. 383-385 (PDF pp. 405-407); class slide on compound terms Prolog · Compare concepts · Textbook concept How do a comma and a semicolon differ inside a Prolog rule body? Give one example of each. Chapter 19, §§19.2-19.4, printed pp. 383-391 (PDF pp. 405-413); class slide on AND and OR rules Prolog · Code interpretation · Original practice For add(X,Y,Z) :- Z is X+Y., why does add(5,3,R) work while add(Missing,3,8) raises an error? Class slide on numeric computation and evaluation order; Chapter 19, §19.2 distinguishes Prolog terms Cost models · Compare concepts · Textbook concept What is a relative cost model, and how does it differ from measuring absolute runtime? Chapter 21, §21.1, printed pp. 445-446 (PDF pp. 467-468); class slides on relative and absolute cost Cost models · Compare concepts · Textbook concept Why is access to A[i] usually modeled as constant work, while reaching the ith element of a Prolog list requires traversal? Chapter 21, §§21.2 and 21.5, printed pp. 446-450 and 459-464 (PDF pp. 468-472 and 481-486); class slide on arrays versus lists Cost models · Short problem solving · Textbook concept A rectangular 3-by-4 C array is stored row-major. List the first six elements in memory order and find the offset of A[1][2]. Chapter 21, §21.5, printed pp. 459-463 (PDF pp. 481-485); class slide on row-major memory organization Java · Compare concepts · Textbook concept Why should you avoid saying that every Java int[][] is one contiguous row-major rectangle? Chapter 21, §21.5, printed pp. 463-464 (PDF pp. 485-486); related class array-layout slides Cost models · Short conceptual question · Textbook concept What is a spurious cost model? Use manual inlining of a tiny function as an example. Chapter 21, §21.6, printed pp. 465-467 (PDF pp. 487-489); class slide on spurious cost models Prolog · Code interpretation · Textbook concept A slide says to apply restrictive goals first. Why can Age > 30 not safely go before person(Name,Age,City) when Age is unbound? Chapter 21, §21.4, printed pp. 456-459 (PDF pp. 478-481); class slide on the restrict-early principle Java · Compare concepts · Textbook exercise adaptation Two IntList objects contain the same integers in the same order. Must x == y be true? What should a value-based x.equals(y) test instead? Chapter 13, Exercise 3, printed p. 234 (PDF p. 256) Java · Short problem solving · Textbook exercise adaptation A Java IntList append method must return x followed by y without changing either input. Which part can be shared and which part needs a copy in a linked-list design? Chapter 13, Exercise 4, printed p. 234 (PDF p. 256) Java · Predict output · Textbook exercise adaptation The book asks for Queue and PriorityQueue implementations of one Worklist interface. If baker, able, and charlie are added in that order, what removal order would a FIFO Queue produce, and what order would an alphabetic PriorityQueue produce? Chapter 15, Exercise 1, printed pp. 289–290 (PDF pp. 311–312) Java · Compare concepts · Textbook exercise adaptation The book contrasts a character iterator with hasNext() and one whose next() throws a checked exception at the end. How would a caller know when to stop in each design? Chapter 17, Exercise 1, printed pp. 344–345 (PDF pp. 366–367) Java · Predict output · Textbook exercise adaptation An array starts as [0,2]. A method receives its two selected int elements as ordinary Java int parameters, then assigns 1 and 3 to those parameters. What remains in the caller's array, and why? Chapter 18, Exercise 6(a), printed p. 381 (PDF p. 403) Prolog · Short problem solving · Textbook exercise adaptation Using parent(X,Y) and female(X), say a Prolog rule for mother(X,Y). Explain the meaning of the comma. Chapter 19, Exercise 1, printed p. 410 (PDF p. 432) Prolog · Short problem solving · Textbook exercise adaptation Define a relation third(List,Item) that finds the third element. Can it be written as a single fact-style clause using a list pattern? Chapter 19, Exercise 7, printed p. 410 (PDF p. 432) Prolog · Short problem solving · Textbook exercise adaptation Define first_pair(List) so it succeeds when a list has at least two elements and its first two elements are equal. Chapter 19, Exercise 8, printed p. 410 (PDF p. 432) Prolog · Short problem solving · Textbook exercise adaptation Define del3(Input,Output), where Output is Input with its third element removed. Explain why the rule fails on a short list. Chapter 19, Exercise 9, printed p. 410 (PDF p. 432) Prolog · Code interpretation · Textbook exercise adaptation The book asks for a prefix relation that can also generate prefixes. For the rule below, what answers can prefix(X,[a,b]) return? Chapter 19, Exercise 14, printed p. 411 (PDF p. 433) Prolog · Code interpretation · Textbook exercise adaptation Using the standard append relation, list every solution to append(Left,Right,[1,2]). Why are there exactly three? Chapter 20, Exercise 2, printed p. 443 (PDF p. 465) Prolog · Code interpretation · Textbook exercise adaptation Can a depth-first Prolog search appear stuck even when a logically valid answer exists in another branch? Explain with a small clause-order example. Chapter 20, Exercise 4, printed p. 443 (PDF p. 465) Cost models · Short problem solving · Textbook exercise adaptation A recursive predicate reverses its tail, then uses append to put the old head at the end. How would an accumulator remove the repeated traversal, and what changes in the cost? Chapter 21, Exercise 3, printed p. 468 (PDF p. 490) Cost models · Compare concepts · Textbook exercise adaptation A grandfather rule can test male(X) before or after searching parent(X,Z). If there are many parent facts but only a few male facts, which order would you try first? How could the answer change with different data? Chapter 21, Exercise 9(a–b), printed pp. 469–470 (PDF pp. 491–492) Prolog · Short problem solving · Textbook exercise adaptation Define max_num(X,Y,Max) for two already known numbers. Which Prolog operation compares the numbers, and how is Max bound? Chapter 22, Exercise 1, printed p. 489 (PDF p. 511) Prolog · Short problem solving · Textbook exercise adaptation Describe a recursive Prolog predicate ordered(List) that succeeds when a known numeric list is in nondecreasing order. Which base cases are needed? Chapter 22, Exercise 3, printed p. 490 (PDF p. 512) Java · Code interpretation · Textbook exercise adaptation An array cell A[0] starts at 4. A fictional routine receives A[0] as p, executes p = 7, and then returns. What is A[0] during the routine and after return under by-value, by-reference, and value-result? Chapter 18, Exercise 6(a–c), printed p. 381 (PDF p. 403) Java · Short problem solving · Textbook exercise adaptation A conceptual actual expression next() increments a counter and returns its new value. A callee reads its formal twice. How many times does next() run under by-value and by-name passing, and why? Chapter 18, Exercise 6(a,e), printed p. 381 (PDF p. 403) Prolog · Code interpretation · Textbook exercise adaptation For a known list [1,2,3] and target 3, a subset-sum relation generates subsequences and checks their numeric totals. Which answer lists should it produce, and what role does backtracking play? Chapter 22, Exercise 6, printed p. 490 (PDF p. 512) Prolog · Short problem solving · Textbook exercise adaptation To generalize the book’s eight-queens search to N queens, what should a candidate placement represent, and what two kinds of conflict must a legality test reject? Chapter 22, Exercise 5, printed p. 490 (PDF p. 512) Java · Short problem solving · Textbook exercise adaptation An abstract free list has usable blocks of sizes 8, 4, and 6 in that order. A size-4 allocation arrives. Which block would first fit choose, which would best fit choose, and what could happen to an oversized block? Chapter 14, Exercise 1, printed pp. 265–266 (PDF pp. 287–288) Java · Code interpretation · Textbook exercise adaptation A quick-list heap manager has freed several small adjacent blocks into size-specific quick lists. A larger allocation has no matching free block. Why might it retry after flushing quick lists and coalescing? Chapter 14, Exercise 2, printed pp. 266–267 (PDF pp. 288–289) Java · Compare concepts · Textbook exercise adaptation The textbook proposes one memory region with a heap growing upward and a stack growing downward. What must the manager check on every push or heap growth, and why can this arrangement use space flexibly? Chapter 14, Exercise 3, printed pp. 267–268 (PDF pp. 289–290)