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.
Bubble Sort Swap and Comparison Counts29 questions
Classifying Computational Problems25 questions
Well-defined and Ill-defined Problems23 questions
Complexity Class P20 questions
Generate-and-Test Method26 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.