Question:
computer PROGRAMING HELP!!!?
Big and Tasty
2012-04-02 06:54:54 UTC
A programmer is asked to write a method to search a sorted array t of Strings for a given target String. The programmer writes the following method:

public static int search( String[] array, String target )
{
Random p = new Random();
int r = 0;

while ( !target.equals( array[ r ] ) )
{
r = p.nextInt( array.length );
}

return r;
}


Exactly one of these statements is true. Which one?

A. This method will only work if the target is the first element of the array.

B. On average, this method will perform better when the array is unsorted.

C. There are target values for which this method will never return a value.

D. A sequential search of the same array will always perform better than this method.

E. This method will make at most k iterations, where k is the length of the array.
Four answers:
green meklar
2012-04-02 16:08:21 UTC
C is the correct answer. But what do you expect to gain if you get other people to do your homework for you? The point of homework is to do it yourself so that you learn the material.
anonymous
2016-02-23 01:02:20 UTC
Look on youtube, or google. Just type the name of the language and "tutorial" on your searches. I would recommend you get a Linux or BSD operating system if you are going into programming. Not only is it easier to get compilers, but Linux provides better support for programming software. Also, you can reprogram anything on the operating system, so it's easier to learn and lots of fun to tinker with. Here are some languages you should start with: Java Python C++ C Ruby Perl With java, you need to download the java platform to compile and run your programs.
anonymous
2012-04-02 06:59:46 UTC
Thank you for sharing your assignment with us. What is your question?
James Bond
2012-04-02 07:02:51 UTC
D


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...