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
koban [17]
3 years ago
12

Given a sorted array of integer, A, with possible duplicate elements. Implement an efficient (sublinear running time complexity)

function in Java to find in A, the numbers of occurrences of the input value k. For example, in an array A = {-1, 2, 3, 5, 6, 6, 6, 9, 10} and k = 6, your program should return 3.
Computers and Technology
1 answer:
allsm [11]3 years ago
7 0

Answer:

The java program is as follows.

import java.util.*;

import java.lang.*;

public class SearchProgram

{

   // sorted array may or may not containing duplicate elements

   static int A[] = {-1, 2, 3, 5, 6, 6, 6, 9, 10};

   

   // variable to keep track of number of occurrences, declared and initialized to 0

   static int times=0;

   

// variable to hold value to be searched in the array

   static int key;

   static int search(int[] art, int n)

   {

       // enhanced for loop used to find how many times n occurs in array, arr

       for(int j:arr)

       {

           if(n == j)

               times = times+1;

       }

       

       return times;

   }

   

   public static void main(String[] args)

   {

       // scanner object to allow user input

       Scanner sc = new Scanner(System.in);

       

       // user prompted to enter key to be searched

       System.out.print("Enter the element to be searched: ");

       key = sc.nextInt();

       

       // message displayed to the user on how many times the element is present in the array

       System.out.println("The element " + key + " is present " + search(A, key) + " times in the array.");

   

   }

}

OUTPUT

Enter the element to be searched: 3

The element 3 is present 1 times in the array.

Explanation:

The steps of program execution are shown below.

1. An integer array, A, is declared and initialized.

2. An integer variable, times, is declared and initialized to 0.

3. A method, search(), is created which takes 2 parameters, array A and user entered value for the element to be searched in A.

4. The search() method has return type of integer and returns the value of variable, times.

5. Inside the search() method, an enhanced for loop is used to compute the value of the variable, times.

6. In the main() method, user is prompted to enter the value of key.

7. The search() is called and value of the variable, times, displayed to the user.

8. All the methods and variables are declared as static.

You might be interested in
Can you give me a long list of anime
aleksley [76]
Kill la Kill
Evangaleon
Blue Exorcist
The Devil is a Part Timer
Berserk
Death Note
K
A Boring World Where The Concept of Jokes Does not Exist
Psycho Pass
Elfen Lied
Soul Eater
Fairy Tale
Naruto
3 0
3 years ago
Read 2 more answers
Machine-to-machine (M2M) technology enables sensor-embedded products to share reliable real-time data ________.Select one:a. ove
just olya [345]

Answer:b)via radio signals

Explanation: Machine-to-machine technology is the technology that helps in sharing of the real time information of the device that have embedded sensor.They can work without the help of the manual factors.

The data is shared through the help of the radio signals in the devices like turbines vending machines etc for the tracking purpose and managing.

Thus the other options are incorrect because short distance is a disttance, cloud services are for the collection of services and databases contains the data. So, the correct option is option (b).

5 0
3 years ago
You load an image file into a numpy array and look at its shape, which is (433, 650). What does this indicate?
Nat2105 [25]

Answer:

option C

Explanation:

The correct answer is option C

the uploaded image shape is ( 433 , 650 )

this shape means that the image is a grayscale image which is 433 pixels high by 650 pixels wide.

a gray scale image is  in white and black color.

433 pixels high by 650 pixel wide means that the image is formed with the combination of 433 vertical dots and 650 horizontal dots.

Resolution of an image can be found out by the  pixels present in the images.

higher the pixel higher is he resolution of the image.

6 0
2 years ago
What is the ghosted text or picture behind the content on the page?​
Svetach [21]

Answer:

Watermark

Explanation:

This is actually called a Watermark. It is usually used as a way of showing the name or logo of the author who owns the content that is underneath the watermark. This is done so that individuals cannot steal the owner's work and use it as their own. Usually, the owner has the original version of the content without any watermark, as well as individuals that have purchased the content or a licence to use the content for personal or commercial usage.

3 0
2 years ago
Alt +f4 is a short cut of close a document in MS word /ture /false​
vesna_86 [32]

Answer:

True.

Explanation:

Microsoft Word refers to a word processing software application or program developed by Microsoft Inc. to enable its users to type, format and save text-based documents.

In Computer science, there are specific key combinations (short cut) that avail end users the opportunity to perform specific functions without having to go through a series of step.

For example, when you press the Alt button and function key 4 (F4) at the same time, it would close the current open window.

Hence, Alt + F4 is a short cut key that can be used to close a document in MS word.

8 0
2 years ago
Other questions:
  • A. True
    8·2 answers
  • Answer all 1).The most common layout of keys on the keyboard is the _____ keyboard. ASDF QWERTY JKL QWOPY,
    5·2 answers
  • "In an artificial neural network, what input values will cause the neuron below to produce an output of 1". Group of answer choi
    12·1 answer
  • How to solve 3(x - 2) = 9x<br><img src="https://tex.z-dn.net/?f=3%28x%20-%202%29%20%3D%209x" id="TexFormula1" title="3(x - 2) =
    14·1 answer
  • A blue NFiPA label indicates: A) Health Hazard B) Special information C) Flammability D) Reactivity
    6·2 answers
  • HELP PLEASE 100 POINTS
    8·2 answers
  • Which of the following statements best reflects the pros and cons of overtime potential for a line installer or repairer?
    15·1 answer
  • You can perform an in-place upgrade to Windows 7 from both Windows XP and Windows Vista
    11·2 answers
  • Similarities between master file and reference file
    12·1 answer
  • Which of the following offers a combination of the features of ram and rom?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!