Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Example of Interval.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 Interval.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

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

Step: 3

blur-text-image

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

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago