Question: 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 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. 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
Get step-by-step solutions from verified subject matter experts
