How do I make a recursive method for finding the largest element in an array A of N elements?

Posted on 2009-02-17
Last Modified: 2013-12-29
I need to know how to start a program that uses a recursive method in order to find the largest element in an array A of N elements.
Question by:15jen
    LVL 92

    Accepted Solution

    try something like:

    public int largest(int[] array)
       return largest(array, 0);

    int largest(int[] array, int start)
       if (start==array.length-1) return array[start];
       else return Math.max(array[start], largest(array, start+1);

    LVL 23

    Assisted Solution

    You can use something like this:

    int max(int[] A) {
          return max(A, 0, -Integer.MAX_VALUE);

    int max(int[] A, int start, int max) {
          if(start>=A.legnth) {
                return max;
          if(A[i]>max) {
                return max(A, start + 1, A[i]);
          return max(A, start + 1, max);

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
    Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project ( automates most of the tasks discussed in this article. You can even fin…
    The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
    The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now