7. You are a Network Admin managing a Network and you are using a topology which has a
single point of failure. If there's a break in the network media, the network becomes unavailable.
What is the topology you are using which can connect all devices to a trunk cable? Explain about
the Topology? 8. Your manager has asked you to implement a Network infrastructure. The
Requirements for the New Network Implementation are: i. The Topology you are going to
implement should accommodate failed connections. ii. The new Network implementation should
use faulttolerant topology when you connect routers on your wide area network. Which Network
topology would you implement to provide a solution for a failed link? Explain about the
Topology. 9. Mention the difference between OSI model and TCP model in Networking..
Separation of Lanthanides/ Lanthanides and Actinides
7-13 LAB- BST validity checker (C++)- I need help for BTSChecker-h- Sp.pdf
1. 7.13 LAB: BST validity checker (C++). I need help for BTSChecker.h. Specifically with the
tests shown below. The files shown are also down below. I have finished part of my code but
turning the integer variables into pointers causes them to not return an output. Please analyze it
carefully.
main.cpp
#include <iostream>
#include <string>
#include "Node.h"
#include "BSTChecker.h"
using namespace std;
int main(int argc, char *argv[]) {
// Get user input
string userInput;
getline(cin, userInput);
// Parse into a binary ree
Node* userRoot = Node::Parse(userInput);
if (userRoot) {
Node* badNode = BSTChecker::CheckBSTValidity(userRoot);
if (badNode) {
cout << to_string(badNode->key) << endl;
}
else {
cout << "No violation" << endl;
}
}
else {
cout << "Failed to parse input tree" << endl;
}
Node::DeleteTree(userRoot);
}
Node.h
#ifndef NODE_H
#define NODE_H
#include <cctype>
#include <string>
#include <vector>
2. class Node {
private:
static std::string RemoveLeadingWhitespace(std::string str) {
int i = 0;
while (i < (int) str.length()) {
// If the character at index i is not whitespace, then return the
// substring that starts at i
if (!std::isspace(str[i])) {
return str.substr(i);
}
i++;
}
// Completing the loop means the entire string is whitespace
return std::string();
}
public:
int key;
Node* left;
Node* right;
Node(int nodeKey, Node* leftChild = nullptr, Node* rightChild = nullptr) {
key = nodeKey;
left = leftChild;
right = rightChild;
}
virtual ~Node() {
}
// Counts the number of nodes in this tree
virtual int Count() {
int leftCount = 0;
if (left) {
leftCount = left->Count();
}
int rightCount = 0;
if (right) {
rightCount = right->Count();
}
return 1 + leftCount + rightCount;
}
static void DeleteTree(Node* root) {
if (root) {
3. DeleteTree(root->left);
DeleteTree(root->right);
delete root;
}
}
// Inserts the new node into the tree.
virtual void Insert(Node* node) {
Node* currentNode = this;
while (currentNode) {
if (node->key < currentNode->key) {
if (currentNode->left) {
currentNode = currentNode->left;
}
else {
currentNode->left = node;
currentNode = nullptr;
}
}
else {
if (currentNode->right) {
currentNode = currentNode->right;
}
else {
currentNode->right = node;
currentNode = nullptr;
}
}
}
}
virtual void InsertAll(const std::vector<int>& keys) {
for (int key : keys) {
Insert(new Node(key));
}
}
static Node* Parse(std::string treeString) {
// # A node is enclosed in parentheses with a either just a key: (key),
// or a key, left child, and right child triplet: (key, left, right). The
// left and right children, if present, can be either a nested node or
// "null".
// Remove leading whitespace first
treeString = Node::RemoveLeadingWhitespace(treeString);
4. // The string must be non-empty, start with "(", and end with ")"
if (0 == treeString.length() || treeString[0] != '(' ||
treeString[treeString.length() - 1] != ')') {
return nullptr;
}
// Parse between parentheses
treeString = treeString.substr(1, treeString.length() - 2);
// Find non-nested commas
std::vector<int> commaIndices;
int parenCounter = 0;
for (int i = 0 ; i < (int)treeString.length(); i++) {
char character = treeString[i];
if ('(' == character) {
parenCounter++;
}
else if (')' == character) {
parenCounter--;
}
else if (',' == character && 0 == parenCounter) {
commaIndices.push_back(i);
}
}
// If no commas, treeString is expected to be just the node's key
if (0 == commaIndices.size()) {
return new Node(std::stoi(treeString));
}
// If number of commas is not 2, then the string's format is invalid
if (2 != commaIndices.size()) {
return nullptr;
}
// "Split" on comma
int i1 = commaIndices[0];
int i2 = commaIndices[1];
std::string piece1 = treeString.substr(0, i1);
std::string piece2 = treeString.substr(i1 + 1, i2 - i1 - 1);
std::string piece3 = treeString.substr(i2 + 1);
// Make the node with just the key
Node* nodeToReturn = new Node(stoi(piece1));
// Recursively parse children
5. nodeToReturn->left = Node::Parse(piece2);
nodeToReturn->right = Node::Parse(piece3);
return nodeToReturn;
}
};
#endif
BTSChecker.h
#ifndef BSTCHECKER_H
#define BSTCHECKER_H
#include "Node.h"
using namespace std;
class BSTChecker {
public:
static Node* CheckBSTValidity(Node* rootNode) {
return rootNode;
}
};
#endif
Inispect the class deciaration for a BSI node in Node.h. Access Noden oy cicking on the orange
arrow next to main.cpp at the top of the coding window. Each node has a key, a left child
pointer, and a right child pointer. Step 2: Implement the BSTChecker::CheckBSTValidity()
function Implement the CheckBSTValidity0 function in the BSTChecker class in the
BSTChecker.h file. The function takes the tree's root node as a parameter and retums the node
that violates BST requirements, or nullptr if the tree is a valid BST. A violating node will be one
of three things: - A node in the left subtree of an ancestor with a lesser key - A node in the right
subtree of an ancestor with a greater key - A node with the left or right member variable pointing
to an ancestor The given code in main.cpp reads and parses input, and builds the tree for you.
Nodes are presented in the form (key, leftchild, rightchild), where leftchild and rightChild can be
nested nodes or "None'. A leaf node is of the form (key). After parsing tree input, the
BSTChecker: CheckBSTValidity0 function is called and the returned node's key, or "No
violation", is printed. If the input is: ( 50 , ( 25 , None, ( 60 )) , ( 75 )) which corresponds to the
tree above, then the output is: 60 because 60 violates BST requirements by being in the left
subtree of 50 . If the input is: ( 20 , ( 10 ) , ( 30 , ( 29 ) , ( 31 )) which corresponds to the tree
above, then the output is: No violation because all BST requirements are met. The input format
doesnt allow creating a tree with a node's chlld referencing an ancestor, so unit tests are used to
test such cases. 8.Unit test 0/1 invalid tree with right child linking to ancestor 9:Unit test Invalid
tree with left child linking to parent 10 Unit test Invalid tree with left chid linking to ancestor