Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 820199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:26:13+00:00 2026-05-15T02:26:13+00:00

I have to find recursively if there is any repeated element in an integer

  • 0

I have to find recursively if there is any repeated element in an integer array v.
The method must have the following signature:

boolean hasRepeatedElements(int[] v) 

I can’t see any way of doing that recursively without having to define another method or at least another overload to this method (one that takes for example the element to go after or something). At first I thought about checking for the current v if there is some element equal to the first element, then creating a new array with L-1 elements etc. but that seems rather inefficient. Is it the only way?

Am I missing something here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T02:26:14+00:00Added an answer on May 15, 2026 at 2:26 am

    I agree that recursion is not terribly necessary here, but it can be used.
    Do you know quick-sort algorithm? Same divide-and-conquer approach can be taken here.

    boolean hasRepeatedElements(list v) 
        if v.length <= 1 return false;
        List less, greater;
        x = v[0];
        for each y in v, except v[0]
            if y == x
                return true;
            else if y < x
                less.add(y);
            else if y > x
                greater.add(y);
        end;
        return hasRepeatedElements(less) || hasRepeatedElements(greater);
    end;
    

    You can also add randomization to make algorithm statistically O(n*log(n)).

    http://en.wikipedia.org/wiki/Quicksort

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Find function in order to find an element from a BST
I have a javascript object, and I want to recursively search it to find
Possible Duplicate: How to find the kth largest element in an unsorted array of
I have an array of words I need to do a find-and-replace by regex
I have a whole array of regexp queries to make recursively going through the
is there any way to convert this to a recursion form? how to find
I have the following function to recursively search for dll files. Function ProcessDLLFiles Exch
I am evaluating datamining packages. I have find these two so far: RapidMiner Weka
I have to find some patters from a XML file, but i am unable
I have a few models that need to have custom find conditions placed on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.