Helsingin yliopisto / Tietojenkäsittelytieteen laitos / Tietorakenteet / Copyright © 2001 Arto Wikla.

581325-0 Data Structures, 1. Course Examination 12.3.2001/AW

Write the name of the course, the date of the exam, and your name, personal number and signature on each paper. Write each answer on a separate sheet of paper!


  1. Explain exactly and with examples how O(f(n)) is defined and how it can be used when mapping out the execution time of algorithms. Give examples of algorithms that belong to O(1), O(log n), O(n), O(n2) and O(2n). Justify your answer.
                                                                  (7 points)
    
    

  2. A train is presented as a double-linked list. The locomotive and the cars are Strings. Program the class Train with the operations:

    Specify the behaviour of the methods, in error situations, as well, and implement the class Train.

    With the help of the class Train, create the separate class Tools with library functions for the foreman of a railway station. The class Tools should contain the following tools.

    Please note! The tools must be implemented only with the help of the public methods listed above.
                                                                  (7 points)
    
    
  3. Specify a list, a stack and a queue as an abstract data type (ADT).
                                                                  (4 points)
    
    
    

  4. A binary tree represents a family tree, where the root is 'me'. The subtrees of the root are 'mother', 'father' etc. The specification of the tree starts as follows.
      class Relative {
        String name;
        int yearOfBirth;
        Relative mother, father;
      }
    
      public class FamilyTree {
    
         private Relative root;
    
         public FamilyTree() {
           root = null;
         }
         ...
    
    
    Program the methods for the class (specify their function in error situations, as well).

                                                                  (7 points)