• Home
  • Blog
  • two parts(python). 1- class for binary tree, 2- class to output HTML, computer science homework help

two parts(python). 1- class for binary tree, 2- class to output HTML, computer science homework help

0 comments

In all the classes for this assignment, use of the following Python language features is mandatory:

It is strongly recommended to read and understand http://docs.python.org/py3k/reference/datamodel.ht… and http://www.cafepy.com/article/python_types_and_obj….

  1. Define a class that can be used to output an HTML report regarding word frequencies in an input text file. The report must identify the shortest word, the longest word, the most frequently used word, the least frequently used word, and a histogram of all the words used in the input file. The class, at a minimum, must have the following interface:
    • A constructor
    • Add a word
    • Write a report to file named `filename`

    The remainder of the class definition is left up to you.

  2. Write one or more classes that define a binary tree which can be used with the following main function.
    import random
    import sys
    
    def main( ):
      if len(sys.argv) < 2:
        print('Please provide the number of keys to enter.')
        sys.exit(1)
      s = int(sys.argv[1])
      parts = int(s/3)
      t = Tree( )
      r = list(range(1,s+1))
    
      print('Randomly inserting the numbers from 1 to {}.'.format(len(r)))
    
      random.shuffle(r)
    
      for i in r:
        print('inserted {}'.format(i))
        t.insert(i)
      f = open('a.dot', 'w')
      writeTree(t, f)
      f.flush( )
      f.close( )
      random.shuffle(r)
    
      for n in range(1, 3):
        m = r[(n-1) * parts : (n * parts)]
        print(len(m))
        for i in m:
          print('removed {}'.format(i))
          v = t.remove(i)
          if v:
            print('tcompleted.')
          else:
            print('terror.')
        c = chr(n + 97)
        filename = str(c) + '.dot'
        f = open(filename, 'w')
        writeTree(t, f)
        f.flush( )
        f.close( )
    

    The output of the program is a file in DOT syntax. The output of your program must be passed to the program `dot`, part of Graph Viz, to create an visualization of your tree. An example output file is the following:

    digraph BST{
            node [fontname="Helvetica"];
            7 -> 2;
            2 -> 1;
            null1 [shape=point];
            1 -> null1;
            null2 [shape=point];
            1 -> null2;
            null3 [shape=point];
            2 -> null3;
            7 -> 9;
            null4 [shape=point];
            9 -> null4;
            null5 [shape=point];
            9 -> null5;
    }

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}