TO DO: Create a Python Program that satisfies all the testcases

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Topics: Graph Data Structures, Depth-First Search, Breadth-First Search, Dijkstra’s Algorithm, Bellman-Ford Algorithm, Kruskal’s Algorithm, Prim’s Algorithm, Quick Find, Quick Union, Weighted Quick Union

TO DO: Create a Python Program that satisfies all the testcases

Since an electronic circuit is the interconnection of several components, it might not be surprising that they can be represented as graphs which allow our computers to simulate the behavior of the circuit. A sample resistor network has its corresponding netlist representation used in ngspice (see Figure 1).

Description:

This problem focuses on properly parsing the input. To test this, your code should be able to properly store each input resistor and store them in a data structure and representation of your choice. To verify this, your code should be able to identify which resistors are in series and which resistors are in parallel. In the context of a graph, two resistors can be considered in series if there are no branches in the path formed between the resistors. On the other hand, two resistors can be considered in parallel if they are connected to the same two nodes. 

Input Format:

The first line of the input consists of 2 integers N and which is the total number of resistors and total number of queries, respectively. The next lines will consist of 3 strings and an integer R, each separated by a space. The first string is the resistor name, the second, and third strings are the node names where the resistor terminals are connected, and R is its resistance value. Finally, there will be Q lines with two strings each which will each be the name of a resistor. 

Output Format:

The output is expected to have Q lines which correspond to the answer to each query. If the resistors in the first query are in series, the first line of the output should be SERIES. If they are parallel, the expected output is PARALLEL. If they are neither in series or parallel, the expected output is NEITHER

Constraints

● Resistors in the queries are guaranteed to exist.
● 1 ≤ N,Q ≤ 1000 and 0 < ≤ 109

Three Testcases:

Sample Input 1
(see Figure 2)

5 4
R1 Vdd a 1000
R2 a GND 1000
R3 Vdd b 1000
R4 b GND 1000
R5 b GND 1000
R1 R2
R2 R3
R3 R4
R4 R5

Sample Output 1

SERIES
NEITHER
NEITHER
PARALLEL

Sample Input 2

3 6
R1 Vdd GND 1000
R2 Vdd GND 500
R3 Vdd GND 200
R1 R2
R1 R3
R2 R3
R2 R1
R3 R1
R3 R2

Sample Output 2

PARALLEL
PARALLEL
PARALLEL
PARALLEL
PARALLEL
PARALLEL

Sample Input 3

5 10
R1 Vdd a 10000
R2 a b 2000
R3 b c 300
R4 c d 40
R5 d GND 5
R1 R2
R1 R3
R1 R4
R1 R5
R2 R3
R2 R4
R2 R5
R3 R4
R3 R5
R4 R5

Sample Output 3

SERIES
SERIES
SERIES
SERIES
SERIES
SERIES
SERIES
SERIES
SERIES
SERIES

Vad
R1
2
R2
smo
D
R4
Input 1
54
R1 Vdd a 1000
R2 a GND 1000
R3 Vdd b 1000
R4 b GND 1000
R5 b GND 1000
R1 R2
R2 R3
R3 R4
R4 R5
R3
R5
1
2
345
R1 Vdd a 1000
R2 a GND 1000
R3 Vdd b 1000
R4 b GND 1000
R5 b GND 1000
Output 1
SERIES
NEITHER
NEITHER
PARALLEL
Visualization
Va dd
Figure 2. Sample Input and Output
R₁
5
Figure 1. A sample resistor network
(left) circuit diagram, (middle) ngspice netlist, and (right) graph representation.
a
R₂
(GND)
Vad
R₁₁
a
R₂
(GND)
RA
R3
RA
R3
b
R5
b
R5
Transcribed Image Text:Vad R1 2 R2 smo D R4 Input 1 54 R1 Vdd a 1000 R2 a GND 1000 R3 Vdd b 1000 R4 b GND 1000 R5 b GND 1000 R1 R2 R2 R3 R3 R4 R4 R5 R3 R5 1 2 345 R1 Vdd a 1000 R2 a GND 1000 R3 Vdd b 1000 R4 b GND 1000 R5 b GND 1000 Output 1 SERIES NEITHER NEITHER PARALLEL Visualization Va dd Figure 2. Sample Input and Output R₁ 5 Figure 1. A sample resistor network (left) circuit diagram, (middle) ngspice netlist, and (right) graph representation. a R₂ (GND) Vad R₁₁ a R₂ (GND) RA R3 RA R3 b R5 b R5
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Algebraic Expressions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education