COMP2247 - Algorithms and Data Structures

Syllabus Software Installation Assignments Tests
Lectures and Labs
**Back to Full Menu**

Recursion Factorial Program Fibonacci Program Integer Power Program Tower of Hanoi Program Max Element Program Palindrome Program Reverse String Program Array Sum Program



MaxElement Program


Description

This program uses a recursive method to find the largest element in an integer array.

Associated Concepts:

Recursion

Algorithm:

main method:

Create an array with a number of integer elements.

Call the recursive method findMax() to find the largest element, and pass the array and the starting index as the arguments.

findMax method definition:

If the array has only one element, it returns the only element.

Otherwise, the method returns the larger element between the first element and the largest element in the remaining sub-array.

Source Code



Sample Run



Video