content="Data-structures and algorithms in Standard ML. Notes from a lecture course given by Michael Fourman at the University of West Australia, Spring 1994." /> rel="start" type="text/html" href="/mfourman/index.html" title="Michael Fourman" />

University of Western Australia
Data Structures 201
Final Examination
June 1994

This paper contains:

Section A (three questions); Time allowed: One hour
Section B (three questions). plus reading time: Ten minutes
Five pages in total.

Questions in Section A each carry 5 marks.
Questions in section B each carry 10 marks. Marks for this paper total 35.

Candidates should answer all three questions from Section A,
and only two questions from Section B.


Section A

Answer all three questions from this section.

  1. (5 marks)

    1. The diagram represents a Vuillemin priority queue, v.

      Draw diagrams representing the results of evaluating the following expressions:

      1. enq(7,v)
      2. deq(v)



  2. (5 marks)
    1. The diagram represents an AVL search tree, a.

      Draw diagrams representing the results of evaluating the following expressions

      1. insert(3, a)
      2. insert(13, a)
      3. insert(8,a)


  3. (5 marks)
    1. The diagram shows a weighted, directed graph.
      1. Which of the following lists of nodes are in topologically sorted order?
        1. [a, b, c, d, e, f, g]
        2. [a, d, c, f, b, e, g]
        3. [a, c, d, f, b, e, g]
        4. [a, d, f, c, b, e, g]
      2. Find a shortest path from a to g.
      3. What form of graph search would you use to find
        1. a topological sorting of the nodes,
        2. shortest path between two nodes?



Section B

Answer two questions from this section.

  1. (10 marks)

    This question uses the following declaration of a type of binary trees:

    datatype Tree = Lf | Nd of Tree * int * Tree

    We assume that implementations of the following heap operations are provided

    val insert   : int * Tree -> Tree  
    val remove   : Tree -> int * Tree  
    val downheap : Tree -> Tree

    These operations satisfy the following properties:

    • labels(insert(a,t)) = a labels(t)
    • if t is a heap then insert(a,t) is a heap
    • if (a,t) = remove(t) then labels(t) = a labels(t)
      and if t is a heap, so is t.
    • labels(t) = labels(downheap(t))
    • if the subtrees of t are heaps then so is downheap(t)

    1. (3 marks)

      Draw a diagram of the result of the operation downheap(t), where t is the tree

         (Nd (Nd (Lf, 1, Lf), 4, Nd (Lf, 0, Lf)),  
            Nd (Nd (Lf, 5, Lf), 8, Nd (Lf, 2, Lf)))

    2. (3 marks)

      Give an ML signature QueueSig suitable for a Priority Queue of integers.

    3. (4 marks)

      Write a functor with header

      functor HPQ(  
         datatype Tree = Lf | Nd of Tree * int *  Tree  
         val insert : int * Tree -> Tree  
         val remove : Tree -> int * Tree  
         val downheap : Tree -> Tree  
                 ) : QueueSig

      that uses these functions to implement an integer priority queue.



    1. An implementation of Kruskal’s algorithm (for finding a minimal-cost spanning-tree) uses two auxiliary datastructures: a priority queue of edges, and a partition of the vertices.
      1. (4 marks)

        Describe the operations on these datastructures that are used by Kruskal’s algorithm. (Give the type of each operation, and briefly describe its effect. You are not asked to describe the implementation of these operations.)

      2. (2 marks)

        What are the complexities of the priority queue operations, if the queue is implemented using a heap?

    2. Consider an alternative implementation that maintains a sorted list of the edges, removing edges from the head of the list as they are considered. (A datastructure representing a partition of the vertices is still required.)
      • (2 marks)

        What is the complexity of a suitable sorting algorithm?

    3. (2 marks)

      Consider a graph, G = (V,E). Compare the complexities (in terms of the sizes of the sets (V,E)) of the two implementations of Kruskal’s algorithm. You may assume that the operations on a partition are O(1), (this is not strictly correct, but it is a good approximation, adequate for all practical purposes).



  2. (10 marks)
    1. (2 marks)

      What is an efficient hash function?

    2. (8 marks)

      An implementation of sets of integers as balanced search-trees is “improved” by hashing with a hash table of size 117 and the hash function
      fun hash n = n mod 117
      (each entry in the hash table is itself a balanced search-tree).

      For each of the following set operations, give the complexity (in terms of the size, N, of the set) for the original implementation, and say what speedup (or slowdown) you would expect to obtain from the introduction of hashing. (Assume that the hash function is efficient for the data encountered, and that the cost of computing the hash function may be ignored.)

      1. empty
      2. isEmpty
      3. member
      4. insert
      5. delete
      6. union
      7. intersect


The End