Question

MULTIPLE CHOICE:​​​​​​ 1. How would you best describe the purpose of the following code? f =...

MULTIPLE CHOICE:​​​​​​

1. How would you best describe the purpose of the following code?
f = 0;
for (i = 1; i < N; ++i)
if (a[i] >= a[f])
f = i;

a. Rearrange the first N components of array a in descending order.

b. Rearrange the first N components of array a in ascending order.

c. Place the largest component of array a in position N.

d. Compute the value of the largest component in array a.

e. Determine the subscript of the last occurrence of the largest of the first N components of array a.

2. Which one of the conditions that follow will be false (value of 0) after execution of the program segment below?
int v[5] = {0, 0, 0, 0, 1};
int k, j;
for (j = 3; j >= 0; --j)
for (k = j; k < 4; ++k)
v[k] += v[k + 1];

a. v[0] == v[4]

b. v[1] == v[3]

c. v[0] < v[1]

d. v[1] < v[2]

e. v[2] < v[3]

3. Searching an array by testing each element in the array using a loop is called a(n) _______ search.

a. random

b. linear

c. looped

d. stacked

e. none of the above

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Question 1:
e. Determine the subscript of the last occurrence of the largest of the first N components of array a.

Question 2:
v[0] = 1
v[1] = 4
v[2] = 6
v[3] = 4
v[4] = 1
Answer:
e. v[2] < v[3]

Question 3:
Searching an array by testing each element in the array using a loop is called a(n) linear search.
Answer:
b. linear

Add a comment
Know the answer?
Add Answer to:
MULTIPLE CHOICE:​​​​​​ 1. How would you best describe the purpose of the following code? f =...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 6. (4 points) The following code for insertion sort has been modified to print out the...

    6. (4 points) The following code for insertion sort has been modified to print out the sorted component of the array during the sort. What will be the output of running the main method of the following code? Try to trace by hand and then verify by executing the code public class Insertion ( public static void sort (String[] a) f int n- a.length; for (int i-1; i < n; i++) f for (int j i; j 0; j--) if...

  • When asked to describe an algorithm you are expected to give a clear pseudo-code description of...

    When asked to describe an algorithm you are expected to give a clear pseudo-code description of the algorithm 1. (10 pts) Here is a new sorting algorithm NewSort Suppose the original call made is NewSort(A,0,n-1) where A is an array integers. == void NewSort(int A[], int i, int j){ \\ sorts the subarray Aſi..j] if (j i+1) \\when there are only 2 elements if (A[i] > A[j]) swap(A,i,j) \\swaps A[i] and A[j] else { int k = (j-i+1)/3; NewSort(A,i,j-k); \\...

  • Question No.1 [CLO 1][7 marks] 1. Consider the following pseudocode: Algorithm IterativeFunction (a, b) // a...

    Question No.1 [CLO 1][7 marks] 1. Consider the following pseudocode: Algorithm IterativeFunction (a, b) // a and b are integers while (a>0) B- a/2 A a-2 end while return b; i. What is the time complexity of the IterativeFunction pseudocode shown above? ii. What is the space complexity of the IterativeFunction pseudocode shown above? 2. What is the time complexity of the following algorithm (Note that n(n+1) 2,2 n(n+1)(2n+1) 2 and ): Provide both T(n) and order, e(f(n)). int A=0;...

  • How would I be able to get a Merge Sort to run in this code? MY...

    How would I be able to get a Merge Sort to run in this code? MY CODE: #include <iostream> #include <fstream> #include <stdlib.h> #include <stdio.h> #include <time.h> using namespace std; class mergersorter { private:    float array[1000] ;    int n = 1000;    int i=0; public:    void fillArray()    {        for(i=1;i<=n;i++)        {            array[i-1]= ( rand() % ( 1000) )+1;        }    }    void arrayout ()    {   ...

  • Do anyone knows how to write this in java?    You are allowed to use the...

    Do anyone knows how to write this in java?    You are allowed to use the following methods from the Java API: class String length charAt class StringBuilder length charAt append toString class Character any method moveXDownLeft takes a char and a two dimensional array of char as input and returns nothing: The method should find the first occurrence of the char in the array (searching from "top" to "bottom" and "left" to "right"), and it should slide that character...

  • I need help fixing my code: In C++ *************** 1) I want to sum the digits...

    I need help fixing my code: In C++ *************** 1) I want to sum the digits of an n*n matrix 2) find the average I have completed the rest ****Do not use C++ standard library. You must use pointers and pointer arithmetic to represent the matrix and to navigate through it. MY CODE: (I have indicated at which point I need help) #include <iostream> using namespace std; void swap(int *xp, int *yp) { int temp = *xp; *xp = *yp;...

  • QUESTION 12 If an array contains unordered values, searching for a particular value O is accomplished...

    QUESTION 12 If an array contains unordered values, searching for a particular value O is accomplished with a linear search is accomplished with the bipolar search O can't be done in Java O requires multiple parallel processing threads QUESTION 13 What best describes the processing of the following method? public static t[] mystery (int[] list) int[] result = new int[list.length]; j 1; for (int i = 0, result.length i < list.length; i++, j--) { result[j] = list[i]; } return result;...

  • The following program sorts the array of numbers entered by the user and prints out the...

    The following program sorts the array of numbers entered by the user and prints out the elements in descending order. It has many errors. Debug the code and show the output. #include <stdio.h> #define N 4 void desc(float *a, float *b) float tp; tp=a; a=b; b=tp; int main() int i, j, ii, mark[N] ; for (ii==0;ii<N;ii++) printf("Enter the %d th element of your array: \n",ii); scanf("%d", mark[ii]); printf("You have entered the following array: \n"); for (ii=0,ii<N,ii++) printf("%d ", mark[ii]); printf("\n...

  • Consider the following pseudocode: Algorithm RecursiveFunction (a, b) // a and b are integers if (as1...

    Consider the following pseudocode: Algorithm RecursiveFunction (a, b) // a and b are integers if (as1 ) return b; else return RecursiveFunction (a-2, a/2); endif a. What is the time complexity of the RecursiveFunction pseudocode shown above? b What is the space complexity of the RecursiveFunction pseudocode shown above? n(n+1) C. What is the time complexity of the following algorithm (Note that 21-, i = n(n+1)(2n+1). and Σ.,1 ): Provide both T(n) and order, Ofn)). int A=0; for (int i=0;i<n;i++)...

  • 1. What is the output of the following code segment? int array[] = { 8, 6,...

    1. What is the output of the following code segment? int array[] = { 8, 6, 9, 7, 6, 4, 4, 5, 8, 10 }; System.out.println( "Index Value" ); for ( int i = 0; i < array.length; i++ ) System.out.printf( "%d %d\n", i, array[ i ] ); 2. What is the output of the following code segment? char sentence[] = {'H', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u' }; String output = "The sentence...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT