CS203 2017秋 期中
Data Structure and Algorithm Analysis
2017-18 Midterm Examination B
Part I. Please answer the questions (32%)
Write down a kind of structure that we can directly locate elements:
. What is the corresponding postfix expression of the infix expression
: . What is the number of non-empty substrings of the string "windows10":
. What is the basic difference between stack and queue?
is FIFO, is LIFO. Suppose there is a stack; when we push an element into the stack it prints "S", and when we pop an element it prints "X". Four integers are pushed in order 1,2,3,4. If we want the pop order 3,4,2,1, what is the corresponding sequence of operations (sequence of S and X)?
. Suppose an empty stack receives pushes
in that order. If the pop order is what is the minimum capacity of the stack? . Suppose that we use an array (capacity 6) to simulate a queue and when the index value of rear equals front, the queue is empty. Now the index values of rear and front are 4 and 2 respectively, in this case, after we add two elements into the queue, what's the index value of rear?
After that we remove one element out of the queue, what's the index value of front?
Part II. Short answer questions (28%)
II-1
A is a linear table
II-2
we know a pattern string P = "abababc" and a target string S = "abababababcaba"
II-2-1
You are asked to give the next array of the pattern string P = "abababc"
II-2-2
Please draw the matching process using KMP algorithm
Definition:
II-3
write down a class of doubly linked list and describe its process of adding and deleting an element
II-4
Given a string, you are supposed to judge if it is symmetric, For Example, given "abba", you should return 1, given "abbc" ,you should return 0.
Part III. Algorithms and programming (40%)
III-1
Given a nonnegative integer (1<=n<=10), compute n! using recursion. Examples:
III-2
Suppose we have two singly linked lists. Maybe they have some common nodes. Please design an algorithm to find their first common node.
Assume the lengths of the two linked lists are m and n ,
if your algorithm's time complexity is
if
III-3
Using the defined double stack structure as following, please implement how to calculate the result of a postfix expression.
Stack_Double
- capacity : int
- S: double[]
- top: int
+ Stack_Double(int)
+ IsEmpty() : boolean
+ push(double) : void
+ top() : double
+ pop() : doubleIII-4
Real estate developers plan to build
As we know, one of the factors that decide the house price is the distance of this house away from its neighbors: the further it is away from its neighbors, price could be higher.
They ask you for help to find the largest minimum distance. Please design and implement an algorithm which time complexity is