Maths

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

Q.1 What is an Algorithm? What are its characteristics?

Ans - An algorithm is a sequence of instructions that solves a particular


problem and produces a result. It is a set of instructions to be executed in
a certain order to achieve a specific output. An algorithm is a well-
defined set of instructions or steps to solve a problem.

Characteristics of an Algorithm -
1. Its complexity can vary greatly, and it must have inputs and an output.
2. The input types should be known beforehand, and it must always
produce an output.
3. An algorithm should be clear, unambiguous, competent with available
resources, and should have independent step-by-step directions.
4. The characteristics of an algorithm include finiteness, input, output,
definiteness, and effectiveness.
5. It should have at least one output, and the instructions should be clear
and simple.
6. There are no well-defined standards for writing algorithms, and it is
problem dependent.
7. The efficiency of an algorithm is decided by time and space used by
the algorithm, which includes the running time and storage space required
by an algorithm in terms of input data size.

Q.2 Simple Algorithms.


Example 1. Write an algorithm to find out the cube of a number.
Solution. In this problem, the number whose cube is to be calculated is
given. Its cube is calculated and then displayed.
The steps of the algorithm are :
Step 1: Start.
Step 2: Input first number as a.
Step 3: Calculate their cube as c = a * a * a, where c is another number in
which cube is stored.
Step 4: Display c.
Step 5: Stop.

Example 2. Write an algorithm to find out the compound interest


when principal, rate of interest and time is given.
Solution. In this problem, the principal P, rate of interest r and time t is
given. The compound interest I is to be calculated by formula I = P x r x t
/ 100 and displayed.
The steps of the algorithm are:
Step 1. Start.
Step 2. Input principal as P.
Step 3. Input rate of interest as r.
Step 4. Input time as t
Step 5. Calculate their interest as I = Pert 0.01, where I is another number
in which interest is stored.
Step 6. Display I
Step 7. Stop.

Example 3. Write an algorithm to find the sum of two numbers.


Solution. In this problem, two numbers are given. Their sum is to be
calculated and then displayed.
The steps of the algorithm are:
Step 1. Start.
Step 2. Input first number as a.
Step 3. Input second number as b.
Step 4. Calculate their sum as c = a + b, where c is another number in
which their sum is stored.
Step 5. Display c.
Step 6. Stop.

Example 4. Write an algorithm to find greatest among three


numbers.
Solution. In this problem, three numbers a, b and c are given. The greatest
number among them is to determined and displayed.
The steps of the algorithm are:
Step 1. Start
Step 2. Input numbers a, b and c.
Step 3. If a ≥b then greater a else greater = b.
Step 4. If greater ≥ c then greatest = greater else greatest = c.
Step 5. Display greatest.
Step 6. Stop

Example 5. Write an algorithm to calculate f(x), where

{
4
x if x is even
f(x) = for all integers x.
¿ x 4 if x is odd

Solution. The steps of the algorithm are:


Step 1. Start
Step 2. Input integer as x.
Step 3. If x is even then calculate c=x*x*x*x else c=x*x
Step 4. Display c
Step 5. Stop.

Example 6. Write an algorithm to check an integer for even or odd.


Solution. The steps of the algorithm are
Step 1. Start
Step 2. Input an integer as NUM
Step 3. Calculate their remainder as R when NUM is divided by 2.
Step 4. If R = 0, then display "Even" else display "Odd"
Step 5. Stop.

Example 7. Write an algorithm to find the G.C.D. (Greatest Common


Disisior) of two numbers.
Solution. In this problem, two numbers a and b whose g.c.d is to be
calculated are given. The g.c.d. of a and b is to be calculated and
displayed.
Step 1. Start
Step 2. Input first number as a.
Step 3. Input second number as b.
Step 4. If b = 0 then goto step 5th
Step 5. While (b≠0) Do
Begin temp = a
a=b
b= remainder of temp when divided by b
End
Step 6. If a = 0 then display "we cannot find g.c.d." else display g.c.d. is
"a".
Step 7. Stop.

Example 8. Write an algorithm for factorial computation.


Solution. In this problem, the number whose factorial is to be calculated
is given. Its factorial is to be computed and displayed.
The steps of the algorithm are:
Step 1. Start
Step 2. Input number N.
Step 3. Set fact. = 1.
Step 4. If N = 0 then fact. = 1.
Step 5. Set K = 1.
Step 6. Repeat step 6 for K 1 to N.
Step 7. fact = K fact.
Step 8. Display fact.
Step 9. Stop.

Example 9. Write an algorithm to reverse a given number.


Solution. The steps of the algorithm are
Step 1. Start
Step 2. Input an integer as NUM
Step 3. Assume reverse as REV = 0
Step 4. While (NUM 0) Do
Begin
R = Remainder of NUM when divided by 10.
NUM = Quotient when NUM is divided by 10.
REV= REV*10+R
End
Step 5. Display Reverse as REV
Step 6. Stop.

Q.3 What are Merits and Demerits of Algorithm?


Ans - Merits -
1. It is a step by step procedure, which is very easy to understand
2. It is easy to debug, so that errors can be easily pointed out.
3. It is independent of programming languages.
4. It helps to create the program.
5. It has a beginning and end within which there are defined steps to
produce output within a specified period of time.
Demerits:
1. No standard is available.
2. If the problem is lengthy and complex, then it becomes space
consuming, lengthy and lack of clarity.
3. Difficulty to modify or alter
4. Not a natural way of expressing procedure as writing in English.

Q.3 What are the measures of central tendency?


Ans - A measure of central tendency is a summary measure that attempts
to describe a whole st of data with a single value that represents the
middle or centre of its distribution.
There are three main measures of central tendency: the mode, the median
and the mean. Each of these measures describes a different indication of
the typical or central value in the distribution.

Q.4 What is the mode?


Ans - The mode is the most commonly occurring value in a distribution.

Consider this dataset showing the retirement age of 11 people, in whole


years:

54, 54, 54, 55, 56, 57, 57, 58, 58, 60, 60

This table shows a simple frequency distribution of the retirement age


data.
Age Frequency
54 3
55 1
56 1
57 2
58 2
60 2

The most commonly occurring value is 54, therefore the mode of this
distribution is 54 years.

Q.5 What is main advantage of mode over the median and the mean?
Ans - The advantage of mode over the median and the mean is that it can
be found for both numerical and non-numerical data.

Q.6 What is the median?


Ans - The median is the middle value in distribution when the values are
arranged in ascending or descending order.

The median divides the distribution in half. In a distribution with an odd


number of observations, the median value is the middle value. Looking at
the retirement age distribution (with 11 observations), the median is the
middle value, which is 57 years:

54, 54, 54, 55, 56, 57, 57, 58, 58, 60, 60

When the distribution has an even number of observations, the median


value is the mean of the two middle values. In the following distribution:

52, 54, 54, 54, 55, 56, 57, 57, 58, 58, 60, 60

The two middle values are 56 and 57; therefore the median equals 56.5
years:

Q.7 What is the mean?


Ans - The mean is the sum of the value of each observation in a
distribution divided by the number of observations. Looking at the
retirement age distribution:

54, 54, 54, 55, 56, 57, 57, 58, 58, 60, 60
The mean is calculated by adding together all the values
(54+54+54+55+56+57+57+58+58+60+60-623) and dividing by the
number of observations (11) which equals 56.6 years.

Q.8 What is the difference between mean, median and mode?


Ans -
Mean:-
The mean, or average, is calculated by summing all of the observed
values and dividing by the number of observations. The mean is the
simplest way to summarise a single variable and it is generally the best
measure of central location for purposes of statistical inference.

Median:-
The median is the middle value of a set of observations. There are as
many observations above the median as there are below it. To find the
median, observations must be arranged in order of value. Median is
useful for variables such as age, income, turnover and housing prices.

Mode:-
The mode is the most commonly observed data item in a data set. A set of
data can have more than one mode. The mode is useful when the most
common item, characteristic or value of a data set is required.

Q.9 Define Directed Graph?


Ans - A directed graph is that in which each edge has specific direction.

In a directed pair (V₁,V₂)

V₁, is called the tail or initial vertex.

V₂ is called the head or final vertex..

For example,

Consider the following directed graph G₁.


Here :-

V(G₁) (1, 2, 3, 4, 5)

E(G₁)=((1, 2), (2, 3), (3, 4), (4, 5), (5, 1), (1,3), (5, 3))

The arrow is always from tail vertex to head vertex. Thus in an undirected
graph, pair of vertices representing any edge is unordered i.e. (v, w) and
(w, v) represent the same edge whereas in the directed graphs each edge
is an ordered pair of vertices i.e. each edge is represented by a directed
pair. So in an directed graph (v,w) and (w, v) represent two different
edges.

Q.10 Define Complementary Graph?


Ans - The complement of a simple graph G(V, E) is defined as a graph
G'(V,F) which has same number of vertices as in graph G and two
vertices in graph G' are connected if and only if they are not connected in
graph G i.e. in G' the vertices u and v are connected by an edge if and
only if there is no edge between u and v in G.
In simple words, suppose a graph G is a set of vertices some of which are
connected by edges. Assume here that no two vertices are connected by
more than one edge. The complementary graph G' of G has the same
vertices as G and two vertices are connected in G' if and only if they are
not connected in G.

For example, the complement of graph G is the graph G' as shown


below:-

Q.11 Define Bipartite Graph.


Ans - Bipartite Graph:-

A simple graph G is said to be bipartite graph if set of vertices V of G can


be partitioned into two disjoint sets V₁ and V₂ such that each edge of G
join the vertex of V₁ with V₂ i.e. there does not exist any edge joining
two vertices in V₁ or V₂.

If m and n are the number of vertices in V₁ and V₂ respectively then


bipartite graph is represented by Km. n.

For example,
G is bipartite because its vertex set V = {1, 2, 3, 4, 5, 6) is partitioned into
two non empty sets V₁ = {1, 3, 5} and V₂ = {2. 4, 6). Every edge in G
connects a vertex in V₁, and a vertex in V₂.

Q.12 Define Complete Bipartite Graph?


Ans - A graph Km,n is said to be complete bipartite graph if every vertex
of V1, is adjacent to every vertex of V2.

As each of m vertices of V1, is connected to each of n vertices of V2.

Total number of edges in Km.n = m.n.

For example,
The graphs shown below are complete bipartite graphs.

Q.13 Define Complete graph OR fully connected graph.


Ans -
(a) An undirected complete graph of n vertices is a graph in which each
vertex is connected to every other vertex.
A complete graph of n vertices is also called an n-clique and is denoted
by Kn.
A complete graph with n vertices will have n(n-1)/2 edges.
For example,
Given below is a complete graph of 4 vertices.

(b) An n vertices directed graph with exactly n(n-1) edges is said to be


complete graph.

For example,

Given below is a complete directed graph of 3 vertices.

Q.14 Define Strongly connected graph.


Ans - A directed graph G is said to be strongly connected if for every pair
of distinct vertices Vi, Vj in V(G) there is a directed path from Vi to Vj
and also from Vj to Vi.
For example -
Consider the following directed graphs -
Here -
(a) Graph G1 is strongly connected graph.
(b) Graph G2 is weakly connected graph because there does not exist a
directed path from vertex 3 to other vertices and so on.

Q.15 Define Planar Graph.


Ans - A planer graph is one that can be drawn on a plane in such a way
that there are no “edges crossings,” i.e. edges intersect only at their
common vertices.

Q.16 Define Regular Graph.


Ans - A graph G(V,E) is said to be a regular graph if the degree of all
vertices in the graph are same. A graph G is called a k-regular graph if
degree of each vertex of G is k all the vertices of G are of same degree k.
A complete graph Kn of n vertices is also a(n-1) regular graph.
For example, the graph G1 is 2-regular graph and graph G2 is 3-regular
graph.

Q.17 Define Rooted Tree with the help of example.


Ans - If a directed tree has exactly one node or vertex called root whose
in-degree is zero and all other vertices have in-degree one, then the tree is
called rooted tree.

For example -
A is the root of this tree. No edge enters A, but several may leave and we
draw these edges downward.

Q.18 Define Complete Binary Tree with the help of example?


Ans - A strictly binary tree is called a complete binary tree if all the leaf
nodes are at the same level. In other words, a binary tree is called
complete binary tree if the number of nodes at level n are 2n for all values
of n.
Example -

Q.19 Define Ordered rooted Tree with the help of example?


Ans - A rooted tree in which the children of every internal vertex are
linearly ordered is called an ordered rooted tree. Ordered rooted trees are
drawn so that the children of each internal vertex are shown in order from
left to right.
Q.20 Describe Isomorphic Graph with suitable example.
Ans - Two graphs G1 and G2 are said to be isomorphic to each other if
there is a one to one correspondence between their vertices and between
their edges such that if the edge e is incident on vertices V₁ and V2 in
graph G1 then the corresponding edge e' in G2 must be incident on the
vertices V₁' and V2' that correspond to V₁ and V2 respectively.
For example - The graphs G1 and G2 are isomorphic because of the
existence of mapping a - V₁,. b - V2, c - V3 , d - V4 and e - V5 Under this
mapping the edges 1,2,3,4,5,6 are mapped into e1,e2,e3,e4,e5,e6 respectively
which are the only edges of the graph.

Q.21 Describe Incidence Matrix with suitable example?


Ans - Suppose G is an undirected graph with m nodes V1, V2.….,Vm and
n edges e1, e2, ........, en. The incidence matrix of G is the m × n matrix M
= (mij) where
{
mij = 1 if node Vi
¿
belongs edge ej ¿ ¿ 0 otℎerwise ¿

There is a row for every vertex and a column for every edge in the
incidence matrix.
The number of one's in an incidence matrix of undirected graph without
loops is equal to the sum of degrees of all the vertices of the graph.
For example,
Graph G has 5 nodes V1, V2, V3, V4, V5 and 8 edges e₁, e2, 23, 24, 25,
26, 27, eg as given below:-

The incidence matrix m of the above graph G is shown below -


Q.22 Describe Eulerian Path with suitable example.
Ans - A path in a graph G is called an Ruler path if it includes every edge
exactly once.
For example -
The path A, B, C, D, B is an Euler path.

Q.23 Describe Haniltonian Path with suitable example.


Ans - A Hamiltonian path is a path that contains each vertex exactly once.
For example -
The path A, B, C, D is a Hamiltonian path.

Q.24 Describe Weighted Graph with suitable example.


Ans - A graph is said to be weighted graph if every edge in the graph is
assigned some weightage. It is denoted by w(e).
It is a non-negative value that may represent the cost of moving along
that edge or distance between the vertices.

For example,
Consider the following undirected weighted graph:-
w(e1) = 4, w(e3) = 7,
w(e4) = 4, w(e6) = 5,

Q.25 Define Subgraphs.


Ans - Let G and G' be two graphs and V(G) and V(G') be the sets of
vertices of the graphs G and G' such that V(G') V(G). If in addition, every
edge of G' is also an edge of G then the graph G' is called a sub graph of
graph G and is written as G' G.

Thus G' is a sub graph of G, if


1.All the vertices of G' are in G.
2.All the edges of G' are in G and
3.Each edge of G' has the same end vertices of G' as in G.

The graphs shown in figures (b), (c), (d) and (e) are each a sub graph of
the graph shown in figure (a).

Q.26 Define Homemorphic Graph.


Ans - Two graphs G1 and G2 are called homeomorphic graphs if G2 can
be obtained from G1 by a sequence of subdivisions of the edges of G1. In
other words, we can introduce vertices of degree two in any edge of graph
G2.
For example,

These two graphs G1 and G₂ are homeomorphic because G₂ can be


obtained from G1 by introducing vertices of degree two on edges(V5. V₁)
and (V4. V2)

Q.27 Define graph?


Ans - A graph G is defined as that which consists of two sets V and E
where
1.V is finite non empty set of vertices.
2.E is set of pair of vertices, these pairs are called edges.

V(G) represents the set of vertices of graph G. E(G) represents the set of
edges of graph G. G=(V, E) is used to represent the graph.
For example -
Consider the following graph G

Here -
V(G) = {1,2,3,4,5}
E(G) = {(1,2),(2,3),(3,4),(4,5),(5,1).(1,3),(3,5)}

Q.28 Define Euler circuits.


Ans - A Euler circuit is a Ruler path in which the initial vertex appears
second time as the terminal vertex.
For example -
The path 1,2,3,4,5,3,1 is an Ruler Circuit.

Q.29 Define Hamiltonian Circuits.


Ans - A Hamiltonian Circuit is a circuit that contains each vertex once
except for the first vertex, which is also the last vertex.
For example -
The path A,B,C,D,A is a Hamiltonian Circuit.

Q.30 Define Tree.


Ans - A graph is called a tree if it has the following properties -
1. It is connected.
2. There is no cycle in the graph.

A cycle is a circuit whose edge list contains n duplicates.


For example, three different trees on five vertices are -
Q.31 Define Binary Tree.
Ans - If the degree of every node is less than or equal to two, then that
tree is called a binary tree.
A binary tree is either empty or has a finite number of nodes.
e.g.

Q.32 What is Big Oh Notation?


Ans - The notation f(n) = O(g(n)) read as f of n equals big Oh of g of n,
has a precise mathematical definition.

Definition:- f(n) = O(g(n)) iff there exists two constants k and k1 such that
| f(n) | ≤ k | g(n) for all n ≥k1.

Where

1. f(n) normally represents the computing time of some algorithm.

2. n is a parameter which characterizes the input and/or outputs.

Thus this definition means that the computing time of an algorithm is


O(g(n)).
n may be the number of inputs or the number of outputs or their sum or
the magnitude of one of them.
Thus this definition simply states that the execution time of an algorithm
can't increase faster than product of a constant k and function g(n).
The order of the function f(n) is the same as the order or degree of the
term in the function.
For example,

1. f(n) = n + 5 then order of f(n) is 1 and in big 0 notation it is


represented as O(n), called linear time.

2. f(n) n3 + 5n² + 12 then order of f(n) is 3 and in big


O notation it is represented as O(n³).

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy