Tutorial Two
- In the context of OOP, explain the concept of inheritance. Use
examples.[4]
- In the context of OOP, explain the concept of polymorphism and
virtual functions/dynamic binding. Use examples [8]
- What is the primary benefit of polymorphism ? [2]
- In terms of efficiency, list one possible disadvantage of polymorphism.
[2]
- Write skeletal declarations for the classes Human, Student, Lecturer
and Freak, where Human is the base class for Student and Lecturer. Freak
must be derived from both Student and Lecturer. The classes must contain
no members and all derived members must have the same attributes as in
the base class. [6]
- Explain the effect of the protection attributes public, private
and protected when interspersed with members in a class declaration.
[6]
- Discuss the concept of operator overloading. [4]
- Assume that Vector is a class which stores data in the form of an array
(Storage). Write the declaration and definition for the overloading of
the addition operator so that two Vectors can be added using the standard
notation, with the standard meaning for vectors. [4]
- In the same framework as the previous question, overload the multiplication
operator so that it permits multiplication of a vector by a standard integer.
[4]
- What are friend functions and friend classes ? [4]
- If two classes are heavily integrated, they can be declared as friends
of each other to allow access to private data. However, in order not to
generalise too much, this is usually not done; instead individual functions
are declared as friends. Assume that two classes Vector and Matrix are
declared consecutively in a program, with each containing operator overloading
functions using the other as a parameter. What problems can be expected
? How can we overcome these problems, other than declaring the entire class
as a friend ? [8]
- List 3 restrictions on the scope of operator overloading ? [6]
- What is a copy constructor ? Why happens if a copy constructor
is not used ? Give examples where not including a copy constructor is valid
and where it is not. [8]
- Write a copy constructor for a Vector class which stores a standard
vector in the array Storage. [4]
- Declare Element as a node in a binary tree, containing a single integer
value and the relevant additional data members. Do not include function
members. [3]
- Write the recursive code to perform an inorder traversal
of a binary tree. [4]
- Write the code to perform an inorder traversal of a binary tree, using
iterative techniques. Hint: use a stack for temporary storage just
as a queue is used for breadth-wise traversal [5]
- Write the code to perform a breadth-wise traversal of a binary
tree. [6]
- Write the code to count the number of nodes in a binary tree. [4]
- By definition, what is a binary search tree ? [2]
- What is the order (in terms of comparisons of elements) of Insertion
in a BST ? Write the code to insert an element into a BST. [5]
- Write the code to search through a BST for a given element. If the
element is found, its address must be returned, otherwise the return value
should be NULL. [5]
- Using standard BST methods (search, inorder, insert, delete), write
a method to eliminate all duplicate elements from a BST. [5]
- In an array-based implementation of a tree, what are the coordinates
of a node's children and parent in terms of its current index i ? [6]
- List 2 advantages and 2 disadvantages of array-based implementations
of trees. [8]
- What is the definition of a heap (tree data structure) ? [2]
- For heaps implemented as arrays, what are the orders of insertion and
deletion ? [2]
- With reference to heaps, explain how the insertion algorithm operates.
[5]
- What is a priority queue ? [2]
- Discuss the differences in efficiency of priority queues implemented
as array-based linear lists, dynamic singly linked lists, dynamic heaps
and array-based heaps. [8]
- What is an AVL tree ? Draw a small sample AVL tree, illustrating
all 3 balancing scenarios for nodes. [5]
- In general, how is the AVL condition restored after the insertion of
an element into the tree ? Draw sample trees before and after single rotation
to illustrate the technique. [6]
- What is the difference between hashing, a hash value and a hash function
? [6]
- Discuss the operation of a hash table (insertion and search),
assuming no collisions ? [6]
- Discuss the two popular collision-resolution techniques employed in
hash tables. [8]
- Hash tables incorporating linked lists can be improved upon. How ?
[2]
- Assuming the existance of a perfect hash function for n elements, what
is the best and worst case efficiency of the search operation applied to
a hash table. Give an example hash function that produces the worst case
scenario. [4]
- List one advantage and one disadvantage of a dictionary implemented
as an n-ary tree. [4]