Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement a class that contains a method with the signature ( [ ] , ) that computes and returns the LAFS of the input. More

Implement a class that contains a method with the signature ( [ ] , ) that computes and returns the LAFS of the input. More specifically, an Almost Flat Subarray is any contiguous subarray of such that no two elements of that subarray differ by more than . We want to find the longest such subarray. The output should be a pair (,), indicating that . . + is the LAFS of . You should also include some nontrivial and interesting test cases in the () method of your class. Your lAFS method should run in worst-case () time, where = .. Any less efficient or incorrect algorithm will lose at least half of the marks. In your a1sol.pdf file you should give some justification about the correctness and time complexity of your implementationimage text in transcribed

Problem 1 (70%] Longest Almost Flat Subarray (LAFS): Implement a Longest Almost FlatSubarray class that contains a method with the signature LAFS( int[] arr, int diff) that computes and returns the LAFS of the input. More specifically, an Almost Flat Subarray is any contiguous subarray of arr such that no two elements of that subarray differ by more than diff. We want to find the longest such subarray. The output should be a pair (start, len), indicating that arr[start.. start + len 1] is the LAFS of arr. You should also include some nontrivial and interesting test cases in the main() method of your class. Your IAFS method should run in worst-case O(n) time, where n = arr.length. Any less efficient or incorrect algorithm will lose at least half of the marks. In your alsol.pdf file you should give some justification about the correctness and time complexity of your implementation. Problem 1 (70%] Longest Almost Flat Subarray (LAFS): Implement a Longest Almost FlatSubarray class that contains a method with the signature LAFS( int[] arr, int diff) that computes and returns the LAFS of the input. More specifically, an Almost Flat Subarray is any contiguous subarray of arr such that no two elements of that subarray differ by more than diff. We want to find the longest such subarray. The output should be a pair (start, len), indicating that arr[start.. start + len 1] is the LAFS of arr. You should also include some nontrivial and interesting test cases in the main() method of your class. Your IAFS method should run in worst-case O(n) time, where n = arr.length. Any less efficient or incorrect algorithm will lose at least half of the marks. In your alsol.pdf file you should give some justification about the correctness and time complexity of your implementation

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

XML Data Management Native XML And XML Enabled Database Systems

Authors: Akmal Chaudhri, Awais Rashid, Roberto Zicari, John Fuller

1st Edition

0201844524, 978-0201844528

More Books

Students also viewed these Databases questions

Question

6. Have you used solid reasoning in your argument?

Answered: 1 week ago