* The Giving Tree of Errors 3.0 You are given a binary tree written as a sequence of parent-child pairs. You need to detect any errors which prevent the sequence from being a proper binary tree and print the highest priority error. If you detect no errors, print out the lexicographically smallest 5-expression for the tree. Input Format Input is read from standard input and has the following characteristics: • It is one line. Leading or trailing whitespace is not allowed. • Each pair is formatted as an open parenthesis (', followed by the parent, followed by a comma, followed by the child, followed by a closing parenthesis ")'. Example: (A,B) • All values are single uppercase letters. • Parent-Child pairs are separated by a single space. • The sequence of pairs is not ordered in any specific way. Input (A,B) (B,C) (A,E) (B,D) Output Output is written to standard output and must have the following characteristics: • It is one line. • It contains no whitespace. If errors are present, print out the first listed error below (e.g. if E3 and E4 are present, print E3). • If no errors are present, print the S-expression representation described below. Errors You should detect the following errors: Code Туре Invalid Input Format Duplicate Pair E1 E2 E3 Parent Has More than Two Children Multiple Roots Input Contains Cycle E4 ES S-Expression Representation If the input is a valid tree, we want you to print the lexicographically smallest S-Expression. "Lexicographically Smallest" simply means "print the children in alphabetical order." Below is a recursive definition of what we want: S-exp(node) = "({node->val}{S-exp(node->first_child)}{S-exp(node->second_child)})" if node != NULL, = ", node == NULL where, first_child->val < second_child->val (lexicographically smaller) Sample Input #01 Sample Input #00 (A, B) (A,C) (B,D) (D,C) (A, B) (B,D) (D,E) (A,C) {C,F) (E,G) Sample Output #01 ES Sample Output #00 Output #01 Explanation Node D is both a child of B and a parent of C, but Cand B are both child nodes of A. Since D tries to attach itself as parent to a node already above it in the tree, this forms cycle. (A(B(D(E(G))))(C(F))) a YOUR ANSWER
* The Giving Tree of Errors 3.0 You are given a binary tree written as a sequence of parent-child pairs. You need to detect any errors which prevent the sequence from being a proper binary tree and print the highest priority error. If you detect no errors, print out the lexicographically smallest 5-expression for the tree. Input Format Input is read from standard input and has the following characteristics: • It is one line. Leading or trailing whitespace is not allowed. • Each pair is formatted as an open parenthesis (', followed by the parent, followed by a comma, followed by the child, followed by a closing parenthesis ")'. Example: (A,B) • All values are single uppercase letters. • Parent-Child pairs are separated by a single space. • The sequence of pairs is not ordered in any specific way. Input (A,B) (B,C) (A,E) (B,D) Output Output is written to standard output and must have the following characteristics: • It is one line. • It contains no whitespace. If errors are present, print out the first listed error below (e.g. if E3 and E4 are present, print E3). • If no errors are present, print the S-expression representation described below. Errors You should detect the following errors: Code Туре Invalid Input Format Duplicate Pair E1 E2 E3 Parent Has More than Two Children Multiple Roots Input Contains Cycle E4 ES S-Expression Representation If the input is a valid tree, we want you to print the lexicographically smallest S-Expression. "Lexicographically Smallest" simply means "print the children in alphabetical order." Below is a recursive definition of what we want: S-exp(node) = "({node->val}{S-exp(node->first_child)}{S-exp(node->second_child)})" if node != NULL, = ", node == NULL where, first_child->val < second_child->val (lexicographically smaller) Sample Input #01 Sample Input #00 (A, B) (A,C) (B,D) (D,C) (A, B) (B,D) (D,E) (A,C) {C,F) (E,G) Sample Output #01 ES Sample Output #00 Output #01 Explanation Node D is both a child of B and a parent of C, but Cand B are both child nodes of A. Since D tries to attach itself as parent to a node already above it in the tree, this forms cycle. (A(B(D(E(G))))(C(F))) a YOUR ANSWER
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Please use python 3 to solve this question
(including the screenshot of your code) thanks!
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 5 images
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY