Untitled - Stacks are the Stanford
Transcription
Untitled - Stacks are the Stanford
Exam No. > 13. (20 points) Give an effective algorithm to determine for an arbitrary context-free grammar, whether all words generated by it contain an equal number of occurrences of letters a and b 31 . Exam # SPRING 1975 COMPUTER SCIENCE COMPREHENSIVE EXAM Given 10 May 1975 noon - 12:00 - 4:30 Polya Hal 1 Room 11 1 9:00 1:30 TO: THOSE WHO TAKE THIS EXAM a) The exam contains questions drawn from six areas of computer science. The total possible score is 360 or 60 points in each area. b) During the lunch break you are urged to relax. You may not consult any references or colleagues or write drafts of answers. c) Write your exam ff in the upper right corner of each page. you have all 31 pages of the exam. d) Show your work as partial credit will be given. syl labus c) Grading Strategy: To pass this exam, you should not leave any subject area completely blank as there will be a minimum competence requirement in each area. After that, the exam will be graded on a curve so you should try to maximize your total score. f) Sign the honor code statement. . Be sure This exam is open - In recognition of and in the spirit of the Honor Code, I certify that I have neither received nor given unpermitted aid on this exam. Signed GOOD luck: ..♦_ The results of the written part will be available Thursday, May 15, at 9:00 in the department office, Polya Hall 253. The programming problem may be picked up at that time and will be due Monday, May 19, at 5:00 p.m. f 1 Exam ff SPRING 1975 COMPUTER SCIENCE COMPREHENSIVE EXAM Systems 1) 2) 3) 4) 5) Deadlock LISP Paging Concepts Compiler Quickies Process Synchronization Hardware 1) 2) 3) 4) Combinational Logic J-K Flip-Flop Binary Counter Architecture Concepts Theory of Computation 1) 2) 3) Diagonal ization Finite Automata Context-Free Language Quickies Algorithms & 1) 2) 3) ALGOL 60 Problem Tree Traversal Sparse Matrix Numerical l) 2) 3) 4) Data Structures Analysis Banded Linear Systems Arithmetic and Error Analysis The Rank Problem Newton's Method Artificial Intelligence 1) 2) 3) *. "Understanding" Systems A.I. Concepts A. I *Quickies . SYSTEMS (5 minutes) Deadlock 1. Exam ff Three parallel processes share four tape units which can be reserved or released only one at a time. units. Each process needs at most two tape Can a deadlock occur in this system? _ * 3 Exam # SYSTEMS 1 (10 minutes) and Systems Question LISP The bindings of variables in a LISP program act quite differently from those in ALGOL. Describe briefly the basic difference in the philosophy of the two approaches to determining binding. 2 How would a paging environment influence your implementation of the CONS (structure building) function? * 4 Exam ff SYSTEMS (20 minutes) Paging Concepts 1. A process refers to five pages, A,B,C,D,E, in the following order: A-B-C-D-A-B-E-A-B-C-D-E Assume the system uses a FIFO replacement algorithm. a. Find the number of page faults starting with an empty store and 3 page frames. 4 page frames. Repeat part "a" assuming a LRU replacement algorithm. b. 2. Same question for Using the hardware mechanisms of current machines that support paging, describe a practical approximation to an LRU. page replacement algorithm 3. Under what circumstances will page sharing improve the performance of a paged multiprogramming system? * 5 SYSTEMS Exam # Compi ler Quickies (5 minutes) 1. Discuss three ways of reducing the storage requirements needed for using precedence techniques. (5 minutes) 2. Give an example of why a compiler writer may want to combine two different parsing techniques in one compiler. (5 minutes) 3. Can precedence functions be assigned to this matrix? answer. ) s s b - . H s, 2 hl> -J * 6 (Justify your SYSTEMS Exam # (5 minutes) 4. What are the pros and cons of typed and typeless languages? examples of each. 7 Give SYSTEMS Exam ff (5 minutes) Process Synchronization Describe a primitive process synchronization mechanism. 8 Exam # HARDWARE (20 minutes) Combinational Circuit Problem The boolean Fibonacci function f is defined to be TRUE for the binary inputs corresponding to il, 2, 3, 5, 8, 1 3 5 and FALSE otherwise except that we don't care what value it has for inputs |7 and i) 9] " Give the minimal sum of products expression for f I 1 / ii) 1 Give the minimal product of sums expression for f. A multiplexor is a circuit that can select information from one of several input channels and route that input to a single output lead. The input terminal is selected by a binary encoded address supplied to the circuit. A multiplexor can be used as a universal switching function by connecting a fixed 1 or a fixed 0 to each of its inputs. 9 ■» Exam # HARDWARE i ii) Implement fon this 16 input multiplexor. iv) Can you implement f using only this single 8-input multiplexor and inverters? (if yes, do it) UJP'oTS 1 ftWm* / " « 10 HARDWARE J-K Flip-Flop (b) st Exam # (10 minutes) A logic diagram for a J-K master-slave flip-flop can be drawn in outputs that are terms of two S-R latches as shown below. Draw the (^ and Q2 inputs shown. obtained from the J, X, and CX 11 HARDWARE Exam # (15 minutes) Bi nary Counter Give the logic diagram of a lf-bit synchronous binary counter us mg J X master-slave flip-flops. (In a synchronous counter all of the output bi ts must change simultaneously.) f. % %■. 12 * HARDWARE Exam § (15 minutes) Architecture Concepts Slow machines usually do things sequentially which faster machines can usually do at least partially in parallel. For each of the following terms , describe briefly what it is and how its use can increase a computer's execution rate. a. multiprocessing b. memory interleaving c. wide buses d. associative memory * 13 Exam # THEORY OF COMPUTATION (30 minutes) Diagonal i zation Problem Diagonal ization is a technique made famous when Cantor proved that The technique assumes a list of items the real numbers are not countable. and establishes the existence of a new item which differs in some way from each item in the list and is therefore not in the list. a. Use diagonal ization to show that there can be no effective enumeration of the total recursive (defined for all inputs) functions. by assuming that there is such an enumeration.) 1 « 14 a (HINT: start THEORY OF COMPUTATION b. It is possible to give a listing [C., C sensitive grammars. , Exam C ...J of all # context Show that there exists a recursive set which is not context sensitive. 15 Exam # THEORY OF COMPUTATION (20 minutes) Fini te Automata Given the finite state machine M below whose inputs can be interpreted as - Letter D - Digit X - Del imi ter L Decimal Point and where F..M is the set of final states fU-KS 7 ] i « (a) Write a regular expression for the strings which end at state For example, the regular expression the set of strings over the set T.* " D*x « 16 £o,lj* foOOj Jo,l}* |O,IJ having 6. denotes three consecutive O's. Exam # THEORY OF COMPUTATION (b) Construct a non-deterministic machine which recognizes the reversal of the language recognized by M. (c) (Draw its state diagram. >. Construct a deterministic machine which recognizes the reversal of the language recognized. (d) Relate this problem to lexical analysis. _> 9 r * 17 . Exam 0 THEORY OF COMPUTATION (10 minutes) Context-free Language Quickies Consider the language defined by the grammar S -* a S -> A b B A -* b A -» S B c B -» A a S B -> a S A with start symbol S and terminal alphabet [a,b,cj 1. Prove that the language contains no strings of length 2. Find all strings in the language of length 9, having the letter "c" as their middle (fifth) character. I V 18 « 100. ALGORITHMS S DATA STRUCTURES 60 Algol Exam § (30 minutes) Problem The original ALGOL 60 report shown on the following page. concluded with the example procedure RK After fifteen years have gone by, we think we know a little more about control structure and style. Suppose ALGOL 60 has been extended to include the following new syntax (basic statement) ::= (loop statement) (loop statement) ::= loop (statement list) while (Boolean expression): (statement list) repeat ::= (statement) j (statement list); (statement) (statement list) and the semantics that, if J and T are statement lists and B is a Boolean expression, the loop statement loop J while B : T repeat is equivalent to J> if B then begin T; loop J while B : T repeat end RK procedure, using the new loop statement, in order to eliminate unnecessary go to statements which tend to obscure the control Rewrite the structure of the program in its original form. Important note: etc. Large segments of the program have been marked OL ,(3 , J so that you need not recopy them; simply give your answer in terms of these abbreviations, as "procedure RK c. " etc. You need not understand precisely what goes on inside those chunks of code in order to solve this problem. Don't make any changes to the actual sequence of computations, and don't try to do any tricky things like eliminating the Boolean variable --"out" etc. Simply remove as many of the go to statements and meaningless labels as you can by taking advantage of the new loop construct * 19 , Exam ff OL c r BB: RKlST(x,y,H,x2,y2); RKlST(x2,y2,H,x3,y3) for k : =1 step 1 until n do if comp(yl[k], y3[k], eta)>eps then go to CC; / comment: comp (a, b, c) is a function designator, the value of which is the ( absolute value of the difference of the mantissas of a and b, after the exponents \ of these quantities have been made equal to the largest of the exponents of the 20 ALGORITHMS £ DATA STRUCTURES Exam # (10 minutes) Tree Traversal Traversal of a binary tree in comprehens ive-qual order (CQ order) is defined as follows. procedure CQ(t) ; binary tree t; if t ± A then begin if right(t) ¥= A then begin CQpeft (ri ght (t) ) ) ; visit(t); CQ(left(t)); vlsl t (right (t)); CQ(right(right(t))) ; end else begin visit(t) ; CQ(left(t)) end end. left (t) , right (t) denote respectively the left and right subtrees of a nonnull binary tree t In what order are the nodes of the following binary tree visited, when it is traversed in CQ order? (State the single-letter names of Here A denotes a null binary tree; and the nodes as they are encountered.) . . < i Answer « 21 ALGORITHMS & DATA STRUCTURES data structure would you use to represent a sparse 100 x 100 matrix (1 word entries), if you are told that it contains (a) At most 5 (b) At most 50 (c) At most 500 (d) At most 5000 non-zero entries non-zero entries non-zero entries non-zero entries The operations you will have to do on the matrix are (i) fetch element A Ci,jl, given i and j (ii) store element A L'..o> given i and j (iii) fetch all non-zero elements of a given row (iv) fetch all non-zero elements of a given column ... # (20 minutes) Sparse Matrix .What Exam 22 Exam # NUMERICAL ANALYSIS Banded Linear Systems 1 ) (lO minutes) It is well known that linear systems Ax = b can be solved using Gaussian elimination without pivoting if the matrix (e.g., A is irreducibly diagonally dominant or A A has certain properties is positive definite). Explain why this is an important practical consideration when dealing with banded matrices m A = , (a. .) is small compared with n a. , . = 0 | 'l-j |> the rank of the matrix. i * if 23 m , say, where Exam # NUMERICAL ANALYSIS (10 minutes) Ari thmetic and Error Analysis 2) a. Do floating point and real arithmetic have the same arithmetic properties (e.g., associativity, + and x commute, etc.)? Prove your point. b. What advantage does inverse error analysis have over forward error analysis? 24 "a. NUMERICAL ANALYSIS Exam # The Rank Problem 3 It is easy to ye a) What does this indicate about the condi tioning of the matrix on the left hand side? b) Does the above example say anything about the use of Gaussian elimination to determine the rank of a matrix? (Recall that Gaussian elimination can be viewed as transforming a matrix to upper triangular form.) * 25 NUMERICAL ANALYSIS Exam # (20 minutes') k) NewtohVs Method Newton's method is one of the best known iterative techniques for evaluating The iterative step of the method is given by the root of a function. xn+l a. x f(x ) n IrW) v n The graph below shows a function using Newton's method has just evaluated F the position for the estimate f near one of its roots. at x as Indicated. A program Show geometrically x / Can you predict any difficulty that will beset the program during the next few iterations ? » « 26 'J Exam # NUMERICAL ANALYSIS Some polynomials, especially those of high degree, are unstable b. in the sense that small changes in the coefficients will lead to large changes in the zero. "■' = 1) where A Ar = Show that the relative root change -a r n *"* an axn p(x) - n l n + a.x is the polynomial Oz.i<n-l 2) p(r) 3) "a " = 0 , i.e. r is a root is the coefficient being slightly changed. ■j / L X "& I o* f> A*-/ (r+tt Newton's method is sometimes recommended because of its quadrat I c c. convergence. Herman Newfellow has observed that the corrections p(x.) / p (x.) were reduced by a factor of about 1/2 for each of the fi 10 iterations of his program. What order of convergence does this mdi cate? How would you explain this to Herman? i 27 * rst r Exam # ARTIFICIAL INTELLIGENCE (30 minutes) "Understanding Systems" In recent years the A.I. research community has been describing much of its research as "understanding": viz. speech understanding, language understanding, and image understanding. l) (20 minutes) What A.I. concepts, capabilities, program organizations, representations, and tools are used in "understanding" systems? Which of these are relatively domain specific and which are general? Illustrate and refine your answer by dealing specifically with one of the following areas of program understanding. For the area chosen, concentrate on one system in detail or survey the few systems which exist in the area. Keep your answers brief and to the point. a) English language understanding b) speech understanding c) organic-chemical mass spectral data interpretation « 28 ARTIFICIAL INTELLIGENCE 2) Exam ff (10 minutes) Suppose we designed an image understanding computer system (ala A.I. vision systems) to ride along on a future ERTS (Earth Resources Technology Satellite) orbiting mission and to radio back to scientists on earth what it "understood" about the scenes being viewed. From the A.I. scientist's point of view, what would be the essential design problem in making the system work? T ■'-. 29 ARTIFICIAL INTELLIGENCE A. I . Exam # (20 minutes) Concepts Define each of the following problem-solving concepts and methods, and give a short (one or two sentence) description of the sort of problem (For instance, "table lookup" might be defined as the selection of data elements from an Information structure by processing keys associated with the data. It would be applicable in situations where the set of possible answers is explicit, there are appropriate keys and selection functions, and the number of elements is small enough to allow the storage and retrieval to be reasonably efficient ) domain to which it is applicable. 1 . heuristic search 2. means-ends analysis 3. hill cl imbing k. "demons" 5. production systems * 30 Exam ff ARTIFICIAL INTELLIGENCE A.I 1 (10 minutes total) Quickies The state-space approach to problem solving is a special case of the problem reduction approach. True or False? why bother dealing with a separate concept 2 (True or False). (if true, then of "state-space methods"?) Explain. The alpha-beta technique is often faster than the minimax technique but it may achieve a less optimal answer. 3 It has been suggested that work on programs of a general problem solving nature has been shelved temporarily. would be the reason for this trend? 31 # Supposing this is correct, what State your answer briefly. * 15 MAY 1975 i COMPUTER SCIENCE COMPREHENSIVE PROGRAMMING PROBLEM Simulation of a Packet-switching Network (Due Tuesday, May 20, at 9.00 a.m. in CS Dept. Office) Computer networks are becoming more widespread and are influencing the way people can .use computers. Although networks seem conceptually simple, some aspects of their design were not appreciated until the networks were actually implemented. In the problem you will be able to experiment with some elements of network design as well as learn something about the programming of a simulation. Background The basic model for a network that we have in mind is a simplified version of the ARPA network. The network is made up of IMPs, which are minicomputers used for message switching and which are connected to each other by transmission lines. Each IMP is also connected to a HOST which is a local computer where the user does his actual computations. Each IMP is in fact a computer and is busy managing the message traffic between HOSTs. For the purposes of this simulation, we will be mostly concerned about whrjt is going on inside the IMPs and will use a relatively simple model for the activity of each HOST. The traffic on the network consists of variable length messages. A message enters the network at the source (or sending) HOST, which specifies a destination (or receiving) HOST. The message is transmitted through an appropriate set of IMPs and finally leaves the network at a destination HOST. - MESSAGES Messages have the following attributes: 1) source: HOST or IMP which sent it 2) destination: HOST or IMP to receive it ?.) acknowledge bit: Bit which is set if the message is simply an acknowledgement of a previous message 4) length: number of bits in message. Specified by sender. - used 5) sequence number: set by sender (32 or 36 bits) messages are delivered in the order they are sent. - to assure that For simplicity, we will assume that messages are sent as a whole we will not model the packing and unpacking of messages into smaller units. Also, we will pay no attention to the contents of messages. For our purposes we will assume that there are only two sorts of messages: 1) Acknowledgement messages, which have the acknowledge bit set and have length HEADER BITS. * I 2) Data messages, which come in two flavors: a) short (length = HEADERBITS+SHORTBITS) b) long (length = HEADERBITS+LONCBITS) Short messages occur with probability SHORTPROB and long messages occur with probability ( 1 SHORTPROB). - LINES Lines carry the messages between IMPs or between an IMP and a HOST. The lines between IMPs carry messages at a fixed rate, LINERATE, in thousands of bits per second. They are full-duplex, that is, they can carry messages simultaneously in both directions (at LINERATE in each direction). The transmission time of a message is assumed to depend only on the message length. Furthermore, each line connecting an IMP to another IMP is assumed to have a probability, LOSSPROB.<Ieneth of messago of garbling a message so that it will have to be retransmitted. (Yes, we know this cannot be quite right, but accept it as an approximation). Error detection circuitry in the receiving IMP will detect broken messages. The lines connecting an IMP to its HOST are assumed to have zero error and operate at HOSTRATE: In addition, they have a special BLOCK signal by which the IMP can prevent the HOST from sending more messages. HOSTS For our purposes, assume that each IMP is associated with exactly one HOST. Each HOST generates messages with a POISSON' arrival time distribution. This means that the intervals between the times that the HOST queues messages for transmission to its IMP are exponentially distributed. These may be generated for the simulation by the relation T ,=T -TLAMBDA.(In(r)) n+ 1 n To = ° where r is uniformly distributed on (0,1), and TLAMBDA = mean interanival time. No HOST sends a message to itself. The distribution of each message from a HOST is equal to the destination of the previous message sent from that HOST with probability SAMEPROB; otherwise, the destination is randomly chosen from among the HOSTs other then the sending HOST (including the HOST of the previous message), each with equal probability. As messages are generated, the HOST places them into an output queue to its corresponding IMP. The IMP accepts messages from the HOST at rate HOSTRATE unless the IMP is blocked (in which case, the messages just remain in the HOST's output queue). If the HOST runs out of buffer space, it stops generating messages until a buffer becomes free. If an IMP blocks a HOST while a transfer (into the IMP) is in progress, that transfer will be completed, but no new HOST-to-IMP transfers will be started until the IMP unblocks the HOST. We assume that the HOST is always able to accept a message from its IMP at the HOSTRATE. We will not simulate what the HOST does with the messages it receives. * I . IMPS The IMP is the basic message switching processor of the system. Each IMP is connected to some subset of the set of other IMPs as determined by the topology of the network. When an IMP accepts a message from its corresponding HOST, it adds a sequence number telling the order (first, second, third, etc) of that message in the stream from the source to the destination HOST. (In other words, there is a separate set of sequence numbers for each HOST-HOST pair). Internally, each IMP has a Route Control Table by which it determines how to route a message. This is simply a table of line numbers indexed by destination IMP or HOST. Every IMP maintains a buffer pool from which it allocates buffers for its various processes. For simplicity, each buffer is assumed to be long enough to contain one maximum length message. to keep a buffer available on each of its lines ready to receive input. When an ungarbled message arrives, and there is a free buffer available, the IMP processes it by doing the An IMP tries following: 1. Send an acknowledgement. (This does not necessarily require a new buffer to create the acknowledgement message). 2. If the message is for its HOST, put the message on the output queue for transmission to the HOST. Otherwise, look-up the destination line in the Route Control Table and put the message on the output queue for that line. If there is no buffer available when a message arrives, the message is lost. After a message has been sent off (to another IMP), the IMP cannot reclaim the message buffer until an acknowledgement has been received from the IMP at the other end of the line. If no acknowledgment has been received for TIMEOUT seconds, the IMP should retransmit the message. The IMPs' processing time to allocate buffers, etc., is assumed to be zero. NOTE: Since some messages get delayed in the network due to line loss and re-transmission delays, messages may arrive for an IMP's HOST out of sequence order. An IMP must deliver messages to its HOST in correct sequence order. (This implies that the destination HOST never receives the same message twice.) . THE PROBLEM specified here the order and the timing by which the IMP sends messages. Part of your design problem is to work out a scheme that avoids excessive delay. Be sure to explain your We have not scheme in the documentation. You are to build a simulator & simulate the performance of a sample network (see below) from time zero until a simulated time DEADLINE. At time zero, all buffers and queues are empty. Each HOST'S first message will be to a destination and will occur at time T. for that HOST. 1. Assume that HOSTs and IMPs have an infinite buffer pool. * I Print out a distribution (histogram) and averages for each of the following quantities: 1. average number of occupied buffers per IMP per unit time. (Lump together the. statistics for all IMPs, since each will have the same distribution in the network considered) 2. average number of occupied HOST buffers per unit time. (Again, lump together the statistics for each HOST.) 3. delay time for messages between each class of HOST-HOST pairs. (In the sample data set, there are just three such classes.) Lump together all statistics within a given class. You should calculate delay time from when the message is created in the source HOST to when transfer into the destination HOST is complete. . Print out these statistics at every REPORTINGJNTERVAL of simulated time. Clear out the accumulated totals so that each interval has fresh statistics. 2. Same question assuming that each IMP has only IMPSPACE buffers available and every HOST has only HOSTSPACE buffers available. 3. Document your program. In items. particular, describe and explain your implementation of the following a. representation of HOSTs and IMPs b. handling of time in the simulation c. data structures used in the program d. IMP buffer allocation schemes 4. Have you thought about what you have done? Explain how you would redesign these network and your implementation of the simulation to overcome peculiarities and difficulties you observed in this problem. Did the test data set fully expose the capabilities and pathologies of your algorithms network algorithms? Programs will be graded according to the following criteria: a. Functionality. Are the results correct? b. Clarity. Is the program and documentation clear? Is the program easy to modify? c. Appropriateness of data structures. t Partial credit will be given for incomplete solutions, but be sure done, and indicate how you would do the rest. « to document fully what you have » TEST DATA: Run your program for the following data HOSTRATE: =IBB kb SHORTBITS := 128 LINERATE:=SB kb HtAUHHBITS := 9G SHORTPROB := .35 TI MEOUT: = .05 sec OEADLINE:=2 sec L0SSPR0B:=.8881 per bit LONGBITS := 1088 SAHEPROB := 8.75 HOSTSPACE : =I =I B TLAHBDA: -.886 sec ItIPSPACE:- 25 HIPSPACE:= REPORTING_INTERVAL=B.S sec LIST OF CONNECTIONS 2 3 5 3 G 4 5 G G 1 1 1 2 2 3 4 4 5 Route control table Ron Classes of A = I 1«2, B = I 1-5, C = I 1»4. 4 pairs 1 2 3 4 5 G x 2 3 3 B 2 1 x 3 3 1 G 1 2 x 4 1 2 5 G 3 x 5 G 1 6 4 4 x G S 2 4 4 5 x 2«3, 3-1, 4«5, 5«6, 6«4 I 2«6, 3«4 1 1«G, 2»4, 2*5, 3*5, 3»G 1 ANSWERS SPRING 1975 COMPREHENSIVE EXAM SYSTEMS 1. Deadlock No - A deadlock can only occur if all the tape units are reserved and processes are waiting indefinitely for resources which will never be If all four tape units are reserved, then one of the available. processes has all the tape units it needs and Its two units will become available when it finishes. (Partial credit was given to persons who interpreted the problem as allowing deadlock to specific tapes (not tape units) or other resources if their answer indicated clearly that they understood deadlock.) 2. LISP 1. In ALGOL, variable bindings are static and semantical ly determined at compile time from the block structure and scope rules. In LISP, bindings are dynamic and depend on the order that routines are called. A LISP variable is bound to its most recent definition on a value stack. 2. Try to place the new cell on the same page as the old structure CAR). (either the CDR or the This is to alleviate paging during traversal of the data structures and implies that a free storage list should be associated with each page. 3. Paging Concepts 1 . a. (* indicates a page fault) FIFO with 3 frames. A-B-C-D-A-B-E-A-B-C-D-E JL JL JL JL J- 9 faults J- FI FO with 4 frames A-B-C-D-A-B-E-A-B-C-D-E JL b. JL JL JL LRU with JL JL JL JL JL JL JL JL JL JL JL J*;. JL -L ABCDABEABCDE ABCDABEABCD ABCDABEABC * (FIFO Anomaly) frames (List shown) 3 A-B-C-D-A-B-E-A-B-C-D-E JL 10 faults 10 faults Page 2 LRU with 4 frames 8 faults A-B-C-D-A-B-E-A-B-C-D-E JL. JL JL J- JL JL JL JL JL JL JL ABCDABEABCDE ABCDABEABCD ABCDABEABC ABCDDDEAB 2. Associate a reference bit with each page which is set with each reference and which Is cleared later by a pointer advance. When it to select a page for removal, a pointer advances in a is time circular list of pages and selects the first page whose reference bit is clear. (while clearing and skipping those set). Another scheme (which is only available on a single machine) is to associate an aging register with each page.. The register is set to a maximum value at each reference and is decremented by an interval timer. removal 3. . At a fault, the page with the lowest counter is selected for - e.g. On a system where there are many commonly used programs compilers and editors it is useful to reduce paging by having users - share the common pages. Such sharing reduces both the overhead of moving code to and from the drums and the required amount of drum Sharing data pages between programs can be much more efficient than other methods of transferring data from producers to storage. consumers. 4 Compi ler Quickies 1. The idea is to reduce the storage required for the precedence matrix. storing only the Three methods are (l) sparse matrix techniques - non-blank relations (2) precedence functions (if they exist) (3) pointers to identical rows or columns. 2. Most compilers use a simpler technique for the scanner than for the context-free parser. Some compilers use top down methods for good ri error recovery but switch to operator precedence on expressions to avoid backup. In FORTRAN, a special parser might be used for FORMAT statements. 3. No. From the matrix we conclude that g(s-) = f(s.)>g(s ) = f(s )>g(s ) 2 1 2 which is unsat isf iable in precedence functions. * 4. Typed languages - Page 3 e.g. ALGOL, SAIL, FORTRAN, PASCAL, SIMULA Advantages 1) Many more errors detectable at compile time 2) Compiler knows more about what a program is doing and can perform optimizations. 3) System provides type conversion automatically. Disadvantages 1) Less flexible language. 2) Compiler harder Typeless languages to - e.g. write BCPL, LISP, APL, EULER, GEDANKEN Advantages l) More flexibility possible in programming resulting sometimes in greater efficiency. 2) Compiler easier due to the uniform treatment of addresses Disadvantages 1) Harder to debug. Remarks: Some bugs result in subtle smashing of code or data LISP has untyped variables, but typed values. In languages like PASCAL where there are user defined data types, it is possible to do more representation independent programming. 4 Process Synchronization The Test-and-Set instruction provides a primitive way for a process to check a flag before proceeding. A process l) waits for a flag to be clear, 2) sets the flag, 3) enters its critical region and clears the flag when it is done. The Test-and-Set instruction guarantees mutual exclusion between processes checking and setting the flag since it cannot be interrupted during execution. The disadvantage is that this technique is a form of busy waiting. A better primitive method is semaphores (Dijkstra) which allows processes, to be queued while they are waiting and restarted when the shared resource (e.g. critical region) becomes available to them. basic operations to the program are P (wait) and V (signal). to be protected is bracketed as in a. wait(s) [code s ignal (s) The The code Page HARDWARE f F W) Two o(- ihe fbssVble arvsv.ot.ri ar^ sV.;_.wy\ 4 Page 5 2. J-K Flip Flop 3_. 4-Bit Synchronous Binary Counter « Page 6 4 Architecture Concepts a. Multiprocessing means that there are several processors capable of operating simultaneously on a system. For example, swapping drums and other I/O devices usually have their own processors which run fairly independently of the cpu. Some systems may even have several cpu's. b. Memory interleaving means that successive addresses refer to words which are physically located in different memory banks. Since reading a word from memory is usually destructive, there is usually a delay time for that bank during which local hardware restores the contents of "the word. The effect of this delay can be minimized if the next word fetched is from a different bank. Another use for interleaving arises on memories having multiple say for the cpu and swapping drum. Usually the I/O ports ports have higher priority. If memory was not interleaved, a drum could effectively lock the cpu (or some other device) out of a bank of - memory altogether during a rapid block transfer. diminishes this c. Interleaving "interference". Wide buses permit the parallel transfer of more information at the If each access to memory fetches two words at once, the memory bandwidth is potentially doubled and a cpu may need only about half as many bus cycles to carry out the instructions. "Associative" memory means memory addressed by part of its content. This is used to speed up the search for an entry in a table based on same time. d. the parallel operation of the hardware which carries out the association. It is often used to speed up the vi rtual -to-physical address translation or in implementing a cache memory. * Page 7 THEORY OF COMPUTATION 1 . Diagonal ization a. Assume that there Is an effective listing JT , T , T , . . Y\ of total recursive functions and that T.(j) denotes the result of applying ' th function in the list. Let us define a new total function F as follows: F(x) = T (x) + 1 for all x. Clearly F is total since each T. is total, and it is recursive since argument jto the i T. (j) can be computed — given i and j . Furthermore F is not in the list because it differs at argument i for each T. in the list, i Therefore the list is not complete. Since this contradiction appears with any complete listing of the total recursive functions, there can be no such l isti ng. b. Every context sensitive language is recursive. If every recursive language were context sensitive we would have a contradiction ;of part (a) C_, be an effective listing of all the Alternatively, letlc,. C , .Y\ fixed (countable) alphabet^. could be an appropriate ordering of the sets of productions.) context sensitive grammars, over a (This Let us define the set S as | a' l L(C.) where a is some letter in _T S= a 1 is not in . j S is recursive because L(Cr) is recursive. But S is not context sensitive since it is generated by no context sensitive grammar (that is, S differs in at least one word from each L(C.)). Hence S is a recursive set sensitive. 2. Finite Automata a. {D>* {.}{o} *{x} s. * over £ which is not context Page 8 d. This finite machine of part (a) is essentially that part of a scanner which recognizes the numeric constant and variable tokens in a language. Final state 7 corresponds to an integer constant, state 6 corresponds to a floating point constant (including the which is only a decimal point!), and state 4 corresponds to a variable name. Of course, real compilers have somewhat more complicated scanners which allow only finite length tokens, etc. The "reversal" part might be used if the source is (for some reason) to be read backwards. Also scanners use equivalent strange one determi n i st ie \mach \ nes * . Page 9 3. Context-free Language Quickies 1. The language contains no strings of even length. Proof: be a shortest string of even length that can be parsed as B , SBc S . AaS , or , Then or cA has one of the forms , where the A aSA strings which are shorter than oC , 2. (In fact, all for some k> 0 .) S B string has length 3 -> SBc The shortest production A , hence c , Abß , , hence have odd length. is a contradiction. 4k+l B A b , S denote parsable a , e<, Let This strings are of length , and c occurs only in the can appear in the middle if and only if the string has a parse tree S Abß SBc a The only four solutions are by * aab or baa . aßcbß where each B is replaced Page 10 ALGORITHMS AND DATA STRUCTURES 1. ALGOL 60 Problem procedure RK cc Beginning of program: i°> loop 7 RKlST(x,y,H,x2,y2) ; RKLST(x2,y2,H,xS,y3) . check stepsize: for k := 1 step 1 until n do if comp (yl[k].y3[k], eta) > eps then begin 6 c go to check stepsize end; x x := 3; while not out c repeat ; 11 end RK can't be eliminated without introducing extra computation. But it isn't such a harmful one, and one would expect an example at the end of a language definition to illustrate most of the The remaining go to features of that language. . 4 Page 11 2. Tree Traversal (F) A (B) C (G) where (F) = FLM (B) = (J) B (D) EX (G) = G (N) 0 (J) = JRT (D) = PDHIQ (N) = NSU So it comes toFLMAJRTB P D HIQEKCGNSUO 3.. Sparse Matrix f i ,j 2) a. A sequential list containing entries (i, j, A nonzero A [j ,jj b. An "orthogonal list" arrangement like that in Knuth Section 2.2.6 Same as b or (for example) a hash table of size M C750 which c. . A^i.jl finds d. given the key <i,j>. IF the hash function has the form (a? + bj) mod M, it will be possible to perform operations (iii) and (iv) without too much delay. 10000 consecutive cells with A Ci,j7 in location L + 100 i + j for some L o o « . * for . Page 12 Wume r i cal Analysis 1 . Banded Linear Systems 1) ( a ) (b) If partial pivoting is not used the band width will not be increased Partial pivoting could increase the band width from 4m + (c) . 2m+l to significantly increasing the 1 (c) Additionally. number of arithmetic operations. (d) storage requirement and the logic must be introduced to carry out the searches for pivots which increases the complexity of the code and adds to the machine time required. 2. Arithmetic and error analysis a. Floating point and real arithmetic do not have the same arithmetic For example, the floating point number system is not properties. associative with respect to + . To see this consider two digit In this case base 10 arithmetic. f 1 (10 + fl (-10 + 0.1 )) - 0 but fl (fl (10 b. - 10) +0.1) = 0 Forward error analysis must be carried out in floating point arithmetic which as shown above in associative. 2)a. is, among other things, not This is extremely involved if anything useful can be obtained at all. Inverse error analysis can be carried out in real arithmetic and is therefore much easier. produces simpler It also usually /bounds which are easier to work with and consequently of more utility. 3. The rank problem a. If we use the I norm, II xII ._, I . .max I<i<n x. and the induced matrix norm we find that where A m 1 I ,x ~ ), = (x.,...,x 1 n" cond (A) > n ~2 2 is the matrix on the left hand side of the equality. Page 3. a (cont. ) If we let x = (1, bb ">> A -1 b =x 2 , 22_n) ' and 2 "n ■ b = (0,0, 13 . .. ,0,2 2_n ) ' we obtain which yields ||A- I ||2 - 2 n = and lIAII. - -1 IIA Since ||*IL >|| AT\\\ m - ||x„m 1 iiaAi_> 00 1 so cond (A) n Thus for large b !!. det (A) - HAIIJIA" !^ 1 this matrix, n-2 > 2 A, is quite ill conditioned. ( = 1 , Ais clearly nonsingular and the diagonal elements are certainly not small. This example shows that "nearly singular" for large then very large. n A is since its condition number is Methods based upon Guassian elimination to deter- mine rank must rely upon the size of the diagonal elements, once transformed to upper diagonal form, to determine rank. r rows have diagonals which are "essentially zero" that the rank was n-r . If the lower we would conclude Our example shows that there are nearly singular matrices, or matrices which are only a small perturbation from being singular which have large diagonal elements. Therefore, this approach will not be suitable for floating point computation. « Page 14 k. Newton's Method The iteration will clearly not converge and from the picture it is reasonable to conclude that = X n X n+2 = = x = "*' n+2m and x n+l " X n+3 X n+2m+l p(x) Let " X ~ n+2m+l ''' m so for all b. ~' " X n+2m =Sn xn + £ I= I a.x X n+l , 1 "Xnl>" * > ° - , p(r) =o,£r= r r o<i<n-1 Then £>(*") n = A a -? n * p( r ) and via Taylor expansion we obtain, to terms p(r) M p(r) + Ar-p'(r) . Consequently, n -Aan mr and to terms or « , = -A a *(r + n &&m) n » Ar«p'(r) &(^r + Ar 'A an ) *r «A r 'P( r ) -A an n n-1 a r w - V _V_. &r A£ pTr) " r ~- Aa -Ail an 2 &(^r ), A an -a^ Page 15 . . 4 ( cont ) c. i- 1, 2, ...,10 For P (x i ) Herman has observed that P( X i-1 m 1 } 2 p'Ui) so X i+l x.i I " X i| - x.,i-1 1 2 and the convergence is linear for these iterations. This may have occurred because: i) the Iterates are not close enough to the root, or ii) the _ "* x. are converging to a multiple root. Page 16 ARTIFICIAL INTELLIGENCE 1. Understanding Systems (The following is an example of an acceptable answer. ) "English Language Understanding" A program which '^understands English must have some way of representing the meaning of sentences. This meaning needs to be incorporated into the program's mod e l of the world. For example, In- Winograd' s SHRDLU a model of the "blocks world" is kept and updated by In Colby's PARRY, the variables of the program model the the program. emotions of the paranoid. In Shank's work, a semantic net carries the meaning in a data structure. The importance of the model derives in part from the necessity of the program to " r eason" about its world. For example SHRDLU knows about the transitivity of "on top of" and also knows what it has done. The MYCIN program knows "why" it made each step of a diagnosis. The In models in these cases include the prior activities of the program. general A.I. developments, reasoning has been based on theorem proving with new techniques involving the Resolution Principle. Older general techniques include "means-ends analysis" of GPS. Today's more successful programs use more domain specific techniques. SHRDLU 'reasons' about its model using the goal directed computations of /"--PLANNER. In a sense, it knows "what follows from what" although it does not solve theorems in general. Like several of the new A.I. languages, A-PLANNER does the book keeping of back tracking. This tool lets a program gracefully abandon a fruitless subgoal. Sometimes there are several sources of knowledge for a program to draw upon or there is knowledge to be used only in particular contexts. The first case is called the "multiple expert" problem and is exemplified by the HEARSAY program. The program subjugates the various experts of an English-speaking chess playing program (sound expert, syntax expert, chess expert, ...) to a MASTER which arbitrates between them. The second case is handled by a new software concept - the pattern-directed (or pre-conditioned) interrupt known as a demon. M If Page 17 the entire calculation is driven by patterns of the form <pre-condi tion>-?<action> , then the system is termed a "production system". These various concepts can be viewed either as fancy developments in program organization, or as variations on the procedural representation of knowledge. In summary, English understanding is a rich enough area to require and impact all the major areas of A.I. research, Including heuristic search, knowledge representation, and new program organizations. 2 ERTS The main A.I. problem for the design of the satellite's "understanding" program is to determine specifically what objects are to be specifically what description will be used for the recognized: object-finding; and specifically how the "finding" process will exploit the description. Thus, the satellite has to be able to recognize specific objects such as rivers, river bends, deltas, mountains, islands, etc., which it will report about; and effective computational models of these (descriptions based on world knowledge) constructed. 3 A. I 1. . Concepts Heuristic Search. For any task regarded as nontrivial, the search space is very large. Rules and procedures called heuristics are applied to steer or limit the search. Often the heuristic rules are greatly task specific. Heuristic search is useful when no formal search method exists (or is feasibly applied) or when informal knowledge, i.e. heuristics, exist for pruning of and steering the search space. 2. Means-Ends Analysis is a problem solving method applicable where a goal state (G) is explicitly defined, an initial state (l) is explicitly given, a set of operators is available to perform state change, and a goal state can be achieved by incremental progress. The method is to iteratively select an operator to transform the current state into an intermediate state I' which is closer to G. * The process stops when I ' = G. Page 3. 18 - Hill Climbing is a technique for exploring for the optima of a function E of n variables. The technique generally cannot distinguish between local and global optima the "hiJls" of the surface in n+l dimensions. The technique is useful as a performance improvement method for the best performance setting of n variables where E is the performance evaluation function. Unfortunately, "best" is - sometimes a molehill compared to nearby mountains. 4. Demons - a conditional interrupt which operates autonomously in a program. It activates whenever the "condition" occurs in the program. This conditional expression may be simple or a complicated pattern matching expression. "Demons" are useful for representing a process which can be conveniently conceptualized in terms of a few independent pattern-invoked actions or subprocesses in addition to the main computation. 5. Production Systems - are a way of representing a program in terms <s i tuation, action> pairs which are called productions. The basic idea is that the action (subprocess or event) takes place when the situation (pattern matching conditional expression) becomes true. A more precise flow control (arbitration between competing actions) is handled differently on different systems. This technique of of programming Is useful for representing processes which consist of many independent pattern-invoked subprocesses. The technique is useful in a system where easy experimentation ?n terms of the order of operations is required or where it is desired to add new subprocesses (e.g. processing knowledge) without revising large portions of the system. 3 A.! 1 Quickies True - each application of an operator can be viewed as the reduction of the problem to a simpler subproblem. The special case of state space methods remains useful as a separate concept from problem reduction because (l) some problems are more easily conceptualized as "moves in a state space" than as "problem reduction steps"; (2) sometimes simpler algorithms apply. (Prof. Knuth has remarked that he has some especially efficient algorithms which apply in this case. ._■ He cites a strong analogy between "state-space approach" <—>"f i ni te Page 19 state languages" and "problem reduction approach"**-*"context-free languages". - - research paper in progress) the alpha-beta technique always achieves exactly the same result as minimax. 2 False 3 Detailed knowledge of task domains has been found to be useful and necessary for high levels of performance. Attention has turned to acquiring and utilizing such detailed knowledge for specific problem domains. These particulars seem necessary to achieve significant search reduction. In addition, general problem solving methods have tended to force awkward, non-natural representations of problems and domain-dependent knowledge. *