This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: CARLETON UNIVERSITY Final
EXAMINATION
Winter 1995 No. of Students: 90 Systems and Computer Engineering 94.302A 73 / DURATION: 3 HWRS Department Name 8. Course Number:
Course lnstructor(s) Professor T. Pearce Aurnomzlo nunonene
Closed Book, No Aids Students MUST count the number of pages in this examination question paper before beginning to
write. and report any discrepancy immediately to a proctor. This question paper has 6 pages. This eurnination question paper MAY be taken from the examination room. ANSWER ALL QUES'I‘IONS.
QUESTION 1 [12 marks}
Brieﬂy deﬁne each of the following:
a) abstraction b) data type c) 1 dynamic data structure
d) recursive procedure e) sorted tree 1‘) information hiding QUESTION 2 [16 marks] Suppose that sorted linked lists maintain integer data values in increasing order. The lists are
built using: TYPE
Typ = ANode;
Node = RECORD
Data : integer;
Next : Typ;
END; Engineering 94.302A Page 2 Write a recursive procedure with the header:
PROCEDURE Merge( VAR L1, L2 : Typ); such that the data values appearing in sorted list L2 have been merged into the sorted list Ll (i.e.
L1 now contains all of its initial values, plus all of L2's values). During the merge operation,
only the list L1 may be modiﬁed and the list L2 must remain unmodiﬁed. The merge must be
performed such that the resulting list L1 is sorted. Your procedure may call support procedures (be sure to supply the code for all of your solution),
but you must always use recursion to process the lists (NO iterative processing using loops). QUESTION 3 [20 marks] In the "good old daze" at Carleton (before the touchtone registration system), registration in
September involved filling in your registration form, getting approval from the appropriate
department (a faculty member would review and initial your form), and then paying your
registration fee in the gym. A prof in one department thought a simulation might help to gain
a better understanding of the situation. Assume the following: 1) There is one department. 2) Students arrive to register with their forms filled out. There is one faculty member assigned
to review forms. Students muSL form a single line to wait for the faculty member to review their
forms. 3) There is a Random Number/Distribution ADT similar to that used in assignment 3. The ADT's
interface includes the operation: 1 function GetRand( var Dist : Typ ) : real;
pre: Dist is a valid Random Number/Distribution variable
post: the function returns a random number satisfying the distribution Dist 4) The inter—arrival times of students at the department has a particular distribution. Assume that
the distribution is encapsulated in the variable ADdist, and ADdist has been initialized (i.e.
ADdist is a valid Random Number/Distribution variable). 5) The time needed to review and initial forms by the faculty member has a particular
distribution. Assume that the distribution is encapsulated in the variable Fdist, and Fdist has been .~ ~» %
 40
Engineering 94.302A I E E Page 3 initialized (i.e. Fdist is a valid Random Number/Distribution variable). 6) Once a registration form has been approved by the department, the student must go to the gym
to pay. Assume the travel time from the department to the gym is zero. (This assumption will
be the focus of part d). 7) In addition to the students arriving from the department, there are others students arriving at
the cashier (in the gym) from. other places. Assume that the inter—arrival time distribution of
these additional students is encapsulated in the variable AGdist, and AGdist has been initialized
(i.e. AGdist is a valid Random Number/Distribution variable). 8) Students must form a single line to pay at the single cashier in the gym. The time needed to
service each student at the cash register has a particular distribution. Assume that the distribution
is encapsulated in the variable Cdist, and Cdist has been initialized (i.e. Cdist is a valid Random
NumberlDistribution variable). Design a simulation to determine, on average, how long it takes a student who registers with the
department to complete the registration process. [2] (a) Draw a diagram of the queues and servers necessary to model the problem. Only show
those queues and servers needed to model the problem (not the simulation solution). Be sure to show all points where students arrive and depart from the system. [2] (b) List all events that you would include in your simulation and give a one sentence
description of each event in terms of the problem (not in terms of the simulation solution!). [12] (c) Give pseudocode for the processing of each event you have listed in part b. Do not
give implementation details. Be sure to brieﬂy describe all simulation variables your psedocode
references. You may assume convenient support ADT's exist, but be sure to brieﬂy describe any
operations on these ADT's that your pseudocode uses. Do not give pseudocode for initialization, the main simulation loop, or termination. [4] ((1) Brieﬂy describe how your design might change if the travel time from the department
to the gym was not assumed to be zero. Be sure to list any additional information that might be
needed to complete the modiﬁcations to the design. DO NOT actually modify your design, just
describe the major issues. Engineering 94. 302A QUESTION 4 [20 marks] A "map" can be represented as an undirected graph where the nodes are towns and the arcs are
roads joining the towns. Each road has an associated (integer) distance. Write a depth—first
search function that checks a map to see if a path exists from a source town to a destination town
such that the length of the path does not exceed a speciﬁed maximum distance. (The length of
a path is the sum of the distance of each road in the path.) The header for the function is: FUNCTION Search( VAR G: Graph.Typ; Source, Dest : Graph.Town;
Max : integer) : boolean;
where:
G is the graph to search
Source is the source town
Dest is the destination town Max is the maximum dis'rance of the desired path from Source to Dest the function returns true if and only if a path with length less than or equal to
Max has been found You may assume that in the initial call to Search, the supplied values for Source and Dest are
valid towns in graph G. You may also assume that there is at most one road joining any pair
of towns. You MUST assume that a convenient Graph unit exists. The unit hides all information about
how graphs are implemented. Do *NOT* describe how graphs are internally represented or base
your solution on a particular representation. Any access to a graph must be accomplished
through calls to the operations of the Graph unit. Be sure to briefly describe any operations that
you use in your solution. You may assume that additional convenient support modules with convenient operations exist,
but you must brieﬂy describe any operations that you use in your solution. « Suggestion: Make the Search function a shell around a recursive traversal function/prooedure. QUESTION 5 [16 marks] The syntax of programming languages are often described using grammars. One programming
language includes "constants" that can have several forms. One of the forms is the string
constant that starts and ends with single quotes that enclose a nonempty sequence of characters.
(For simplicity, assume that the characters that can appear in string constants do not include the
single quote symbol.) Another form is the integer constant that is a non—empty sequence of digits
that may be preceded by an optional single sign (+ or ). The final form is the signed identifier
that has an optional single sign (+ or —) followed by an identiﬁer. An identifier is a non—empty Engineering 94. 302A Page 5 sequence of letters and digits that must start with a letter. Some examples of valid constants are:
'abcd‘, —34, 25, Const3, Limit, +U2 Some examples of invalid constants are: 'abc missing the closing '
3r identiﬁer starts with a digit
C+3 sign can not appear in an identifier In your answers to the following, you may use:
C to represent any character that may appear in a string
L to represent any letter
D to represent any digit a) Construct a (deterministic) FSM that accepts constants. b) Give either the RE or BNF grammar for constants. QUESTION 6 [16 marks]
A "branch" of a tree is any path from the root node to a leaf. (A tree with only one node  the
root node  has one branch that starts and ends at the root.) Consider a tree in which each node has an integer data value (the tree is not necessarily sorted). The "weight" of a branch is the sum
of the data values of each node in the branch. Trees are built using: TYPE Typ = ATreeRec; TreeRec = RECORD
Data : integer;
Left, Right : Typ;
END; a) Write a recursive traversal procedure with the header: PROCEDURE MinWeight( VAR T : Typ; VAR Branches, Weight : integer); The speciﬁcations for the returned values of Branches and Weight are: IEEE Earletan , Engineering 94.302A  Page 6 Branches = the number of branches in tree T
(hint: number of branches = number of leaf nodes!) Weight = the minimum weight of any branch in tree T
if the tree is empty, then Branches = 0 and Weight can be any value (i.e. undefined) Do *NOT* make any assumptions about the initial values of Branches and Weight Do *NOT’"
use a shell to initialize these variables before calling your recursive procedure. b) Does your solution use a preorder, inorder or postorder traversal? ...
View
Full
Document
This note was uploaded on 10/15/2010 for the course SYSC 3600 taught by Professor John bryant during the Spring '08 term at Carleton CA.
 Spring '08
 John Bryant

Click to edit the document details