Skip to content

This textbook is in beta – content is actively being refined. Report issues or suggestions

06.07 Code Optimisation And Assessing Effectiveness - Quiz

Check your understanding

  1. Which four dimensions are used to assess code effectiveness?

    • Speed, memory, disk space, network usage
    • Correctness, clarity, performance, maintainability { data-correct }
    • Syntax, logic, structure, documentation
    • Input, processing, output, storage
  2. What is the principle of “avoiding premature optimization”?

    • Never optimize code under any circumstances
    • Optimize everything from the beginning to save time later
    • Don’t optimize until you know where the bottlenecks actually are { data-correct }
    • Only optimize code that looks complex
  3. Which data structure choice would provide the best performance for frequent membership testing (checking if an item exists)?

    • List
    • Set { data-correct }
    • Tuple
    • String
  4. What is the most effective type of optimization for improving algorithm performance?

    • Using shorter variable names
    • Removing comments and whitespace
    • Choosing algorithms with better time complexity { data-correct }
    • Using more advanced language features
  5. When should you prioritize code readability over performance optimization?

    • Never - performance is always most important
    • When the performance gain is minimal and the code is not a bottleneck { data-correct }
    • Only in prototype code
    • When using interpreted languages
  6. What is the primary purpose of profiling code?

    • To check for syntax errors
    • To identify actual performance bottlenecks before optimizing { data-correct }
    • To count the number of lines of code
    • To verify code correctness
  7. Which of the following demonstrates better maintainability?

    • All code in one large method to avoid method call overhead
    • Code separated into focused methods with clear responsibilities { data-correct }
    • Using single-letter variable names to save typing
    • Avoiding comments to keep code concise
  8. In the context of Big O notation, which represents the best time complexity for a search algorithm?

    • O(n²)
    • O(n log n)
    • O(n)
    • O(1) { data-correct }
  9. What should you do first when you suspect a performance problem in your code?

    • Immediately start rewriting the slowest-looking parts
    • Profile the code to measure where time is actually spent { data-correct }
    • Switch to a faster programming language
    • Add more comments to understand the code better
  10. Which approach best balances all four dimensions of code effectiveness?

    • Write the fastest possible code regardless of readability
    • Focus only on making code work correctly, ignore other factors
    • Write clear, correct code first, then optimize identified bottlenecks { data-correct }
    • Optimize everything from the start to avoid later rewrites