Question: The following algorithm examines all the components in a given array to check whether there are any two consecutive numbers (even if they are not

The following algorithm examines all the components in a given array to check whether there are any two consecutive numbers (even if they are not adjacent) or not. For example 1: input: A[10,7,21,18,45, 22] output: true For example 2: input: A124,15,18,18,42, 22] output: false In example 1 the output is True because 21 and 22 are consecutive numbers (even not adjacent), while the output of example 2 is False because there is no any consecutive numbers. Input: An array A[O...n-1] Output: Return True if there are two consecutive elements in the array, False otherwise a) Design a brute force algorithm to solve this problem (3 marks) and analyze its complexity. [explain your answer] (2 marks) b) This problem belongs to which type of problems: P, NP, NP-Hard, NP-Complete? (2 marks) c) Design a more efficient algorithm to do the same job [Hint: don't design the detail of any internal function adopted in your algorithm, simply use a declarative name for such function without going into the details). (6 marks) analyze the complexity of your algorithm [explain your answer] (3 marks) d) Assume that the value of the elements in such array A[ ] is always between 1 and 100, can you find an algorithm able to do the check-Test in complexity in O(n). If possible, explain your idea. (4 marks)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
