Took an exam back in June which dealt mainly with algorithms, however I never really put the time into the module so the exam was beyond me at times. Was just wondering if anyone could spare the time to check out a few of the questions I came up against, as I've got a retake around the corner and can't seem to get my head around them. Probably very trivial to you guys!
Ok, here it goes..
1) Write an algorithm which calculates both the maximum and minimum of a non-empty array A[1...n]. Examples of its application:
When writing the algorithm you are allowed to use only once occurrence of a looping construct; that is one for loop or once occurrence of a while loop.
2) Given a non-empty array of numbers A[1....n], the running max of A is an array M[1...n], in which the slot M[i] contains the maximum of the subarray A[1...i]. Examples:
Write an algorithm, in the complexity class Θ(n), which inputs an array A[1....n] and outputs the running max of A.
Also, why is the algorithm in class Θ(n).
Any kind of help would be much appreciated,