1/39
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
program
algorithms that have been specialized to a specific set of conditions and assumptions.
Can the words program and algorithm be used interchangeably?
They shouldn't be!
heuristic process
helpful procedure for finding a result, often an approximation for a solution.
What are the five steps for creating an algorithm?
1) Input Specified
2) Output Specified
3) Definiteness
4) Effectiveness
5) Finiteness
True or False? Algorithms CAN be specified at different levels of detail
True
True or False? Algorithms NEVER build on functionality previously defined and known to the user
False; it should be ALWAYS
True or False? Two different algorithms can be used to get the SAME solution in different amounts of time
True; the solutions can be equal even if one algorithm is much more complex than the other
Flowchart
A visual representation of the sequence of events to be performed by the algorithm
Consider the following JavaScript code segment:
var a = Number("23" + "321") / 1000;var b = a.toFixed(2);
What is the final value of b?
23.32
A Boolean value can only be either true or false
True
In JavaScript, the statement var x, y = 4; will assign the value 4 to:
A) y only
B) neither x nor y
C) both x and y
D) x only
A
Select all that apply. Which of the following is(are) required of an algorithm?
A) It must be executable without further external support.
B) It must specify every step and the order the steps must be performed.
C) It must, eventually, end.
D) Input and output must be specified.
All of the above
When creating a flowchart, the symbol for a decision is the parallelogram and the symbol for an assignment is a rectangle.
False
Select all that apply. Which of the following are valid variable declarations?
A) myName = "Snoopy";
B) var 1stName;
C) var x;
D) var myName = 23;
B, C, and D
In JavaScript, the statement 17 % 5 results in
A) 3
B) 0.175
C) 2
D) 3.4
C
var i = 28; if ( i / 2 % 2 > 0 ) {
document.write("The number is an odd integer");
}
else {
document.write("The number is an even integer");
}
What is displayed when the code segment above is executed?
A) The number is an even integer.
B) The number is an odd integer.
C) Nothing is printed. The result of the computation is equal to 0.
D) Nothing is printed. There is a runtime error.
A
What is the final value of z after following JavaScript code segment is executed?
var x = 12, y = 9;
var z = x / 2 + y / 3 + "88" ;
988
What is the value of the variable shipping if cost = 50 and country = "Canada"?
if (cost < 50 && country == "Canada")
shipping = 6.00;
if (cost < 100 && cost > 49 && country == "Canada")
shipping = 9.00;
else
shipping = 12.00;
A) 12.00
B) 6.00
C) 9.00
D) cannot tell since the else clause does not specify the conditions
C
True or False?
var green = -5;
The expression ! (green) will change the sign of the value on the variable green.
False
Assume the following JavaScript variable assignments have been made:
var a = 2, b = 4;
The Boolean expression a == 4 || b > 2 evaluates to _____?
A) True
B) False
True
Consider the following code segment.
var a = 3;
var b = 8;
var c = 4;
a = a + 1;
b = b - 1;
c = c + a;
What are the final values of a, b, and c?
a = 4
b = 7
c = 8
The condition on the if statement below to set the taxRate to 0.15 for the residents of the states of New Jersey and New York would be (assume the variable state has been declared and has a value):
if (condition)
taxRate = 0.15;
A) state == "NJ" && state == "NY"
B) state == "NJ" || state == "NY"
C) state == "NJ" && "NY"
D) state = "NJ" || state = "NY"
B
What is output?
var x = 10;
if (x > 5) {
x = 1;
}
else {
x = 0 ;
}
document.write(x);
A) nothing is output
B) 1
C) 0
D) 10
B
True or False? If a function definition contains two parameters, two arguments must be included in the function call.
True
True or False? Variables in the parameter list of a JavaScript function are declared automatically.
True
If you wanted the following function to return only the two values of 0 and 1, how would you re-write line 2?
function tossIt( ) {
return Math.random( );
}
A) return Math.round(random());
B) return Math.round();
C) This cannot be done.
D) return Math.round(Math.random());
D
True or False? A function definition is the same as a function call.
False. Defining a function says what the function is, while calling a function determines when/where you are using it.
True or False? Local variables cannot be accessed outside the functions in which they are declared.
True
How many iterations will occur in the following loop?
for(var again = 0; again < 5; again++) {
...
}
A) four
B) six
C) five
D) cannot tell
C
Which of the following is the correct code for the step size of the loop shown to ensure that the loop will repeat exactly five times?
for ( c = 3; c < 13; ________)
A) c = c + 2
B) c++
C) c = c + 3
D) c = c + 4
A
If you have a nested loop structure where the outside loop runs five times and the inside loops runs seven times, the statements of the inside loop will be executed ________ times.
A) twelve
B) seven
C) thirty-five
D) five
C
Which of the following statements is TRUE about the following JavaScript declaration?
var rows = new Array(5);
A) The last item in the array will be rows[5].
B) The first item in the array will be rows[0].
C) All of these are true.
D) The array will have six items.
B
Consider the JavaScript code segment below:
var choco = new Array("Hershey", "M&M", "Godiva", "Cadbury");
var yumCandy = choco[choco.length - 1];
What us the value of yumCandy>:
A) M&M
B) Cadbury
C) Hershey
D) Godiva
B
True or False? It is possible to set up a loop that never iterates.
True
Which of the following is an infinite loop?
A) for (k = 1; k <= 4; k = k - 1)
B) for (k = 1; k < 3; k = k + 1)
C) for (k = 0; k <= 10; k = k + 1)
D) for (k = 1; k <= 4; k = k + 1)
A
Consider the following JavaScript code segment.
var sum = 0;
var arr = new Array(7,1,6,9,4);
for(var i = 2; i < arr.length; i++){
sum += arr[i];
}
document.write(sum);
What is displayed when this code is executed?
A) 19
B) 20
C) 27
D) Nothing would be printed; An error would occur.
A
Which of the following is the correct way to declare an array named myArray with ten elements?
A) var myArray = new(10);
B) new myArray = Array(10);
C) var myArray = new Array(10);
D) myArray = new var(10);
C
An algorithm is a(n)
A) list of general nonspecific steps to produce an output
B) logarithm
C) systematic method for producing a specified result
D) math problem
C
Algorithms must always
A) produce output
B) produce output or state that there is no solution
C) produce input or state that there is no solution
D) state that there is no solution
B
Given this array: var cars = new Array(9); which of the following is a valid way of accessing a valuewithin the array.
A) cars[9]
B) cars[7.5]
C) cars[0]
D) cars[10]
C