Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Final Examination 1998 Computer Science 1, Data and Data Structures Computer Science 1, 1998 COMSA13, COMS100B Data and Data Structures, Final Examination Department of Computer Science University of the Witwatersrand, Johannesburg Instructions You may bring into the examination room one A4 sheet of self-prepared notes and refer to it while answering the questions on this examination. Otherwise, this is a closed book examination. No calculator of any type may be used. Answer all questions. You have a maximum time of 90 minutes (1.5 hours) to complete the examination. The 24 numbered questions are weighted equally. Fill in your name, student number, etc. on the special mark sense card and follow all instructions on the card. Encode your student number and mark your answers to all multiple choice questions on that card. Read each question completely and carefully before answering it. Most of the questions below are of the multiple choice type. Select the best answer to each among the choices offered. If more than one answer applies, select that one which is the best or the most comprehensive or which best expresses the most important and essential aspects of the issue in question. Please note that the guessing factor will be applied to all multiple choice questions. That is, for each correct answer you will receive full credit. For each incorrect answer, 1/4 credit will be subtracted from your score. If you do not answer a question, 0 will be counted for that question. This examination consists of two parts. Mark your answers to the multiple choice questions on the mark sense cards provided. Answer the remaining, non-multiple choice questions in the answer book provided. Multiple choice part Mark your answers to the following questions on the mark sense card. 1. Viewed abstractly, data consists of: symbols and sequences of symbols. values and associations between values. algorithms for manipulating data. simple variables, arrays, linked lists and trees. numbers and sequences of symbols (e.g. letters, special characters, etc.). 2. Data values can be associated with one another by physical adjacency. explicit pointers. an underlying association between array index values referring to the data values in question. an implicit connection external to an information system, e.g. in the minds of the system’s designers, users, etc. all of the above. page 1 of 8 Final Examination 1998 Computer Science 1, Data and Data Structures 3. Which of the following statements best describes the various number systems used in the course of human history to date? All were positional systems like our current one. Some important earlier systems were non-positional and others were mixed (e.g. using a non-positional scheme up to a certain value and positional representation for larger values), but now they have been largely replaced by our decimal positional notation. Many number systems have been used, but the only number system which ever became important is our current decimal positional number system. Originally non-positional systems were used, but they were replaced by our current positional system in one step. All number systems were basically unsystematic until the current decimal positional number system was introduced. 4. The sequence of symbols “B3.8” viewed as a hexadecimal number (radix = 16) is, when converted to decimal, 113.8 83.5 179.64 179.5 none of the above. 5. The meaning or interpretation of data represented in a computer system is inherent in and implied by the representation. is external to the system and is typically based on various assumptions and conventions. must be explicitly documented within any program manipulating the data. follows from the data types used to represent the data. follows from the data structures in which the data collection is stored. 6. You have been given a program to review and, if necessary, correct. The program, which was written by a colleague who is no longer with your company, performs the following decimal additions with the following results: 1234567 12345678 7654321 7654321 8888888 20000000 Clearly, the first result is correct and the second result differs from the correct sum by 1. Which of the following conclusions can be correctly drawn from these two test cases? The above results give no indication of what kind of an error to look for first. The deviation of 1 from the correct answer could be caused by loss of accuracy when performing floating point arithmetic. Because the numbers above are all integers, the observed deviation could only be caused by exceeding the declared range when performing integer arithmetic (overflow). This deviation cannot be explained by either B or C above. Therefore, the deviation must be caused by a programming mistake. It is impossible for correctly functioning computer hardware to give the above results. Therefore, the hardware must be faulty. 7. The (negative) decimal number –30, when represented in two’s complement form with 8 bits (one byte), is 11100010 11100001 page 2 of 8 Final Examination 1998 Computer Science 1, Data and Data Structures 00011110 00100010 10011110 8. A designer is considering whether to implement a stack with (1) a one-dimensional array, (2) a two-dimensional array, (3) a circular array, (4) a linear linked list or (5) a heap. Which of the following statements apply to this design task? Any of these five possibilities is a reasonable way to implement a stack. Any of the arrays or a linear linked list is a reasonable way to implement a stack, but a heap is not. Neither a heap nor a circular array is a suitable way to implement a stack, but the other possibilities above are. Of the above possibilities, only the one-dimensional array and the linear linked list are appropriate ways of implementing a stack. None of the above statements (A-D) is correct. 9. Consider an implementation of a pipeline as a circular array named “p”. The array is declared with index values ranging from 0 to N–1 inclusive, where N is some sufficiently large integer. The value of the variable “out” is the index of the oldest data value in the pipeline and the value of the variable “in” is the index of the array element into which the next data value is to be “put”. The operation represents addition modulo N. The operation represents subtraction modulo N, i.e. ((xy)y)=x for all x and y. The pipeline is empty when out=in. Which of the following conditions is the best data invariant for this pipeline, i.e. best describes the state of the pipeline at all times before and after putting an item into the pipeline and getting an item from it? the pipeline contains the sequence of values [p(out), p(out1), ... p(in1)] outin and the pipeline contains the sequence of values [p(out), p(out1), ... p(in1)] or out=in and the pipeline is empty (outin and the pipeline contains the sequence of values [p(out), p(out1), ... p(in1)] or out=in and the pipeline is empty) and out in the pipeline contains the sequence of values [p(out), p(out1), ... p(in1)] and out in (outin and the pipeline contains the sequence of values [p(out), p(out1), ... p(in1)] or out=in and the pipeline is empty) and in1 out page 3 of 8 Final Examination 1998 Computer Science 1, Data and Data Structures 10. Consider an implementation of a pipeline as a circular array as in question 9 above. Which of the following algorithms will put the value of the variable “newval” into the pipeline? valretrieved := p(out); out := out + 1 newval := p(in); in := in 1 in := in 1; p(in) := newval p(in) := newval; in := in 1 none of the above. 11. Consider a circular array implementation of a pipeline. The time required to get one item from a pipeline containing n items is proportional to log2(n). is proportional to n. is proportional to n*log2(n). is proportional to n2. does not vary with n. 12. What type of tree is the following? (Be as specific as possible.) desk 2 top pedestal 1 2 3 pedestal frame 1 foot 1 trough drawer 1 1 back panel a tree (a general tree, no specific type). a binary tree. a binary search tree. a heap. a 3-tree. page 4 of 8 front panel Final Examination 1998 Computer Science 1, Data and Data Structures 13. The number in each node in the tree below is the data value of that node. What type of tree is the following? (Be as specific as possible.) 13 6 17 3 1 8 4 7 22 10 20 25 a tree (a general tree, no specific type). a binary tree. a binary search tree. a heap. a 3-tree. 14. The number in each node in the tree below is the data value of that node. What type of tree is the following? (Be as specific as possible.) 1 3 28 8 9 5 15 6 30 15 a tree (a general tree, no specific type). a binary tree. a binary search tree. a heap. a 3-tree. page 5 of 8 45 66 Final Examination 1998 Computer Science 1, Data and Data Structures 15. A binary tree contains n data items (and therefore n nodes). The height of the tree (measured in number of edges, not nodes) is h. Which of the following gives the strongest upper and lower bounds on h? log2(n+1)–1 h n–1 log2(n)–1 log2(n+1) h n–1 log2(n+1)–1 log2(n) h n h n–1 h n 16. A heap contains n data items (nodes). The time required to search the heap for a given value is, in the worst case, proportional to log2(n). proportional to n. proportional to n*log2(n). proportional to n2. constant (independent of n). 17. A binary search tree contains n data items (nodes) and is as balanced as possible. The time required to search this binary search tree for a given value is, in the worst case, proportional to log2(n). proportional to n. proportional to n*log2(n). proportional to n2. constant (independent of n). 18. Although pointer values can be considered to be integers and are often implemented as integers, many programming languages provide a way of declaring them as special pointer types specific to the type of variable or record to which they point. There are several reasons for providing these features. Which of the following is not such a reason? Performing arithmetic operations on pointer values is not meaningful, so such operations should be prevented. Using a pointer value generated for one type of record or variable to refer to a different type of record is normally incorrect and should be prevented. Specific pointer values are meaningful only to the programming language system which generated them; they are not meaningful at the application program level. The application program should, therefore, be prevented from using pointer values for any purpose other than referring to the corresponding data items. It is much easier to write program statements involving pointers when they have been declared as such rather than as integers. The range of values associated with a pointer variable can be assigned automatically by the programming language system; the programmer need not concern him/herself with this system-technical question. page 6 of 8 Final Examination 1998 Computer Science 1, Data and Data Structures 19. Which of the following statements regarding dynamic allocation of data items (variables, records, etc.) is not true? Memory is reserved for dynamically allocated data items only if and when needed during the actual execution of a program. Memory occupied by data items that are no longer needed can, during the execution of a program, be released for other uses later. Data items identified and referenced by pointers are frequently allocated dynamically and, the other way around, dynamically allocated data items are typically identified and referenced by pointers. The two concepts of dynamic allocation and pointers are fundamentally associated with one another and inseparable; it is impossible to use either one without the other. Dynamic allocation of data items permits memory to be used more flexibly and effectively, but often at the expense of a longer execution time. This is the end of the multiple choice part of this examination. Continue to the next part. page 7 of 8 Final Examination 1998 Computer Science 1, Data and Data Structures Non-multiple choice part Write your answers to the following questions in the examination book. 20. Consider the algebraic expression ((a*b)+(c/(d-e))) in infix notation. Construct 20.1. a binary tree representing this expression, 20.2. an equivalent expression in Polish prefix notation and 20.3. an equivalent expression in Polish postfix notation. 21. Consider the binary search tree below: K F P B First, a node for H is inserted and later a node for G is inserted. Draw a diagram representing the binary search tree resulting from this sequence of insertions. 22. Consider the tree in question 12 above (on page 4) representing the composition of a desk. The numbers in each node are the quantities of the subsidiary components required to make one of the items named in the node, i.e. 2 feet are required to make one pedestal. Write a list showing the quantity of each end item required to manufacture 15 desks. 23. Draw diagrams representing a linear linked list before and after inserting a new element at the beginning of a non-empty list. Assume that memory for the new element has already been allocated and its data value(s) assigned, but that it has not yet been linked into the list. 24. Write the statements in the insertion algorithm for question 23 above and between each pair of statements draw a diagram representing the list and all links at that point of the execution of the insertion algorithm: (“before” diagram from question 23 above) statement 1 diagram 1 ... statement n (“after” diagram from question 23 above) End of this examination Verify that your name and student number are written on your examination book and on your mark sense card and that you have encoded your student number on the mark sense card. page 8 of 8