Data Structures and Algorithms in Java
Data Structures and Algorithms in Java
6th Edition
ISBN: 9781119278023
Author: Michael T. Goodrich; Roberto Tamassia; Michael H. Goldwasser
Publisher: Wiley Global Education US
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 4, Problem 36C

Explanation of Solution

Efficient algorithm to find ten largest numbers in an array:

//Create a class

public class Integers

{

The main() function stores number of integers in an array and then use the for loop to determine the first ten largest numbers in an array.

  //Main function definition

  public static void main (String[]args)

  {

  //Declare the array of integers

int[] x= new int[]{3,4,5,6,7,8,9,10,11,2,12,13,14,15,16};

//Execute the condition until the length is 9

  if(x.length>9)

  {

/*Execute the for loop until it ends with the array of integers*/

  for(int i=1;i<x...

Explanation of Solution

Explanation:

  • Create a class and then declare the main() function.
  • Declare the required variable and assign the integer array with values.
  • Use if condition to execute until the length of array.
  • Use the outer for loop to execute until it includes all the elements in the array.
  • Use the inner for loop to determine the ten largest numbers in an array by swapping the values.
  • Then use for loop to print the ten largest numbers from an array.

Running time of algorithm:

In the above algorithm, it uses three for loop...

Blurred answer
Students have asked these similar questions
Design an algorithm to rearrange elements of a given array of n real numbers so that all its negative elements precede all its positive elements. Your algorithm should be both time efficient and space efficient.
Describe an algorithm for finding the 10 largest elements in an array of size n. What is the running time of your algorithm?
16. Given an n-element array with n > 100, is it possible to find an algorithm that can find an element that is neither the maximum nor the minimum with fewer than 10 comparisons? (a) yes (b) no

Chapter 4 Solutions

Data Structures and Algorithms in Java

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education