Give an algorithm in pseudocode for finding the largest sum of any pairs of integer numbers in
Question:
Give an algorithm in pseudocode for finding the largest sum of any pairs of integer numbers in a given sequence. For instance, if the input sequence is (3, 7, 1, 23, -13), the output has to be 30 (sum of 23 and 7).
The Lines 1,2, 10 and 11 are operations that are executed only once: 1 operation The outer loop in Line 3 is executed n times: n operations. Lines 4-9 execute a constant number of times for each iteration of the loop, so we can treat them as a single operation that executes n times. The inner loop in Line 4 contains conditional statements, which are executed in constant time, so the total time complexity of the inner loop is constant. Therefore, the total time complexity of the algorithm is 2n + 1.
Data Structures and Algorithm Analysis in Java
ISBN: 978-0132576277
3rd edition
Authors: Mark A. Weiss