Algorithms and Problem Solving

Computer Science, HSSC-Punjab First Year. This chapter is split into 62 topics and has 1,453 practice questions. The topics covered are listed below, followed by 10 free sample questions from the chapter.

Topics in this chapter

  1. Complexity Class NP and Sudoku 23 questions
  2. Bubble Sort Pass Tracing 26 questions
  3. Bubble Sort Special Cases 22 questions
  4. Greedy Algorithms 21 questions
  5. Selection Sort Pass Tracing 26 questions
  6. Breadth-First Search Concept 23 questions
  7. Linear Search Tracing 30 questions
  8. Tractable and Intractable Problems 21 questions
  9. Even Number Flowchart 26 questions
  10. Identifying Algorithm Design Techniques 23 questions
  11. Binary Search Concept 24 questions
  12. Linear Search Concept 21 questions
  13. Merge Sort Final Lists and Merge Counts 24 questions
  14. Traveling Salesman Problem 24 questions
  15. The Halting Problem 21 questions
  16. Depth-First Search Concept 23 questions
  17. Exercise Short Questions Review 25 questions
  18. Computational Problems Input Process Output 24 questions
  19. Binary Search Step Counts 29 questions
  20. Complexity Class Relationships and P versus NP 22 questions
  21. Exercise MCQ Review 22 questions
  22. Algorithmic Thinking and Learning Outcomes 24 questions
  23. Algorithm Analysis Time and Space Complexity 22 questions
  24. NP-hard and NP-complete Problems 24 questions
  25. Big O Growth Calculations 21 questions
  26. Search Algorithms Overview 21 questions
  27. Comparing Linear and Binary Search 23 questions
  28. Algorithms for Problem Solving 21 questions
  29. Bubble Sort Concept 23 questions
  30. Comparing BFS and DFS 23 questions
  31. Complexity Class Scenarios 20 questions
  32. Binary Search Tracing Midpoints 23 questions
  33. Graphs Basics 27 questions
  34. Binary Search Worked Examples 23 questions
  35. Pairwise Comparisons and Halving Guesses 21 questions
  36. Big O Notation Classes 26 questions
  37. DFS Visiting Order Tracing 28 questions
  38. Tracing Simple Algorithms 30 questions
  39. Backtracking 22 questions
  40. Greedy Coin Change Calculations 27 questions
  41. Growth of Asymptotic Notations Graph 20 questions
  42. Comparing Sorting Algorithms 23 questions
  43. Sorting Algorithms Overview 21 questions
  44. Mixed Algorithm Review 24 questions
  45. BFS Visiting Order Tracing 28 questions
  46. Euclidean Algorithm and GCD 21 questions
  47. Merge Sort Comparisons and Levels 23 questions
  48. BFS Distances and Layers 28 questions
  49. Dynamic Programming Fibonacci Calculations 21 questions
  50. BFS and DFS on a Tree 21 questions
  51. Knapsack Problem 20 questions
  52. Divide and Conquer 22 questions
  53. Selection Sort Concept 20 questions
  54. Selection Sort Counts and Variants 21 questions
  55. Exercise Long Questions Review 25 questions
  56. Dynamic Programming 20 questions
  57. Solvable and Unsolvable Problems 23 questions
  58. Bubble Sort Swap and Comparison Counts 29 questions
  59. Classifying Computational Problems 25 questions
  60. Well-defined and Ill-defined Problems 23 questions
  61. Complexity Class P 20 questions
  62. Generate-and-Test Method 26 questions

Sample questions: Algorithms and Problem Solving

10 sample questions with the correct answer and an explanation. Try to answer each one before reading the explanation.

Q1. A program converts a temperature entered in Celsius into Fahrenheit using F = C × 9/5 + 32. Which item is the input of this problem?

  • A. The Fahrenheit temperature that is displayed
  • B. The multiplication by 9/5 and addition of 32
  • C. The program file stored on the disk
  • D. The Celsius temperature typed by the user(correct answer)

Answer: D.The input is the data supplied at the start (the Celsius value); the formula is the process and the Fahrenheit value is the output.

Q2. A program takes three marks of a student and finds the largest one. What is the output?

  • A. The name of the student
  • B. The three marks typed by the student
  • C. Comparing the marks with each other
  • D. The largest of the three marks(correct answer)

Answer: D.The output is the final result produced, which is the largest mark; the three marks are input and the comparisons are the process.

Q3. To solve a problem computationally, which three things must be identified first?

  • A. The name of the programmer, the date and the size of the saved file
  • B. The compiler, the text editor and the operating system installed
  • C. The programming language, the monitor size and the keyboard layout of the computer
  • D. The inputs, the desired outputs and the process that turns inputs into outputs(correct answer)

Answer: D.Characterising a problem means identifying its inputs, desired outputs and the process needed to transform one into the other.

Q4. Two programs both take a whole number n as input. Program A prints yes if n is prime; Program B prints the list of all primes up to n. What is the difference in the output?

  • A. Both give a list of numbers
  • B. Both give exactly one yes/no answer
  • C. A gives one yes/no answer while B gives a list of numbers(correct answer)
  • D. A gives a list of numbers while B gives one yes/no answer

Answer: C.The output differs: A's output is a single yes/no decision while B's output is a collection of primes, even though the input is the same.

Q5. Which statement correctly separates an optimization problem from a search problem?

  • A. An optimization problem needs any solution at all, while a search problem needs the best one
  • B. A search problem always counts the solutions, an optimization problem lists them
  • C. An optimization problem needs the best solution, a search problem only needs one that meets the criteria(correct answer)
  • D. An optimization problem always gives a yes or no answer, while search counts

Answer: C.Optimization ranks candidate solutions and picks the best by some criterion; search just locates a satisfying solution or item.

Q6. Which is NOT a reason the book gives for studying algorithms?

  • A. They help solve complex problems
  • B. They provide the logic behind software operations
  • C. They reduce the physical size of computers(correct answer)
  • D. They help optimize performance

Answer: C.The book names logic of software, solving complex problems, optimizing performance and accuracy; size of computers is not mentioned.

Q7. In which field is the Generate-and-Test method often used?

  • A. Weather forecasting by looking at the shape of clouds
  • B. Artificial intelligence, such as game playing and problem solving(correct answer)
  • C. Printing and binding of books in a publishing house
  • D. Cable manufacturing and the testing of plugs and wires

Answer: B.The book says it is often used in AI applications where the solution space is large and different possibilities are tried until one works.

Q8. The list [12, 37, 6, 40, 36, 57, 17] is partly sorted by one pass of Selection Sort and, separately, by one pass of Bubble Sort (both ascending). Which list does the Selection Sort pass give?

  • A. [12, 37, 6, 40, 36, 57, 17]
  • B. [6, 12, 17, 36, 37, 40, 57]
  • C. [6, 37, 12, 40, 36, 57, 17](correct answer)
  • D. [12, 6, 37, 36, 40, 17, 57]

Answer: C.Selection Sort moves the minimum to the front ([6, 37, 12, 40, 36, 57, 17]), unlike Bubble Sort's [12, 6, 37, 36, 40, 17, 57].

Q9. The list [51, 53, 38, 28, 59, 8, 30] is partly sorted by one pass of Selection Sort and, separately, by one pass of Bubble Sort (both ascending). Which list does the Selection Sort pass give?

  • A. [8, 28, 30, 38, 51, 53, 59]
  • B. [51, 53, 38, 28, 59, 8, 30]
  • C. [51, 38, 28, 53, 8, 30, 59]
  • D. [8, 53, 38, 28, 59, 51, 30](correct answer)

Answer: D.Selection Sort moves the minimum to the front ([8, 53, 38, 28, 59, 51, 30]), unlike Bubble Sort's [51, 38, 28, 53, 8, 30, 59].

Q10. A tree has root 0; node 0 has children 1, 2 and 3; node 1 has children 4 and 5; node 2 has child 6; node 3 has child 7. A stack-based DFS pops a node and pushes its unvisited children in ascending order (so the largest child is popped first). What is the visiting order?

  • A. 4, 5, 1, 6, 2, 7, 3, 0
  • B. 0, 3, 7, 2, 6, 1, 5, 4(correct answer)
  • C. 0, 1, 4, 5, 2, 6, 3, 7
  • D. 0, 1, 2, 3, 4, 5, 6, 7

Answer: B.The stack pops 3 first, then 7, then 2, 6, then 1, 5, 4: this order differs from the book's DFS output because the children are pushed in ascending order.

Take a full practice exam on this chapter

Mix every topic of the chapter, get instant explanations, and track your accuracy over time.

Create a free account
An unhandled error has occurred. Reload 🗙