Csci 335 Assignment 2 Programming: Using and Comparing Tree Implementations solution

$24.99

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (5 votes)

The goal of this assignment is to become familiar with trees and compare the performance of the basic binary search tree with the self-balancing AVL tree. You will also work with a real world data set and construct a generic test routine for comparing several different implementations of the tree container class. You are encouraged to use the book’s implementation for the BST and AVL trees. You will are provided with the following code to start: avl_tree.h, bst_tree.h, query_tree.cc, test_tree.cc, test_tree_mod.cc, dsexceptions.h, a README.txt, a Makefile and some .txt files for input and expected output. Part 1 (5 points) First, create a class object named SequenceMap that has as private data members the following two: string recognition_sequence_ ; vector enzyme_acronyms_; The name of the file should be sequence_map.h. Other than the big-five (note that you can use the defaults for all of them), you have to add the following: a) A constructor SequenceMap(const string &a_rec_seq, const string &an_enz_acro),that constructs a SequenceMap from two strings (note that now the vector enzyme_acronyms_ will contain just one element, the an_enz_acro). b) bool operator<(const SequenceMap &rhs) const, that operates based on the regular string comparison between the recognition_sequence_ strings (this will be a one line function). c) Overload the operator<< for SequenceMap. d) void Merge(const SequenceMap &other_sequence). This function assumes that the object’s recognition_sequence_ and other_sequence.recognition_sequence_ are equal to each other. The function Merge() merges the other_sequence.enzyme_acronym_ with the object’s enzyme_acronym_. The other_sequence object will not be affected. This class (which is non-templated) will be used in the following programs. First test it with your own test functions to make sure that it operates correctly. Part 2 Introduction to the problem For this assignment you will receive as input two text files, rebase210.txt and sequences.txt. After the header, each line of the database file rebase210.txt contains the name of a restriction enzyme and possible DNA sites the enzyme may cut (cut location is indicated by a ‘) in the following format: enzyme_acronym/recognition_sequence/…/recognition_sequence// For instance the first few lines of rebase210.txt are: AanI/TTA’TAA// AarI/CACCTGCNNNN’NNNN/’NNNNNNNNGCAGGTG// AasI/GACNNNN’NNGTC// AatII/GACGT’C// AbsI/CC’TCGAGG// AccI/GT’MKAC// AccII/CG’CG// AccIII/T’CCGGA// Acc16I/TGC’GCA// Acc36I/ACCTGCNNNN’NNNN/’NNNNNNNNGCAGGT// … That means that each line contains one enzyme acronym associated with one or more recognition sequences. For example on line 2: The enzyme acronym AarI corresponds to the two recognition sequences CACCTGCNNNN’NNNN and ‘NNNNNNNNGCAGGTG. Part 2(a) (40 points) You will create a parser to read in this database and construct a search tree (either a regular BST or an AVL tree). For each line of the database and for each recognition sequence in that line, you will create a new SequenceMap object that contains the recognition sequence as its recognition_sequence_ and the enzyme acronym as the only string of its enzyme_acronyms_, and you will insert this object into the tree. This is explained with the following pseudo code: Tree a_tree; string db_line; // Read the file line-by-line: while (GetNextLineFromDatabaseFile(db_line)) { // Get the first part of the line: string an_enz_acro = GetEnzymeAcronym(db_line); string a_reco_seq; while (GetNextRegocnitionSequence(db_line, a_rego_seq){ SequenceMap new_sequence_map(a_reco_seq, an_enz_acro); a_tree.insert(new_sequence_map); } // End second while. } // End first while. In the case that the new_sequence_map.recognition_sequence_ equals the recognition_sequence_ of a node X in the tree, then the search tree’s insert() function will call the X.Merge(new_sequence_map) function of the existing element. This will have the effect of updating the enzyme_acronym_ of X. Note, that this will be part of the functionality of the insert() function. The Merge() will only be called in case of duplicates as described above. Otherwise, no Merge() is required and the new_sequence_map will be inserted into the tree. To implement the above, write a test program named query_tree which will use your parser to create a search tree and then allow the user to query it using a recognition sequence. If that sequence exists in the tree then this routine should print all the corresponding enzymes that correspond to that recognition sequence. Your programs should run from the terminal as follows: query_tree should be “BST” for binary search tree, and “AVL” for AVL tree. For example you can write on the terminal: ./query_tree rebase210.txt BST The user should enter THREE strings (supposed to be recognition sequences) for instance: CC’TCGAGG TTA’TAA TC’C Your program should print in the standard output their associated enzyme acronyms. In the above example the output will be AbsI AanI PsiI Not Found I will test it with a file containing three strings and run your code like that: ./query_trees rebase210.txt BST < input_part2a.txt ./query_trees rebase210.txt AVL < input_part2a.txt Part2(b) (40 points) Next, create a test routine named test_tree that does the following in the sequence described below: 1. Parses the database and construct a search tree (this is the same as in Part2(a)). 2. Prints the number of nodes in your tree �. 3. Computes the average depth of your search tree, i.e. the internal path length divided by �. a. Prints the average depth. b. Prints the ratio of the average depth to log! �. E.g., if average depth is 6.9 and log! � = 5.0, then you should print !.! !.! = 1.38. 4. Searches (find()) the tree for each string in the sequences.txt file. Also counts the total number of recursive calls for all executions of find(). a. Prints the total number of successful queries (number of strings found). b. Prints the average number of recursion calls, i.e. #total number of recursion calls / number of queries. 5. Removes every other sequence in sequences.txt from the tree. Also counts the total number of recursion calls for all executions of remove(). a. Prints the total number successful removes. b. Prints the average number of recursion calls, i.e. #total number of recursion calls / number of remove calls. 6. Redo steps 2 and 3: a. Prints number of nodes in your tree. b. Prints the average depth. c. Prints the ratio of the average depth to log! �. The output of Part2(b) should be of the exact form: 2: 3a: 3b: 4a: 4b: 5a: 5b: 6a: 6b: 6c: If you didn’t complete a step, just print after the step number: Not Done ——— For both Part2(a) and Part2(b) you must write the test routine using templates so each tree can be used interchangeably. The trees should have identical interfaces. Your program should run from the terminal as follows: test_tree should be “BST” for binary search tree, and “AVL” for AVL tree. For example you can write on terminal ./test_tree rebase210.txt sequences.txt AVL Part2(c) (15 points) You will use the avl_tree.h code you have written for Part2(b) and you will modify it in order to implement double rotations directly instead of calling the two single rotations. Name your modified implementation avl_tree_mod.h. Run the exact same routines as in Part2(b), but now with your modified AVL implementation. The executable should be named test_tree_mod. The results should be the same as in Part2(b). For example you can write on terminal ./test_tree_mod rebase210.txt sequences.txt You will be given a mandatory Makefile, along with some code to start (start of main functions query_tree.cc test_tree.cc test_tree_mod.c, along with the Avl and BST implementations from the book. Deliverables: You should submit these files (and only these files) to Gradescope: • README.txt file (as discussed in class) • Part 1: sequence_map.h: Your original sequence_map.h will be reused for all further sections. • Part 2A: (Modify avl_tree & code by adding functions) query_tree.cc avl_tree.h bst_tree.h • Part 2B: test_tree.cc avl_tree.h (same file as above) bst_tree.h (same file as above) • Part 2C: test_tree_mod.cc avl_tree_mod.h In summary you will upload to Gradescope (by drag and drop) the following files (do not change their names in any way – do not capitalize any letter): README.txt, sequence_map.h, avl_tree.h, bst_tree.h, query_tree.cc, test_tree.cc, test_tree_mod.cc, avl_tree_mod.h