Java Programming   Consider a set of n intervals I1,...,In, each given as an integer tuple (si,fi) with si

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Java Programming

 

Consider a set of n intervals I1,...,In, each given as an integer tuple (si,fi) with si<fi, such that the ith interval starts at si and ends at fi. We want to determine the maximum number of nonoverlapping intervals. More formally, we want to determine the size of a largest subset S⊆{1,...,n} such that for i, j∈S,  with i≠j we have fj≤si or fi≤sj. Note that the intervals [1,2] and [2,3] are not considered to be overlapping.

Input

The first line of input consists of an integer n∈{1,...,105}, the number of intervals. Each of the following n lines consists of two space-separated integers ss and ff, indicating an interval starting at s and ending at f, with 0≤s<f≤109.

 

requirements: 

CPU Time limit: 4 seconds

Memory limit: 1024 MB

 

Output

Output a single integer, the largest number of nonoverlapping intervals.

Sample Input 1
Sample Output i
3
2
1 4
2 8
5 9
Sample Input 2
Sample Output 2
8
1 4
3 5
3 8
4 7
5 9
6 10
8 11
Transcribed Image Text:Sample Input 1 Sample Output i 3 2 1 4 2 8 5 9 Sample Input 2 Sample Output 2 8 1 4 3 5 3 8 4 7 5 9 6 10 8 11
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY