HW-1

docx

School

The City College of New York, CUNY *

*We aren’t endorsed by this school

Course

103

Subject

Computer Science

Date

Jan 9, 2024

Type

docx

Pages

3

Uploaded by BaronPuppyPerson1126

Report
HW-1 / Chapter 1 “The Phases of Software Development” 1. Why is writing easily modifiable code important? A. Easily modifiable code generally has a quicker run time. B . Most real-world programs require change at some time. C. Most text editors make it easy to modify code. D. Several people may be writing the same function at the same time. 2. Which phase of the software life-cycle is usually the most expensive? A. Analysis and specification of the task B. Design C. Implementation D . Maintenance and evolution 3. What will happen if a function is executed and the precondition for the function is not met? A. An error message will be printed. B. The program will loop indefinitely. C. The system will crash. D . Any of the above results could happen. * 4. Answer true or false for this statement: When programming in teams, the specification of a function should be written by the person writing the code for the function. TRUE. FALSE . 5. If the precondition fails, it is a good idea to write a useful error message and then halt the program. Why is the program halted? A. Most operating systems forbid continuation. B . The function is no longer guaranteed to make the postcondition true. C. The function's memory requires have become exponential (or worse). D. The function's running time has become exponential (or worse). 6. Which of these functions can be used to stop the program execution when a precondition is not met. A . assert(); B. exit(); C. return(); D. void(); 7. Which of these function calls will cause an exception to be thrown when x is 23. (x is an int variable). A. if (0 == x) throw std::invalid_argument(“Wrong x”); B . if (0 < x) throw std::invalid_argument(“Wrong x”); C. if (0 > x) throw std::invalid_argument(“Wrong x”); D. None of the above will cause an exception when x is 23.
8. Determine which of the following formulas is O(n) : A. 16 n 3 B . n 2 + n + 2 C. | n 2 /2| D . 10 n + 25 9. What does a run-time analysis usually count? A . The number of arithmetic and other operations required for the program to run B. The number of megabytes required for the program to run C. The number of seconds required for the program to run D. The number of seconds plus the number of megabytes E. The number of seconds times the number of megabytes 10. Here is some code for an  integer  variable n: while (n > 0) { n = n/10; // Use integer division } What is the worst-case time analysis for the above loop? A. O(1) B . O(log n) // Any algorithm which   cuts the problem in half   each time is O(log n). C. O(n) D. O(n²) 11. What term is used to describe an O(n) algorithm. A. Constant B . Linear C. Logarithmic D. Quadratic 12. Why is it important to test boundary values when testing programs? A. Calculating by hand, it's easy to find the right answers for boundary values. B. Debuggers are easier to use when testing boundary values. C . In practice, a large proportion of errors arise from boundary values. D. The correct execution of a function on all boundary values proves a function is correct. 13. Which software tool will best help you determine whether your test cases are fully exercising your code? A. Compiler B. Debugger C. Make D. Pine E . Profiler
14. Which of these statements will always cause a program to halt? (x is an int variable). A. assert(10 > 0); B . assert(10 < 0); C. assert(x < 0); D. None of the above will always cause a program to halt. 15. (Optional) Each of the following are formulas for the number of operations in some algorithm. Express each formula in big- O notation. A. n 2 + 5 n { O(n 2 ) } B. 3 n 2 + 5 n { O(n 2 ) } C. ( n + 7)( n 2) { O(n 2 ) } D. 100 n + 5 { O(n) } E. 5 n + 3 n 2 { O(n 2 ) } F . The number of digits in 2 n { O(log n) } Suppose that a number has x digits (x!=0). Then this number will be between 10 x-1 and 10 x -1. That means the numeric value of the x-digit number is exponential as a function of x. G. The number of times that n can be divided by 10 before dropping below 1.0 { O(log n) } Just like in question #10.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help