Question

Design & Analysis of Algorithms Implement the algorithm in Java of the following problem

Design & Analysis of Algorithms

Implement the algorithm in Java of the following problem

media%2Fe8e%2Fe8e93cbf-7713-41c4-8e73-13

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>

using namespace std;

#define MaxInterval 3

struct Interval
{
int start, end;
};

void findSubset(Interval arr[MaxInterval], int a) {

Interval temp[MaxInterval];

int p = 0;
for (int i = 0; i < MaxInterval; i++) {
if (a >= arr[i].start && a <= arr[i].end) {
temp[p] = arr[i];
cout<<"interval is ("<<temp[p].start<<","<<temp[p].end<<")"<<endl; // will print the subset which contains point.
break;
}
}
}

int main() {
Interval arr[MaxInterval];

arr[0].start = 1;

arr[0].end = 5;

arr[1].start = 2;

arr[1].end = 3;

arr[2].start = 7;

arr[2].end = 12;

int numArr[5] = {1,3,4,8,10};

for (int i = 0; i < 5; i++) {

findSubset(arr, numArr[i]);

}

return 0;

}

Output:

interval is (1,5)
interval is (1,5)
interval is (1,5)
interval is (7,12)
interval is (7,12)

.

Add a comment
Know the answer?
Add Answer to:
Design & Analysis of Algorithms Implement the algorithm in Java of the following problem
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT