**Question - **
LAURENTIAN UNIVERSITY
DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE
COSC 2007 – Data Structure II
ASSIGNMENT 4
Due date: Thursday, November 20, 2013
Purpose:
To practice implementing recursive algorithms and some basic tree operations.
Files that you must write and turn in:
implementation of the programs described below
a detailed documentation of all your implemented programs
a README file to explain (in full detail) how to run your programs Submissions:
electronic copy via D2L
The Assignment:
Question 1 (20 Marks)
The greatest common divisor of two positive integers m and n, referred to as gcd(m,n), is the largest divisor common to m and n. For example, gcd(24,36) = 12, as the divisors common
...Read More
to 24 and 36 are 1, 2, 3, 4, 6, and 12. An efficient approach to calculating the gcd, attributed to the famous ancient Greek mathematician Euclid, is based on the following recursive algorithm:
gcd(m,n)
if m < n, then swap the values of m, n if n is a divisor of m, return n else return gcd(n,m%n)
Design, implement, and test a GUI program Euclid that repeatedly prompts the user for a pair of positive integers and reports the gcd of the entered pair.
Question 2 (20 Marks)
The following defines a function that calculates an approximation of the square root of a number, starting with an approximate answer (approx), within the specified tolerance (tol).
392884722561482845922561$2
&& approxifapprox −number≤tol
sqrRoot(number,approx,tol)=%(approx2 +number)2
& sqrRoot(number,,tol)if approx −number >tol&'(2×approx)
Write a recursive method sqrRoot that implements the function.
Write a non-recursive version of the method sqrRoot.
Write a driver to test the recursive and non-recursive versions of the method sqrRoot. Which version did you find easier to implement?
Page 1 of 2
Question 3 (60 Marks)
The purpose of this question is to give you experience in implementing a simple spell checking program that uses the binary search trees data structure. In this Question, you will load a dictionary file into a binary search tree and output the height of the tree. Then, read in an input file and check the spelling of each word in the content against that of the dictionary (if a word is present, it is spelled correctly, otherwise, indicate it as misspelled). Your program will take two inputs from the user:
the file name of the dictionary, e.g., dictionary.txt
the file name of the input file to be spell checked, e.g., test.txt
The input file (to be spell checked) can be any text file. You should identify individual words and avoid spaces and punctuations. Words in the dictionary file are separated by spaces. The comparison should be case insensitive (i.e. the words go, Go and GO are the same).
The program should output the height of the binary search tree (for dictionary), possible misspelled words, and count the total number of words as well as the number of misspelled words. You are required to use the binary search tree data structure to solve this problem.
Hints:
Store the dictionary into a binary search tree data structure;
Read in the word one by one from the input file (to be spell checked) and search the binary search tree to see whether it is presented in the dictionary;
Convert the word into lowercase before perform the checking. Numerical numbers are discarded from the spell check.
Marking details
Documentation (Javadoc) / README file 10 Marks
Comments/ Neatness/ Style 10 Marks
Implementation:
Correct output in all test cases: 100%
Correct output in most cases: 80%
Correct output for some test cases: 60%
Lots of errors: 20%
Program does not compile: 5% 80 Marks
Page 2 of 2
...Read Less

**Solution Preview - **No Preview Available. <b>Check Original File</b>

**Original Question Documents**