You are on page 1of 30

Solutions to Chapter One Questions1.

___________ is the process of executing a correct program on data sets and measuring the time and space it takes tocompute the results? Ans. Profiling2. 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 : S pecif i es t hat t he i nst r uct i ons descr i bed i n the al gori t hm shoul d be w el l defined and should not create any ambiguity. Termination : S pecif i es t hat t he i nst r uct i ons descr i bed i n the al gori t hm m ust cont ai n a proper termination condition. Effectiveness : Specifies that the algorithm take less time and less memory space duringits 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 byexecuting the program with a sample dataset.Profiling is the process of measuring the performance of the program by executing it on different data sets. Performanceof 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 Questions1. Give at least 5 real life examples where we use stack operations. Ans. The real life examples of stacks are: Ban g l es in a h an d : 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 thebangles from the hand. The bangle that is worn last is the first one to be taken out. S am e ci rcu m f eren ce ci rcul ar rin g s in a po le : The r i ngs havi ng sam e ci r cumf er encepl aced i nt o a pol e al so f oll ow LIF O st r at egy. The t opm ost r i ng, w hi ch w as t he l ast t o 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 thesack at the bottom is removed last. The bolts screwed to a single nut : When the bolts are screwed to a single nut, the lastscrewed 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 ticketwindow : The person who comes first gets the ticket first. Theperson who is coming last is getting the tickets in last. Therefore,

it follows first-infirst-out(FIFO) strategy of queue.

Vehicles on tolltax bridge : The vehicle that comes first to the toll tax booth leaves thebooth first. The vehicle

that comes last leaves last. Therefore, it follows first-infirst-out(FIFO) strategy of queue.

Phone answering system : The person who calls first gets a

response first from the phoneanswering system. The person who calls last gets the response last. Therefore, it followsfirst-in-firstout (FIFO) strategy of queue.

Luggage checking machine : Luggage checking machine checks the luggage first thatcomes 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 Ver tex r epre sent

sEdge re presents Displacemen tPosition or stateDistanc e between th e two vertic e s connected through the edgeS h o r t e s t PathCit

yDist ance between the two v e r t i c e s conn ected through the edgeC i t y M a p Places of th e cityDista nce betwee n the two v e r t i c e s connect

ed through the edge A i r r o u t eDifferent a irportsDist ance betwee n the two v e r t i c e s connect ed through the edgePopulation Growth per year Populati

on for an yearVariation in the population between thetwo vertices connected through theedgeIn mathematical expr essionsV a l u e Condition s and calc u l a t i o n s Dail

y temperaturereport Temperature for aspecific timeVariation in the temperature betweenthe vertices connected through theedgeChildparent relationshi

pN a m e o f t h e personRelatio nshipO r g a n i zation char tDesignati onOrder or f l o w Chemi cal structureChe mical elementsBond

ing between the elements 4. Draw a connected graph that becomes disconnected when any edge is removed from it. Ans.

The following figure shows a graph that becomes disconnected when any edge is removed from it: Disconnected Graph 5.

Draw all trees of n labeled vertices for n=1,2,3,4 and 5. Ans. The following figures show the trees for various values of n, where n represents the number of vertices

in a tree.For n=1For n=2For n =3There can be a number of trees with 3 labeled vertices. Some of the examples of the trees with 3 labeled vertices are

For n=4Again, there can be a number of trees with 4 labeled vertices. Some of the examples of the trees with 4

labeled verticesare:For n=5Again, there can be a number of trees with 5 labeled vertices. Some of the examples of the trees with 5

labeled verticesare

6. Sketch all binary trees with six pendent edges. Ans.

The following figures show binary trees with six pendent edges:

Binary Tree with Six Pendent Edges

The preceding figures, A, B, and C, show three examples of binary trees having six pendent edges. All the binary treeshaving six leaf nodes come

under this category

You might also like