1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Katena32 [7]
3 years ago
8

Write a linear (O(N)) running time complexity program in Java to find all the dominant elements in the given array of N distinct

integer elements. An element is a dominant element if is greater than all the elements to its right side. The rightmost element in the array is always a dominant element. For example, in the array {16, 17, 4, 3, 5, 2}, dominant elements are 17, 5 and 2.
Computers and Technology
1 answer:
kotykmax [81]3 years ago
3 0

The program is an illustration of arrays

<h3>What are arrays?</h3>

Arrays are variables that hold multiple values of the same type in one variable name

<h3>The program in Java</h3>

The linear (O(N)) running time complexity program in Java, where comments are used to explain each line is as follows

import java.util.*;

public class Main{

   public static void main(String [] args){

       //This initializes an array

       int arr[] = {16, 17, 4, 3, 5, 2};

       //This gets the size of the array

       int size = arr.length;

       //This iterates through the array

       for (int i = 0; i < size; i++){

 //This declares an integer variable

 int j;

 //This iterates through every other element of the array

 for (j = i+1; j < size; j++){

     //This condition breaks the loop

  if (arr[i] <=arr[j])

   break;

 }

 //This conditions prints the dominant element

 if (j == size){

  System.out.print(arr[i] + " ");}

       }

   }

}

Read more about arrays at:

brainly.com/question/25083828

You might be interested in
What is the name of situation where the same data is stored unnecessarily at different places?
Delicious77 [7]

Answer:

Data redundancy.

Explanation:

A database management system (DBMS) can be defined as a collection of software applications that typically enables computer users to create, store, modify, retrieve and manage data or informations in a database. Generally, it allows computer users to efficiently retrieve and manage their data with an appropriate level of security.

A data dictionary can be defined as a centralized collection of information on a specific data such as attributes, names, fields and definitions that are being used in a computer database system.

In a data dictionary, data elements are combined into records, which are meaningful combinations of data elements that are included in data flows or retained in data stores.

Data redundancy is the name of situation where the same data is stored unnecessarily at different places.

Simply stated, data redundancy can be defined as a condition which typically involves storing the same data in multiple storage locations. Thus, data redundancy connotes the unnecessary repetition of the same piece of data (informations) either deliberately or for some specific reasons.

3 0
3 years ago
1. Accessing calendars, contact information, emails, files and folders, instant messages, presentation, and task lists over the
Veseljchak [2.6K]
1. Cloud Computing
2. Web Conferencing
3. Ribbon
4. PowerPoint
5. Sadie should share the document in One Drive and give her sister permission to edit the document
6. The design and arrangement of items for efficiency and safety
6 0
3 years ago
Help please fast
Pachacha [2.7K]
Bookmark because you can go back to it at any given time to re use it
4 0
3 years ago
Read 2 more answers
Java
VARVARA [1.3K]

Answer:

Here are the two statements which use nextInt() to print two random integers between 0 and 9:

System.out.println(randGen.nextInt(10));

System.out.println(randGen.nextInt(10));

Explanation:

Here is the complete program:

import java.util.Scanner;   //to accept input from user

import java.util.Random;   // use to generate random numbers

public class DiceRoll {  //class definition

public static void main (String [] args)  {//start of main function  

Random randGen = new Random();   // creates a Random class object randGen

int seedVal = 0;   //sets starting point for generating random numbers

randGen.setSeed(seedVal);   //sets the seed of random number generator

System.out.println(randGen.nextInt(10));  //generates and prints the first random integer between 0 and 9 (10 is the range from 0 to 9) using nextInt method, which is used to get next random integer value from the sequence of random number generator

System.out.println(randGen.nextInt(10));   //generates and prints the second random integer between 0 and 9 (10 is the range from 0 to 9) using nextInt method

return;    }  }

Another way to write this is to initialize two int variables:

int integer1;

int integer2;

Now use two print statements to print these random integers between 0 and 9 as:

System.out.println(integer1= randGen.nextInt(10));

System.out.println(integer1= randGen.nextInt(10));

Another way to write this is:

Set the value of integer1 to a random number from 0 to 9 and same for integer2

int  integer1 = randGen.nextInt(10);

int  integer2 = randGen.nextInt(10);  

Now use two print statements to print these random integers between 0 and 9 as:  

System.out.println(integer1);

System.out.println(integer2);

5 0
4 years ago
A farmer sells tomatoes. For some reason, the farm obeys mechanical laws of fate.
Mars2501 [29]

Answer:

Here are the if/elif statements:

if tomatoes == 24:  #if farmer sells exactly two dozen tomatoes

   watermelons +=4  #farmer receives 4 watermelons

elif tomatoes >= 12:  #else farmer sells at least a dozen tomatoes

   watermelons +=2  #farmer receives 2 watermelons

else:

   tomatoes<12   #On the days that farmer sells less than a dozen tomatoes

   apples +=1  #farmer will get a single apple

Explanation:

You can test the working of these if elif statements by this program:

tomatoes = int(input("Enter the amount of tomatoes sold: "))  #prompts user to enter number of tomatoes

watermelons = 0  #initialize watermelons value to 1

apples = 0  #initialize apples value to 1

if tomatoes == 24:

   watermelons +=4

elif tomatoes >= 12:

   watermelons +=2

else:  

   tomatoes<12

   apples +=1

   

print("Number of watermelons recieved: ",watermelons)  #displays the received number of watermelons

print("Number of apples recieved: ",apples )  #displays the received number of apples

8 0
3 years ago
Other questions:
  • How would you insert a section break in a document?
    10·1 answer
  • List three examples of observations of earth by remote-sensing satellites
    6·1 answer
  • A feature that displays in the lower right corner of a selected range with which you can analyze your data by using Excel tools
    12·2 answers
  • How should the teachers respond to the parental complaints of student C? If they fail the student, the student will likely be re
    11·1 answer
  • If you are working with a team of students on a class project and your team chooses to share content by uploading Word and Excel
    13·1 answer
  • If you insert a single row by using the Insert command on the shortcut menu, you can continue inserting rows by repeatedly press
    7·2 answers
  • Three Strings someone help
    15·1 answer
  • Please help What two Boolean operators can you use to narrow your search results?
    7·1 answer
  • Identify the reasons that numeric data representation is important to computer programmers. Check all that apply.
    12·2 answers
  • Sort the layout options for two types of masters in PowerPoint.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!