Please Help!!! 1. We can estimate the ________ of an algorithm by counting the n
ID: 3554044 • Letter: P
Question
Please Help!!!
1.
We can estimate the ________ of an algorithm by counting the number of
steps it requires to solve a problem.
A) efficiency
B) number of lines of code
C) run time
D) code quality
E) result
-------------------------------
Your Answer: A
2.
The ________ sort usually performs more swaps/exchanges than the ________
sort.
A) bubble, selection
B) selection, bubble
C) binary, linear
D) linear, binary
E) linear, bubble
-------------------------------
Your Answer: A
3.
A search can be performed on an array of ________ .
A) integers
B) strings
C) objects
D) All of the above
E) A and B, but not C
-------------------------------
Your Answer: D
4.
To find a value that is in an unordered array of 1000 items, binary
search must examine at most ________ values.
A) 7
B) 10
C) 50
D) 20
E) 100
-------------------------------
Your Answer: B
5.
A(n) ________ search is more efficient than a(n) ________ search.
A) string, double
B) integer, double
C) binary, linear
D) linear, binary
E) None of the above; all searches are equally efficient.
-------------------------------
Your Answer: C
6.
The output produced by the code below:
float * f;
float m = 14.5;
f = new float(m);
cout << * f;
-------------------------------
Your Answer: 14.5
7.
Consider the declaration below:
struct Circle
{
float radius;
};
Directions: Write a statement to declare a pointer named Cp, that
can point to a Circle.
_____________________________ //HERE
-------------------------------
Your Answer: STRUCT CIRCLE *CP;
8.
Consider the declaration below:
struct Circle
{
float radius;
};
Directions: Write a statement to declare a pointer named Cp, that
can point to a Circle.
_____________________________ //HERE
-------------------------------
Your Answer: STRUCT CIRCLE *CP;
9.
Consider the code below.
struct Q {int x; char a; Q * nextQ;}
Q myQ;
_______________________________
DIRECTION: Set the nextQ field of record myQ so that it does not point
to anything.
-------------------------------
Your Answer: MYQ->NEXTQ = NULL;
10.
Consider the code below.
const float PI = 3.14159;
struct Q {int x; char a; float * f;};
Q myQ;
_______________________________
DIRECTION: Set the f field of myQ to point to the value 3.14159.
NOTE: DO NOT declare any new variables.
-------------------------------
Your Answer: MYQ->*F = &PI;
11.
Write the statement to cause sptr to point to record You.
struct STUD
{
int ID; string Name; float GPA;
};
STUD You = {1234,"Justice",0.00};
STUD * sptr;
_________________________________________________
-------------------------------
Your Answer: STUD *SPTR = &YOU;
12.
Declare a struct named FELINE with three fields:
fat (an int)
cat (a float)
sibling (pointer to a FELINE)
______________________________________
-------------------------------
Your Answer: STRUCT FELINE { INT FAT; FLOAT CAT; FELINE*SIBLING;}
13.
The base (stopping) case of a recursive function ________.
A) is 0
B) is 1
C) is depth / 2
D) is 1 / (depth * 3.1415)
E) depends on the problem being solved
-------------------------------
Your Answer: E
14.
The function
int fact(int k)
{
return k*fact(k-1);
if (k==0) return 1;
}
A) computes the factorial of the integer parameter k parameter
B) returns the value 1 if it is passed the value 0
C) does not correctly handle its base (stopping) case
D) works for non-negative values of k, but not for negative values
E) None of the above
-------------------------------
Your Answer: A
15.
(T/F) Any algorithm that can be coded with recursion can also be
coded using a loop.
-------------------------------
Your Answer: T
16.
The programmer must ensure that a recursive function not become ________.
A) a static function
B) a prototyped function
C) trapped in an infinite chain of recursive calls
D) a dynamic function
E) None of the above
-------------------------------
Your Answer: C
17.
To find a value that is in an unordered array of 100 items, linear
search must examine an average of ________ values.
A) 7
B) 10
C) 50
D) 100
E) 101
-------------------------------
Your Answer: 100
18.
A ________ algorithm arranges data into some order.
A) sorting
B) searching
C) ordering
D) linear
E) binary
-------------------------------
Your Answer: A
19.
In a linear search, each element of an array is examined, starting
with the first element, until an element is reached that matches
the search key. If no match is found, the search failed.
Directions: Write the statement for LINE2.
bool LinearSearch(int Key, int A[], int First, int Last)
{
for (int i=First; i <= Last; i++)
{
if (Key == A[i])
__________________________ // LINE1
}
____________________________ // LINE2
}
-------------------------------
Your Answer: NO Answer
20.
A selection sort based on maximum value is being used to arrange the
following list of numbers into ascending order:
8 6 4 9 3 7
After the second pass of the sort is completed, what order will the
data be in?
A) 8 6 4 7 3 9
B) 3 4 6 7 8 9
C) 3 6 4 9 8 7
D) 3 6 4 7 8 9
E) None of the above
-------------------------------
Your Answer: D
21.
In a linear search, each element of an array is examined, starting
with the first element, until an element is reached that matches
the search key. If no match is found, the search failed.
Directions: Write the statement for LINE1.
bool LinearSearch(int Key, int A[], int First, int Last)
{
for (int i=First; i <= Last; i++)
{
if (Key == A[i])
__________________________ // LINE1
}
____________________________ // LINE2
}
-------------------------------
Your Answer: NO ANSWER
22.
A bubble sort is being used to arrange the following set of numbers
into ASCENDING order:
7 5 3 9 2 6
After the SECOND pass of the sort is completed, what order will the
data be in?
A) 2 5 3 9 7 6
B) 2 3 5 6 7 9
C) 5 3 7 2 6 9
D) 3 5 2 6 7 9
E) None of the above
-------------------------------
Your Answer: D
23.
[Points = 1]
(T/F) The ampersand (&) is used to dereference a pointer variable in C++.
-------------------------------
Your Answer: F
24.
________ can be used as pointers.
A) Array names
B) C++ string objects
C) Punctuation marks
D) All of the above
E) None of the above
-------------------------------
Your Answer: A
25.
Assuming that arr is an array identifier, the statement sum += *arr; ________.
A) adds the value stored in arr[0] to sum
B) is illegal in C++
C) will always result in a compiler error
D) adds the address of the pointer arr to sum
E) None of the above
-------------------------------
Your Answer: B
Explanation / Answer
11. STUD *sptr = &You
12. STRUCT FELINE { int fat; FLOAT cat; FELINE*sibling;}
13. E
14. A
15. True
16. C
17. 100
18. A
19. return false
20. D
21. return true
22. D
23. False
24. A
25. D(assigns the dereferenced
pointer's value, then increments the pointer's address)