This document is for Coventry University students for their own use in completing their assessed work for this module and should not be passed to third parties or posted on any website. Any...

1 answer below »
Programming coursework


This document is for Coventry University students for their own use in completing their assessed work for this module and should not be passed to third parties or posted on any website. Any infringements of this rule should be reported to [email protected]. Faculty of Engineering, Environment and Computing 210CT Programming, Algorithms and Data Structures Assignment Brief 2018/19 Module Title Programming, Algorithms and Data Structures Ind/Group Individual Cohort (Sept/Jan/May) September Module Code 210CT Coursework Title (e.g. CWK1) Individual Programming Assignment Hand out date: 22.10.2018 Lecturer Dr. Diana Hintea Due date: 30.11.2018 Estimated Time (hrs): 60 Word Limit*: Not applicable Coursework type: Individual Programming Assignment % of Module Mark 30% Submission arrangement online via CUMoodle: 6pm submission on the 30th of November 2018 File types and method of recording: Word or PDF Mark and Feedback date: 2 weeks after VIVA Mark and Feedback method: VIVA with a marking scheme and feedback sheet Module Learning Outcomes Assessed: On successful completion of this module a student should be able to: 1. Understand and select appropriate algorithms for solving a range of problems. 2. Design and implement algorithms and data structures for novel problems. 3. Reason about the complexity and efficiency of algorithms. 4. Demonstrate the use of object oriented programming features and advanced language features such as events, unit testing and GUIs. Task and Mark distribution 1. Build a Binary Search Tree (BST) to hold English language words in its nodes. Use a paragraph of any text in order to extract words and to determine their frequencies. Input: You should read the paragraph from a suitable file format, such as .txt. The following tree operations should be implemented: a) Printing the tree in pre-order. b) Finding a word. Regardless whether found or not found your program should output the path traversed in determining the answer, followed by yes if found or no, respectively. 2. Implement a function that deletes a node in a binary search tree in a language of your choice. This document is for Coventry University students for their own use in completing their assessed work for this module and should not be passed to third parties or posted on any website. Any infringements of this rule should be reported to [email protected]. 3. Implement the structure for an unweighted, undirected graph G, where nodes consist of positive integers. Also, implement a function isPath(v, w), where v and w are vertices in the graph, to check if there is a path between the two nodes. The path found will be printed to a text file as a sequence of integer numbers (the node values). 4. Using the graph structure previously implemented, implement a function isConnected(G) to check whether or not the graph is strongly connected. The output should be simply 'yes' or 'no'. 5. Implement BFS and DFS traversals for the above graph structure. Save the nodes traversed in sequence to a text file. 6. Adapt the previous graph structure to support weighted connections and implement Dijkstra’s algorithm. Notes: 1. You are expected to use the CUHarvard referencing format. For support and advice on how this students can contact Centre for Academic Writing (CAW). 2. Please notify your registry course support team and module leader for disability support. 3. Any student requiring an extension or deferral should follow the university process as outlined here. 4. The University cannot take responsibility for any coursework lost or corrupted on disks, laptops or personal computer. Students should therefore regularly back-up any work and are advised to save it on the University system. 5. If there are technical or performance issues that prevent students submitting coursework through the online coursework submission system on the day of a coursework deadline, an appropriate extension to the coursework submission deadline will be agreed. This extension will normally be 24 hours or the next working day if the deadline falls on a Friday or over the weekend period. This will be communicated via email and as a CUMoodle announcement. 6. Please only submit text-based code for the official online submission (no screenshots) otherwise a mark of 0 will be awarded.
Answered Same DayDec 03, 2020

Answer To: This document is for Coventry University students for their own use in completing their assessed...

Snehil answered on Dec 12 2020
144 Votes
My Work/BST/BinarySearchTree.cpp
#include
#include
#include "Node.cpp"
using namespace std;
//class to represent the tree
class BinarySearchTree
{
private:
Node* root;//base node of the tree
public:
BinarySearchTree()//default constuctor
{
root=NULL;
}
//function to add a word into the tree
void addWord(string w)
{
if(root==NULL)//if tree is empty
{
root = new Node(w);//create a new word at teh root of the tree
}
else//if tree is not empty then we find the location where the new word should be added
{
Node* temp=root;//set a temp variable at teh root, we will move this variable down the tree till it finds an empty space
Node* parent;//this variable will store the location of the parent of the empty space where a new word can be added
while(temp)//loop
to run while temp is not empty/NULL
{
parent=temp;//storing the parent location
if(w.compare(temp->getWord())<0)//if given word is lexograqphically smaller than the word present in this location
{
temp=temp->getLeftChild();//move pointer to the left child of the current location
}
else if(w.compare(temp->getWord())>0)//if given word is lexograqphically greater than the word present in this location
{
temp=temp->getRightChild();//move pointer to the right child of the current location
}
else//if the word is the same as the word in the present location, we dont need to add it again, just increase its count and end function
{
temp->addCount();
temp=NULL;
parent=NULL;
}
}
if(parent!=NULL)//if a parent location found for the new owrd to be added
{
if(w.compare(parent->getWord())<0)//if given word is lexograqphically smaller than the word present in this location
{
parent->setLeftChild(new Node(w));//add word as the left child
}
else//if given word is lexograqphically greater than the word present in this location
{
parent->setRightChild(new Node(w));//add word as the right child
}
}
}
}
void printTree()//function to call the recursive pre order printing function
{
printPreOrder(root);//start the function from the root node
}
void printPreOrder(Node* node)//function to print word at given location and recursively call on its children
{
if(node!=NULL)//if given node is not empty
{
cout<getWord()<<" : "<getCount()< printPreOrder(node->getLeftChild());//call function for left child
printPreOrder(node->getRightChild());//call function for right child
}
}
bool findWord(string w)//function to check if word is present in the tree and to print the path of the search
{
cout< if(root==NULL)//if tree is empty
{
return false;
}
else//if tree is not empty
{
Node* temp=root;//set a temp variable at teh root, we will move this variable down the tree till it finds an empty
while(temp)//loop to run while temp is not empty/NULL
{
cout<getWord();//print current word to show as path
if(w.compare(temp->getWord())<0)//if given word is lexograqphically smaller than the word present in this location
{
cout<<"->";
temp=temp->getLeftChild();//move pointer to the left child of the current location
}
else if(w.compare(temp->getWord())>0)//if given word is lexograqphically greater than the word present in this
{
cout<<"->";
temp=temp->getRightChild();//move pointer to the right child of the current location
}
else//if the word is the same as the word in the present location
{
return true;
}
}
//if in the while loop the word was not found that means it doesnt exist in teh tree
return false;
}
}
//function to find out the minimum value present in the given subtree
Node* minValueNode(Node* parent)
{
Node* temp = parent;//set temp as given node
//move to he left child, till there is no left child left
while(temp->getLeftChild()!=NULL)
{
temp=temp->getLeftChild();
}
//the left most child will have the smallest value in a binary tree, return it
return temp;
}
void deleteWord(string w)//function to delete a word from the tree
{
cout< root=deleteWord(root,w);//delete the given word and set the new root node
}
//fcuntion to delete a given word from the tree and return the new root note
Node* deleteWord(Node* root, string w)
{
if(root==NULL)//if given node is empty
{
cout< return root;
}
if(w.compare(root->getWord())<0)//given word is in the left side
{
root->setLeftChild(deleteWord(root->getLeftChild(),w));//recursive call to delete from left side
}
else if(w.compare(root->getWord())>0)//given word is in the right side
{
root->setRightChild(deleteWord(root->getRightChild(),w));//recursive call to delete from right side
}
else//if the given word is at the current node
{
if(root->getLeftChild()==NULL)//if the current node has no left child and maybe has a right child then we just replace the current node with its right child
{
Node* temp = root->getRightChild();//store link to right child
delete(root);//delete current node
cout< return temp;//return link to right child to be stored in place of the current node
}
else if(root->getRightChild()==NULL)//if the current node has a left child but no right child then we just replace the current node with its left child
{
Node* temp = root->getLeftChild();//store link to left child
delete(root);//delete current node
cout< return temp;//return link to left child to be stored in place of the current node
}
else//if the current node has two children then we have to find the in-order successor of the node and replace it with it
{
Node* temp = minValueNode(root->getRightChild());//find the in-order successor (minimum value int the right side of the sub-tree)
root->setWordAndCount(temp->getWord(),temp->getCount());//set the in-order successor values to the current location
root->setRightChild(deleteWord(root->getRightChild(),temp->getWord()));//delete the in-order successor node from the tree
}
}
return root;//return the current locatiion
}
};
My Work/BST/bin/Debug/BST.exe
My Work/BST/BST.cbp

    
    
        
        
        
        
            
                
                
                
                
                
                    
                
            
            
                
                
                
                
                
                    
                
                
                    
                
            
        
        
            
            
            
            
        
        
        
        
        
            
            
            
            
        
    
My Work/BST/BST.depend
# depslib dependency file v1.0
1544494728 source:c:\programming\tfth\35886\my work\bst\node.cpp
    
1544494749 source:c:\programming\tfth\35886\my work\bst\binarysearchtree.cpp
    
    "Node.cpp"
1544494728 c:\programming\tfth\35886\my work\bst\node.cpp
    
1544586337 source:c:\programming\tfth\35859\my work\bst\node.cpp
    
1544588062 source:c:\programming\tfth\35859\my work\bst\driver.cpp
    
    
    
    
    "BinarySearchTree.cpp"
1544587783 c:\programming\tfth\35859\my work\bst\binarysearchtree.cpp
    
    
    "Node.cpp"
1544586337 c:\programming\tfth\35859\my work\bst\node.cpp
    
1544587783 source:c:\programming\tfth\35859\my work\bst\binarysearchtree.cpp
    
    
    "Node.cpp"
My Work/BST/BST.layout

    
    
        
    
    
        
    
    
        
    
My Work/BST/Driver.cpp
#include
#include
#include
#include
#include "BinarySearchTree.cpp"
using namespace std;
void findWord(BinarySearchTree bst, string w);
int main()
{
BinarySearchTree bst;//create a new tree
ifstream fin("para.txt");//open file to be read
string word;
while(fin >> word)//while the file has a word, store it into the variable
{
for (auto c : word)//for each...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here