34SampleQuestions

advertisement

The School of Computer Science

Fundamentals: Data Structures & Algorithms

Sample Questions

(Outline solutions to the following will be provided when these questions are discussed in Revision Tutorials)

Question 1 a)

Define the term’s data, data type, information and knowledge. b) Describe what you understand by abstraction, levels of abstraction and representation. c) Give two levels of abstraction for the following: i) a railway station ii) a library of research journals iii) spectators at a hockey match iv) B. Sc. Honours Degree in Computer Science d) Describe two features necessary in a programming language to support an abstract data type.

Question 2 a) Define the term’s data , data type, data instance , data component and an abstract data type . b) Using your understanding of the four basic abstract data types – sets, list, trees and graphs – suggest and briefly justify an abstract data type for each of the following: i) a box containing an assortment of screws ii) the four hands dealt in a game of bridge iii) your weekly itemised food purchases during 2000 iv) a multi-storey car park v) the architectural plans for a two storey detached house c) describe briefly why the implementation of abstract data types can be much more complex than their representation.

Question 3

Write notes on the following: a) the fundamental abstract data types: sets , lists , trees and graphs b) and abstract data type and a class in the Java programming language c) sequential access and direct access to: i) a set data type ii) a list data type

Question 4 a) Give a specification for the abstract data type known as a stack b) A stack may be represented and implemented using a sequential list or a linked list of stack elements. Describe these alternative methods and comment on the relative merits of these two representations. c) Outline briefly how a stack data type is used the evaluate an expression such as:

(a + b) * c + d d) Give one other use for a stack.

Question 5 a) Give a specification for the abstract data type known as a Set.

b) A Hash table with internal chaining is one way of implementing a set data type. Using a notation of your choice, outline an algorithm for inserting set members into such a table. Define carefully your notation and method of chaining. c) An operation for retrieving an element from a Hash table is also required. Could you use the algorithm outlined in b) above?

Give reasons for your answer. d) Suppose your Hashing function in the above calculates the Hash table position using the left most character in the element keyword and its integer position in the alphabet, i.e. A codes as 1,

B codes as 2 . . . and Z as 26. Construct a diagram showing the resulting Hash table after entering the following keywords using your algorithm described in b) above:

SOFTWARE, SCIENCE, SKIP, SEQUENTIAL, STOP,

SEARCH, STANDARD. e) What type of retrieval process would result if any of these keywords listed in d) above were used in your retrieve operation in c) above? How could the efficiency of retrieval be improved?

Question 6 a) Define the abstract data types a linearly ordered sequential list and a binary search tree and describe how these two data types are related. b) Construct a binary search tree from the following strict sequence of words:

Integer, real, char, structure, boolean, begin, procedure, if, then, link, else, for, do, string

c) Redraw the tree showing it’s structure after: i) deleting the node word ‘string’ ii) deleting the node word ‘char’ d) From your constructions outline an algorithm to delete any specified node from a binary search tree.

Question 7 a) Construct and draw a binary search tree (BST) from the following strict sequence of integers:

8, 4, 12, 16, 18, 9, 14 b) State, giving clearly your reasons, whether the binary search tree you have constructed in a) above is a height balanced (AVL) tree. c) Compute the average access to any node in the BST assuming each node is equally likely to be requested for retrieval. d) Describe how the integers 18 and 25 are inserted into the following AVL tree:

20

16 24

15 17

Draw the tree after inserting 18 and after inserting 25. e) state one advantage and one disadvantage of AVL trees.

Question 8 a) Define the abstract data types binary tree and B-tree . b) Describe how a binary tree may be converted into a B-tree indicating the saving in access that would be realised in the conversion of a large binary tree to a B-tree. c) Describe, with the use of diagrams, how a binary tree and a Btree or order 2 may be grown from the following sequence:

20, 40, 10, 30, 15; 35, 7, 26, 18, 22, 5;

42, 13, 46, 27, 8, 32; 38, 24, 45, 25;

Draw a tree diagram whenever a semi-colon occurs in the above sequence. d) What conclusions can you draw about the subsequent updating and searching of the two final trees you have drawn in c) above.

Question 9 a) Below is shown a digraph with four nodes:

2 1

3 4 i) Determine the adjacency matrix for the above digraph. ii) Give the adjacency list of the above digraph and state the ADT used in your description. iii) State one advantage and one disadvantage of each method of representation in i) and ii) above. b) The traversal of the graph below produces the sequence:

A B D E C H F G

A

B C

H

D G

E F i) State what method of graph traversal was used to produce the above stated sequence. Justify your answer. iii) State, with reasons, what ADT is required for a nonrecursive algorithm for the traversal used in i) above.

Question 10 a) Give a specification for the abstract data type graph with particular reference to the operations of traversing and path enumeration in such data types. b) An adjacency and path matrix are ways of representing properties of a digraph. Define these matrices and show how they are related to each other. c) An adjacency list is another way of representing a digraph.

Describe such a data type and draw a diagram to represent the adjacency list for the digraph shown in Question 9.

Past Exam Papers On-line: www.exampapers.bham.ac.uk

Download