Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Example of Intervals.txt Using Python 3.6.1. An interval on the number line is denoted by a pair of values like so: (3. 8). Our intervals
Example of Intervals.txt
Using Python 3.6.1.
An interval on the number line is denoted by a pair of values like so: (3. 8). Our intervals are closed. So this interval represents all numbers between 3 and 8 inclusive. The first number is always square brackets B in our program we will represent an interval by means of a tuple going to be strictly less than the second number. Normally in mathematics we represent a closed interval with and tuples in Python are represented with parentheses If we have two intervals like (7. 12) and (4,9), they overlap. We can collapse overlapping intervals into a single interval (4, 12). But the following two intervals 0, -2) and 1, 5) are non intersecting intervals and cannot be collapsed. The aim in this assignment is take a set of intervals and collapse all the overlapping intervals and print the smallest set of non-intersecting intervals in ascending order of the lower end of the interval The input data will be in a file called intervals.txt. There will be one or more lines of data in the file. Each line will have two integer numbers denoting an interval. The first number will be strictly less than the second number. Assume that the data file is correct. You will read in each pair of numbers and create a tuple out of them. You will store the tuples in a list. After you have read all the intervals and the list of tuples is complete you will sort the list. Then you will go through the list systematically and replace each pair of overlapping tuples with a single tuple. When you are done you should print out the list of non-intersecting tuples with one tuple per line. The list should be in ascending order of the lower end of the tuples. For the data file that is given with this problem statement, your output will have the following format Non-intersecting Intervals 25 -14 10 (12, 18) 22 30 An interval on the number line is denoted by a pair of values like so: (3. 8). Our intervals are closed. So this interval represents all numbers between 3 and 8 inclusive. The first number is always square brackets B in our program we will represent an interval by means of a tuple going to be strictly less than the second number. Normally in mathematics we represent a closed interval with and tuples in Python are represented with parentheses If we have two intervals like (7. 12) and (4,9), they overlap. We can collapse overlapping intervals into a single interval (4, 12). But the following two intervals 0, -2) and 1, 5) are non intersecting intervals and cannot be collapsed. The aim in this assignment is take a set of intervals and collapse all the overlapping intervals and print the smallest set of non-intersecting intervals in ascending order of the lower end of the interval The input data will be in a file called intervals.txt. There will be one or more lines of data in the file. Each line will have two integer numbers denoting an interval. The first number will be strictly less than the second number. Assume that the data file is correct. You will read in each pair of numbers and create a tuple out of them. You will store the tuples in a list. After you have read all the intervals and the list of tuples is complete you will sort the list. Then you will go through the list systematically and replace each pair of overlapping tuples with a single tuple. When you are done you should print out the list of non-intersecting tuples with one tuple per line. The list should be in ascending order of the lower end of the tuples. For the data file that is given with this problem statement, your output will have the following format Non-intersecting Intervals 25 -14 10 (12, 18) 22 30Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started