As the title says, is there any efficient way to find the second largest element in an array using recursion?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
partition based Selection algorithm is recursive by nature, and it lets you select the
k‘th element in the array, so using it – you can actually find the answer for anyk, includingk = n-1(your case).This is done in
O(n)on average with fairly low constants.