def count_crossings_and_nestings(arcs): Count the number of crossings and nestings between a set of arcs. Parameters: arcs (list): A list of tuples representing arcs. Each tuple contains two integers representing the start and end points of an arc. Returns: tuple: A tuple containing the number of crossings and nestings. || || || crossings = 0 nestings = 0 num_arcs = len(arcs) # Get the number of arcs using the len() function for i in range(num_arcs): for j in range(i+1, num_arcs): arci_start, arci_end = arcs [i] arcj_start, arcj_end: = arcs [j] # Check for crossings if arci_start < arcj_start < arci_end < arcj_end: crossings += 1 elif arcj_start < arci_start < arcj_end < arci_end: crossings += 1 # Check for nestings elif arci_start < arcj_start < arcj_end < arci_end: nestings += 1 elif arcj_start < arci_start < arci_end < arcj_end: nestings += 1 return crossings, nestings # Test the function arcs = [(1, 4), (0, 6), (3, 5), (2, 9), (7, 8)] crossings, nestings = count_crossings_and_nestings (arcs) print (f"Number of crossings: {crossings}") # Expected: 1 print (f"Number of nestings: {nestings}") Number of crossings: 3 Number of nestings: 4 # Expected: 3

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
100%

Look at my code, What can you say about the computational complexity of count_crossings_and_nestings? Discuss how run time and memory requirement grow as the number n of arcs increases. Give reasons.

def count_crossings_and_nestings(arcs):
Count the number of crossings and nestings between a set of arcs.
Parameters:
arcs (list): A list of tuples representing arcs. Each tuple contains two integers representing the start and end points of an arc.
Returns:
tuple: A tuple containing the number of crossings and nestings.
|| || ||
crossings = 0
nestings
= 0
num_arcs = len(arcs) # Get the number of arcs using the len() function
for i in range(num_arcs):
for j in range(i+1, num_arcs):
arci_start, arci_end = arcs [i]
arcj_start, arcj_end: = arcs [j]
# Check for crossings
if arci_start < arcj_start < arci_end < arcj_end:
crossings += 1
elif arcj_start < arci_start < arcj_end < arci_end:
crossings += 1
# Check for nestings
elif arci_start < arcj_start < arcj_end < arci_end:
nestings += 1
elif arcj_start < arci_start < arci_end < arcj_end:
nestings += 1
return crossings, nestings
# Test the function
arcs = [(1, 4), (0, 6), (3, 5), (2, 9), (7, 8)]
crossings, nestings = count_crossings_and_nestings (arcs)
print (f"Number of crossings: {crossings}") # Expected: 1
print (f"Number of nestings: {nestings}")
Number of crossings: 3
Number of nestings: 4
# Expected: 3
Transcribed Image Text:def count_crossings_and_nestings(arcs): Count the number of crossings and nestings between a set of arcs. Parameters: arcs (list): A list of tuples representing arcs. Each tuple contains two integers representing the start and end points of an arc. Returns: tuple: A tuple containing the number of crossings and nestings. || || || crossings = 0 nestings = 0 num_arcs = len(arcs) # Get the number of arcs using the len() function for i in range(num_arcs): for j in range(i+1, num_arcs): arci_start, arci_end = arcs [i] arcj_start, arcj_end: = arcs [j] # Check for crossings if arci_start < arcj_start < arci_end < arcj_end: crossings += 1 elif arcj_start < arci_start < arcj_end < arci_end: crossings += 1 # Check for nestings elif arci_start < arcj_start < arcj_end < arci_end: nestings += 1 elif arcj_start < arci_start < arci_end < arcj_end: nestings += 1 return crossings, nestings # Test the function arcs = [(1, 4), (0, 6), (3, 5), (2, 9), (7, 8)] crossings, nestings = count_crossings_and_nestings (arcs) print (f"Number of crossings: {crossings}") # Expected: 1 print (f"Number of nestings: {nestings}") Number of crossings: 3 Number of nestings: 4 # Expected: 3
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
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