Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

Example of Intervals.txt

image text in transcribed

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 30

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Database Programming

Authors: Chris Fehily

1st Edition

1937842312, 978-1937842314

More Books

Students also viewed these Databases questions

Question

Find the probabilities 3. CAC C 2 2

Answered: 1 week ago

Question

=+j Describe how EU directives impact IHRM.

Answered: 1 week ago

Question

=+and reduction in force, and intellectual property.

Answered: 1 week ago