csc 222 exam 2

¡Supera tus tareas y exámenes ahora con Quizwiz!

A _____ describes the operation performed by the recursive algorithm. condition statement reduction step base case method

c

A recursive algorithm is based on _____ application(s) of the same algorithm on smaller problems. zero single repeated infinite

c

A user can directly interact with the OS through ___________. the internet a Program that uses Graphical User Interfaces typing in commands on the keyboard to a command line terminal the mouse

c

Binary search begins at the ______ of the range. last element given index midpoint first element

c

Identify the base case in the following code. public class FindMatch { public static int findMatch(char array[], int low, int high, char key) { if (high >= low) { int mid = low + (high - low) / 2; if (array[mid] == key) { return mid; } if (array[mid] > key) { return findMatch(array, low, mid, key); } else { return findMatch(array, mid + 1, high, key); } } return -1; } } if (array[mid] > key) int mid = low + (high - low)/2; if (array[mid] == key) if (high>=low)

c

In the following code, the variable indentAmt _____ at each recursive call. public static int sum(int n, String indentAmt) { int sum = 0; if (n == 0) { System.out.println(indentAmt + "your value is: " + n); return 0; } else { System.out.println(indentAmt + "your value is: " + n); sum = n + sum(n - 1, indentAmt + " "); } System.out.println(indentAmt + "Returning pos = " + n); return sum; } remains constant is incremented or decremented based on the call is incremented is decremented

c

What is output? public class RecursionExample { public static void printer() { System.out.println("hello"); printer(); } public static void main(String[] args) { printer(); } } hello hello hello hello stack overflow hello hello

c

What is output? public class UnitTest{ public int square(int value) { return value * 1; } public static void main(String[] args) { UnitTest testObject = new UnitTest(); if(testObject.square(3) != 9) { System.out.println("Error: square(3)"); } if(testObject.square(1) != 1) { System.out.println("Error: square(1)"); } if(testObject.square(-1) != 1) { System.out.println("Error: square(-1)"); } System.out.println("Tests complete."); } } } Tests complete. Error: square(3) Tests complete. Correct! Error: square(3) Error: square(-1) Tests complete. Error: square(3) Error: square(1) Error: square(-1) Tests complete.

c

Which XXX completes the following code? public class MyGCDCalculator { public static int findGCD(int inNum1, int inNum2) { int tempVal; if (inNum1 == inNum2) { tempVal = inNum1; } else { if (inNum1 > inNum2) { XXX } else { tempVal = findGCD(inNum1, inNum2 - inNum1); } } return tempVal; } public static void main (String[] args) { int num1 = 25; int num2 = 15; int returnVal; returnVal = findGCD(num1, num2); System.out.println("Greatest common divisor = " + returnVal); } } tempVal = findGCD(inNum1 + inNum2, inNum2); tempVal = findGCD(inNum1, inNum2); tempVal = findGCD(inNum1 - inNum2, inNum2); tempVal = findGCD(inNum1 - inNum2, inNum2 - iNum1);

c

Which of the following activities can be accomplished using recursive algorithms? Writing a letter to a friend Making lemonade Harvesting crops Going to the supermarket to buy groceries

c

Why is having a Version Control system is so Important? It allows software to be fully test by providing version links into the testable units of the software. It allows multiple programmers to safely work on different programs. It allows the merging of code from different programmers working on the same program. It allows other programmers to see what another programmer is currently working on.

c

A _____ describes the operation performed by the recursive algorithm. reduction step method condition statement base case

d

After the following code prints "yz", what is the next call to remix()? public class RemixChars { public static void remix(String rmn, String chsn) { if (rmn.isEmpty()) { System.out.println(chsn + rmn); } else { for (int i = 0; i < rmn.length(); ++i) { remix((rmn.substring(0, i) + rmn.substring(i + 1, rmn.length())), (chsn + rmn.charAt(i))); } } } public static void main(String args[]) { remix("yz", ""); } } remix("yz", ""); remix("", "yz"); remix("z", "y"); remix("y", "z");

d

Features of a good testbench include: At least 90% code coverage Messages for all tests that pass Test cases for all possible values Answer Border cases and extreme values

d

The command line can be used to _______________. navigate to a directory run graphical programs shut down the computer All of these

d

What is output? public class WordScramble { public static void wordScramble(String rem, String scr) { if (rem.isEmpty()) { System.out.println(scr + rem); } else { for (int i = 0; i < rem.length(); ++i) { wordScramble((rem.substring(0, i) + rem.substring(i + 1, rem.length())), (scr + rem.charAt(i))); } } } public static void main(String args[]) { wordScramble("123", ""); } } 321 312 231 213 132 123 123 123 132 123 132 213 231 312 321

d

What is the main function of a Debugging Tool? Automatically correct errors in a program. Allow a programmer to examine how individual instructions are working. Document errors in a program. Allow the programmer to examine how their program is working.

d

Which XXX completes the following code? import java.util.Scanner; public class GuessMyAge { public static void myGuess(int low, int high, Scanner scnr) { int mid; char userAnswer; mid = (low + high) / 2; System.out.print("Is it " + mid + "? (</>/=): "); userAnswer = scnr.next().charAt(0); if ((userAnswer != '<') && (userAnswer != '>')) { System.out.println("Great!"); } else { if (userAnswer == '>') { XXX } else { myGuess(low, mid, scnr); } } } public static void main(String[] args) { Scanner scnr = new Scanner(System.in); myGuess(0, 100, scnr); } } myGuess (low, high, scnr ); myGuess(low, mid, scnr); myGuess (mid, high, scnr); myGuess(mid + 1, high, scnr);

d

For commercial software, testing consumes a large percentage of time. True False

true

Regression testing means to check if a change to an item caused previously-passed test cases to fail. True False

true

A break point is set when _________. the programmer wants to pause the program to see what the state of the variables are at that point in the program the programmer wants to end a program that has bad data in its variables the programmer wants to display the contents of a variable to the user a program detects an error in its data.

a

A debugger can step through a program when _____________ the programmer sets a break point which pauses the program, and then begins stepping through the program. an error is detected by the debugger that pauses the program, and then begins stepping through the program one line at a time. the user activates debug mode to check code. a system level error occurs that causes an interrupt in the program.

a

A stack overflow typically causes a program to _____. crash give an incorrect output give multiple outcomes return a value

a

In the following code, the variable indentAmt _____ at each recursive call. public static int sum(int n, String indentAmt) { int sum = 0; if (n == 0) { System.out.println(indentAmt + "your value is: " + n); return 0; } else { System.out.println(indentAmt + "your value is: " + n); sum = n + sum(n - 1, indentAmt + " "); } System.out.println(indentAmt + "Returning pos = " + n); return sum; } is incremented is decremented is incremented or decremented based on the call remains constant

a

What are the three basic types of Version Control Systems? Central, Distributed, Local Central, Aligned, Linked Local, Controlled, Open Linked, Distributed, Independent

a

What does the command line or terminal allow the user to do? directly interact with the operating system directly interact with a program directly interact with the hard drive directly interact with the monitor

a

What is a simple method that a programmer can use to identify when a variable does not contain the expected value? Insert print statements to display the value of variables Insert print statement to ask the user what the correct value should be Insert a user request to change the value of an incorrect variable. Insert a program exit if a value is incorrect.

a

What is the primary purpose of Version Control Software? Keeps track of multiple versions of a program. Keep track of bug fixes. Keep track of who worked on a program.

a

When using a centralized VCS, what two things must happen to be able to see your changes in a program? you commit, they update you update, they update you commit, they commit you update, they commit

a

Which of the following recursive methods will result in a stack overflow when main() calls fact(10)? public static int fact(int n) { if (n == 100) return 1; else return n*fact(n-1); } public static int fact(int n) { if (n < 100) return 1; else return n*fact(n-1); } public static int fact(int n) { if (n != 100) return 1; else return n*fact(n-1); } public static int fact(int n){ if (n <= 100) return 1; else return n*fact(n-1); }

a

________ provides an integrated development environment (IDE) for rapidly developing Java programs. Editing, compiling, building, debugging, and online help are integrated in one graphical user interface. Java IDE Java JDK Java API Java language specification

a

Identify the true statement about choosing a recursive method. It's not mandatory to cover all base cases. The problem naturally has a recursive solution. A recursive solution is always better than a non-recursive solution. Reaching a base case everytime is not necessary.

b

What information is kept in the VCS? Programmer identity and how many hours they worked on a project. Informs us about Who, What, When, Why changes have been made. Tracks user interactions with new versions. Allows programmers to debug specific methods within a version.

b

Which calculation does not have a natural recursive solution? Fibonacci Percentage Greatest common divisor Factorial

b

Which is true? Passing all test cases ensures a program is bug free A testbench should only print messages when a test case fails A testbench should test all possible values Calling every method once ensures 100% code coverage

b


Conjuntos de estudio relacionados

MS3 - Ch. 40: Musculoskeletal Care Modalities

View Set

PED 103 Honors Chapter Questions

View Set

BIOL 1030 Mastering Biology Chapter 40

View Set

Facebook Targeting: Lookalike Audiences

View Set