Question

In: Computer Science

1. What will be the value of numbers[1] after the following code is executed? int[] numbers...

1. What will be the value of numbers[1] after the following code is executed?

int[] numbers = {22, 33, 44};

for(int k = 0; k < 3; k++)

{

numbers[k] = numbers[k] + 5;

}

}

2. What will be the results of the following code?

final int ARRAY_SIZE = 5;

double[] x = new double[ARRAY_SIZE];

for(int i = 1; i <= ARRAY_SIZE; i++)

{

x[i] = 10.0;

}

3.What is the value of numbers [3] after the following line of code executes?

int[] numbers = new int[5];

4.What would be the results after the following code was executed?

int[] x = {23, 55, 83, 19};

int[] y = {36, 78, 12, 24};

x = y;

y = x;

5.In order to do a binary search on an array,

Question 5 options:

a. the values of the array must be numeric.

b. the array must first be sorted in ascending order.

c. you must first do a sequential search of the array to assure the element you are looking for is there.

d. there are no requirements.

6. The ______ search repeatedly divides the portion of an array being searched in half.

7.What is the value of x after the following statements execute?

Int[] numbers = { 10, 20, 30, 40, 50 };

int x = numbers[2] + numbers[3];

8. The _________ search steps through an array, comparing each value to the search value.

9. What will be the value of x[1] after the following code is executed?

int[] numbers = {22, 33, 44};

arrayProcess(numbers[1]);

...

public static void arrayProcess(int a)

{

a = a + 5;

}

10.The sequential search algorithm

Question 10 options:

a. requires the array to be ordered.

b. must always be implemented as a method.

c. will not execute, if the element is not in the array.

d. uses a loop to sequentially step through an array, starting with the first element.

Solutions

Expert Solution

SOLUTION 1.>

int [] numbers={22,33,44};

for(int k=0;k<3;k++)

{

numbers[k]=numbsers[k]+5;

}

output:->

this code will increase the value of each element

of array by 5 so new array will be like numbers[]={27,38,49};

numbers[]={27,38,49}

hence numbers[1] is 38

CORRECT ANSWER IS : 38

SOLUTION 2.>

ARRAY_SIZE=5;

double[]x=new double[ARRAY_SIZE];

for(int i=1;i<=ARRAY_SIZE;i++)

{

x[i]=10.0;

}

OUTPUT:

All element of X array will become 10.0

hence array will look like this X[]={10.0,10.0,10.0,10.0,10.0};

SOLUTION 3.>

value of numbers[3] will be garbage values because

array is not initialized with any values

SOLUTION 4.>

on assigning (x=y)

x become y so x={36, 78, 12, 24};

and y become x then y={36, 78, 12, 24};

so correct answer is both become same and equal to y

x={36, 78, 12, 24};

y={36, 78, 12, 24};

SOLUTION 5.>

In order to do binar search on array array must be sorted

becaues binary search uses mid to reduce the search space after every

iteration

so correct option is :

[ b. the array must first be sorted in ascending order.]

SOLUTION 6.>

THE _BINARY_SEARCH _ search repeatedly divides the portion of an array being

searched in half.

CORRECT ANSWER IS : BINARY SEARCH

EXPLAINATION :

binary search first find mid then it compare x with value at mid

if(x>a[mid])

then goes to right half for search

else

it goes to left part for searching .

SOLUTION 7.>

int[] numbers = { 10, 20, 30, 40, 50 };

int x = numbers[2] + numbers[3]

numbers[2]=30;

numbers[3]=40;

hence (numbers[2] + numbers[3]) = 70

so x=70

correct answer: 70

SOLUTION 8.>

CORRECT ANSWER : The __LINEAR__ search steps through an array, comparing each value

to the search value.


explaination:

The linear search check each values of array and compre with x

if matches then return result.

eg:

int search(int x,int arr[],int n)

{

for(int i=0;i<n;i++)

{

if(arr[i]==x)

return(i);

}

}

-->

this is linear search return once value of arr[i] matches with x

and return index at which x present at array

SOLUTION 9.>

CORRECT ANSWER IS :38


EXPLAINATION:

int[] numbers = {22, 33, 44};

numbers[1]=33 because value at index in array is 33

now we are passing it in arrayProcess(numbers[1])

so 33 is passed in arrayProcess(33) function and this function

increase values by 5 since (a=a+5 inside function )

so correct result is 33+5 becomes 38


SOLUTIO 10.>

CORRECT OPTION IS (d)

EXPLAINATION:

The sequential search algorithm ->

d. uses a loop to sequentially step through an array, starting with the first element.



Related Solutions

1) What's the contents of array vals after the following code is executed? int[] vals =...
1) What's the contents of array vals after the following code is executed? int[] vals = {6, 1, 4, 5, 1}; int size = vals.length; for(int i = 0; i < size; i++) vals[i] = vals[i] * i; q) [ 6, 1, 4, 5, 1 ] b)[ 0, 1, 2, 3, 4] c)[0, 1, 8, 15, 4] d)[6, 2, 12, 20, 5] 2) Consider function foo defined below: static int[] foo(int vals[]) { int result[] = new int[vals.length - 1];...
JAVA programing language: What is printed when the following code is executed? int columns; int rows;...
JAVA programing language: What is printed when the following code is executed? int columns; int rows; for(rows = 1; rows < 2; ++rows) { for(columns = 1; columns < 3; ++columns) { System.out.print("x"); } System.out.println(): } select one: A) xx B) xxx xxx C) x x D) xx xx xx
What is the value of n after this code runs? 1 Point int n = 0;...
What is the value of n after this code runs? 1 Point int n = 0; int j = 7; if ((j!=0) && (n < 25)) { n = 1; if (j > 4) { n = 2; } else { n = 3; } } else { n = 4; if (j%2 >= 2) { n = 5; } else { n = 6; } }
What is the value stored in variable perimeter after the code has been executed? (6 pts)...
What is the value stored in variable perimeter after the code has been executed? (6 pts) .data               length:        .word 16               width:        .word 24               perimeter:     .word 0        .text               la $s0, length               la $s1, width               la $s2, perimeter               lw $s3,0($s0)               lw $s4, 0($s1)               add $s3, $s3, $s3               add $s4, $s3, $s4               add $s5, $s3, $s4               sw $s5, 0($s2) Perimeter:__________________________________________
1)What is the output of the following code? struct someType { int a; int b; };...
1)What is the output of the following code? struct someType { int a; int b; }; void f1(someType &s) { s.a = 1; s.b = 2; } someType f2(someType s) { someType t; t = s; s.a = 3; return t; } int main() { someType s1, s2; f1(s1); s2 = f2(s1); cout << s1.a << '-' << s1.b << '-' << s2.a << '-' << s2.b << '-' << endl; return 0; } ------------------------------------------------------------------------------------------------------------------ 2) struct dateType { int...
What is the ouput of the following code? void loop(int num) { for(int i = 1;...
What is the ouput of the following code? void loop(int num) { for(int i = 1; i < num; ++i) { for(int j = 0; j < 5; ++j) { cout << j; } } } int main() { loop(3); return 0; }
[after §3.22 − easy] String Processing : Consider the following code fragment: 1 int a =...
[after §3.22 − easy] String Processing : Consider the following code fragment: 1 int a = 20; 2 int b; 3 double x = 3.5; 4 String s = "All"; 5 char ch; 6 7 x += a; 8 x--; 9 a /= 4 - 1; 10 b = s.length(); 11 b += 4; 12 s += "is well"; 13 ch = s.charAt(b); 14 System.out.println("a = " + a + ", b = " + b); 15 System.out.println("x = "...
What is the Opcode? What is the Operand? What is the value in Register 5 after the instruction is executed?
What is the Opcode? What is the Operand? What is the value in Register 5 after the instruction is executed?
c++ programming What will the following C++ code display? int numbers[4]={99,87}; cout<<numbers[3]<<endl; 87                     &nbs
c++ programming What will the following C++ code display? int numbers[4]={99,87}; cout<<numbers[3]<<endl; 87                            b. 0                                  c. garbage                        d. an error What is the output of the following program segment? double mylist[5]; for(int i=0; i<5; i++) mylist[i]= (pow(i,2)+ 1 /2.0; cout<<fixed<<showpoint<<setprecision(2); for(int i=0; i<5; i++) { cout<<setw(5)<<mylist[i]; }               a. .5           1.5        4.5        9.5        16.5               b. 0.50      1.50      4.50      9.50     16.50              c. 0.50      1.50      8.50     27.50     64.50             d. 0.50      1.50      2.50      3.50      4.50      15. what is stored...
1. What is value of X after following operation int X=0x 45; X = X<<3 ;...
1. What is value of X after following operation int X=0x 45; X = X<<3 ; X= What is value of X after following operation int x=0x 40; X = X>>3 ; X= What is value of X after following operation int x=0X FF; X = X & 0x0F; X= What is value of X after following operation int x=0x FF; X = ~X ; X= What is value of X after following operation int X=0x FF; X = X...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT