Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Solutions to Chapter One Questions

1. ___________ is the process of executing a correct program on data sets and measuring the time and space it takes to
compute the results?
Ans. Profiling
2. Define algorithm? What are its properties?
Ans.
An algorithm is a set of instructions that provide step-by-step specifications to perform a task.
The properties of an algorithm are:
Input: Specifies the data set that is applied to the algorithm to check its validity.
Output: Specifies the data set that is produced as a result of the algorithm execution.
Definiteness: Specifies that the instructions described in the algorithm should be well
defined and should not create any ambiguity.
Termination: Specifies that the instructions described in the algorithm must contain a
proper termination condition.
Effectiveness: Specifies that the algorithm take less time and less memory space during
its execution.
3. What is debugging and what is profiling?
Ans.
Debugging is the process of identifying and fixing the errors in a program. Errors in a program can be identified by
executing the program with a sample dataset.
Profiling is the process of measuring the performance of the program by executing it on different data sets. Performance
of a program is measured by recording the time and memory space that the program takes during its execution.
4. One of the properties of an algorithm is beauty (true/false)
Ans. False
Solutions to Chapter Two Questions
1. Give at least 5 real life examples where we use stack operations.
Ans.
The real life examples of stacks are:
Bangles in a hand: The bangles wore in a hand follow last-in-first-out (LIFO) strategy of
stack. The bangle that you wear first is the last one to be taken out while removing all the
bangles from the hand. The bangle that is worn last is the first one to be taken out.
Same circumference circular rings in a pole: The rings having same circumference
placed into a pole also follow LIFO strategy. The topmost ring, which was the last to be
placed in the pole, is the first one to be taken out.
Sacks full of wheat placed one over other: The sack at the top is removed first and the
sack at the bottom is removed last.
The bolts screwed to a single nut: When the bolts are screwed to a single nut, the last
screwed bolt is unscrewed first and the bolt that was screwed first is unscrewed in the last.
Battery cells in a torch: The battery cells in a torch also follow the same LIFO strategy of
stack.
2. Give at least 5 real life examples where queue is used.
Ans.
Real life examples of queue are:
A queue of people at ticket-window: The person who comes first gets the ticket first. The
person who is coming last is getting the tickets in last. Therefore, it follows first-in-first-out
(FIFO) strategy of queue.
Vehicles on toll-tax bridge: The vehicle that comes first to the toll tax booth leaves the
booth first. The vehicle that comes last leaves last. Therefore, it follows first-in-first-out
(FIFO) strategy of queue.
Phone answering system: The person who calls first gets a response first from the phone
answering system. The person who calls last gets the response last. Therefore, it follows
first-in-first-out (FIFO) strategy of queue.
Luggage checking machine: Luggage checking machine checks the luggage first that
comes first. Therefore, it follows FIFO principle of queue.
Patients waiting outside the doctor's clinic: The patient who comes first visits the doctor
first, and the patient who comes last visits the doctor last. Therefore, it follows the first-infirst-
out (FIFO) strategy of queue.
3. Name 10 situations that can be represented by means of graphs. Explain what each vertex and edge represents.
Ans.
The situations that can be represented by means of graphs are:
Example Vertex represents Edge represents
Displacement Position or state Distance between the two vertices
connected through the edge
Shortest Path City Distance between the two vertices
connected through the edge
City Map Places of the city Distance between the two vertices
connected through the edge
Air route Different airports Distance between the two vertices
connected through the edge
Population Growth per
year
Population for an year Variation in the population between the
two vertices connected through the
edge
In mathematical
expressions
Value Conditions and calculations
Daily temperature
report
Temperature for a
specific time
Variation in the temperature between
the vertices connected through the
edge
Child-parent
relationship
Name of the person Relationship
Organization chart

You might also like