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
Write the SQL code that permits to implement the tables: Student and Transcript. NB: Add the constraints on the attributes – keys and other.
Draw an ERD that will involve the entity types: Professor, Student, Department and Course. Be sure to add relationship types, key attributes, attributes and multiplicity on the ERD.
Draw an ERD that represents a book in a library system. Be sure to add relationship types, key attributes, attributes and multiplicity on the ERD.

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
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,