Gate
Gate
Gate
ALGORITHM ANALYSIS
ISBN : 9789386146250
2
C.g(n)
No
f(n) Matter
F(n)
ALGORITHM ANALYSIS AND DESIGN
Any Algorithm must satisfy the following criteria (or
Properties) n0
n
1. Input: It generally requires finite number of inputs. Fig. 1
2. Output: It must produce at least one output. For all values of n to the right of n 0, the value of f(n) is always lies
3. Uniqueness: Each instruction should be clear and on or below Cg(n).
unambiguous. THE NOTATION (BIG 'Omega')
4. Finiteness: It must terminate after a finite number of steps. O-Notation provides as asymptotic upper bound for a function;
-Notation provides as asymptotic upper bound for a function;
ASYMPTOTIC NOTATIONS -Notation, provides an asymptotic lower-bound for a given
function.
These notations are used to describe the Running time of an
algorithm, in terms of functions, whose domains are the set of We say that the function f (n) ( g (n))) [read as "f of n is big
natural numbers, N = {1, 2, ……}. Such notations are convenient "Omega" of g of n"], if and only if there exist two positive
for describing the worst case running time function. T(n) (problem constants C and n0 such that
size input size). The complexity function can be also be used to f (n) C.g (n) : n n0
compare two algorithms P and Q that perform the same task. The
basic Asymptotic Notations are:
1. O(Big-"Oh") Notation. [Maximum number of steps to solve
a problem, (upper bound)]
2. (Big-"Omega") Notation [Minimum number of steps to C.g(n)
No
solve a problem, (lower bound)] f(n) Matter
3. (Theta) Notation [Average number of steps to solve a f(n) = g(m)
problem, (used to express both upper and lower bound of a F(n)
given )f(n)).
50. Consider the following algorithm for searching for a given (a) 29 (b) 31
number x in an unsorted array A [l ...n] having n distinct (c) 38 (d) 41
values
55. The following are the starting and ending times of
1. Choose an i uniformly at random from l ...nf
2. If A [i] = x then stop else Goto 1; activities A, B, C, D, E, F, G and H respectively in
Assuming that x is present A, what is the expected chronological order :
number of comparisons made by the algorithm before it as bs cs ae ds ce es fs be de gs ee fe hs ge he. Here, xs denotes
terminates? [2002, 2 Marks] the starting time and xe denotes the ending time of
(a) n (b) n – 1
activity X. We need to schedule the activities in a set of
n
(c) 2n (d) rooms available to us. An activity can be scheduled in a
2
51. The running time of the following algorithm room only if the room is reserved for the activity for its
Procedure A (n) entire duration. What is the minimum number of rooms
If n < = 2 return (1) else return (A( n )); required? [2003, 2 Marks]
(a) 3 (b) 4
is best described by [2002, 2 Marks]
(a) O (n) (b) O (log n) (c) 5 (d) 6
(c) O (log log n) (d) O (1) 56. Let G = (V, E) be a directed graph with n vertices. A path
52. The cube root of a natural number n is defined as the from vi to vj in G is a sequence of vertices (vi, v i + 1,...., vj)
largest natural number m such that m3 n. The such that (vk , vk + 1) E for all k in i through j – 1. A
complexity of computing the cube root of n (n is simple path is a path in which no vertex appears more
represented in binary notation) is [2003, 2 Marks]
than once. Let A be an n × n array initialized as follows
(a) O(n) but not O(n0.5)
(b) O(n0.5) but not O(log n)k for any constant k > 0 1, if ( j, k) E
(c) O (( log n)k) for some constant k > 0 but not O A [ j, k] =
0, otherwise
((log log n)m) for any constant m > 0
(d) O (( log log n)k) for some constant K > 0.5 but not Consider the following algorithm :
O ((log log n)0.5) for i = 1 to n
53. Let G = (V, E) be an undirected graph with a subgraph for j = 1to n
G1= (V1, E1). Weights are assigned to edges of G as for k = 1 to n
follows A [j, k] = max (A [j, k], A [j, i ] + A [i, k]) ;
0, if e E1 Which of the following statements is necessarily true for
(e )
1, otherwise all j and k after termination of the above algorithm?
A single – source shortest path algorithm is executed on [2003, 2 Marks]
the weighted graph (V, E, w) with an arbitrary vertex v1 (a) A [j, k] n
of V1 as the source. Which of the following can always
be inferred from the path costs computed? (b) If A [j, j] n – 1, then G has a Hamiltonian cycle
[2003, 2 Marks] (c) If there exists a path from j to k, A [j, k] contains the
(a) The number of edges in the shortest paths from v1 longest path length from j to k
to all vertices of G (d) If there exists a path from j to k, every simple path
(b) G1 is connected
from j to k contains at most A [j, k] edges
(c) V1 forms a clique in G
(d) G1 is a tree 57. Let A [1,....., n] be an array storing a bit (1 or 0) at each
54. What is the weight of a minimum spanning tree of the location, and f(m) is a function whose time complexity is
following graph? [2003, 2 Marks] (m). Consider the following program fragment written in
a C like language :
b 2 g 19 counter = 0;
j
6 for (i = 1; i < = n; i + +)
1 c 3 8
a 2 14 { if (A [i] = = 1) counter + + ;
2 5
15 else {f (counter) ; counter = 0;}
d h
4 }
4
8 9 The complexity of this program fragment is
8 f i
11 [2004, 2 Marks]
2
(a) (n ) (b) (n log n) and O(n2)
2
e (c) (n) (d) O (n)
12
58. The time complexity of the following C function is Which are depth first traversals of the above graph?
(assume n > 0) (a) 1, 2 and 4 (b) 1 and 4
int recursive (int n) { (c) 2, 3 and 4 (d) 1, 3 and 4
if (n = = 1) 64. In the following C function, let n m
return (1) ; int gcd (n, m)
else {
return (recursive (n – 1) + recursive (n – 1); if (n % m == 0) return m;
} [2004, 2 Marks] n = n % m;
(a) O (n) (b) O (n log n) return gcd (m, n);
(c) O (n2) (d) O (2n) }
59. The recurrence equation How many recursive calls are made by this function?
[2007, 2 Marks]
T (1) = 1
(a) (log2 n) (b) (n)
T (n) = 2T (n – 1) + n, n 2
evaluates to [2004, 2 Marks] (c) (log2 log n) (d) n
2
(a) 2n + 1 – n – 2 (b) 2n – n
65. What is the time complexity of the following recursive
(c) 2n + 1– 2n – 2 (d) 2n + n
function?
60. Given the following input (4322, 1334, 1471, 9679, 1989,
int Dosomething (int n) {
6171, 6173, 4199) and the hash function x mod 10. Which it (n < = 2)
of the following statements are true? [2004, 1 Mark] return 1;
(1) 9679, 1989 , 4199 hash to the same value. else
(2) 1471, 6171 hash to the same value. return (Dosomething (floor (sqrt (n))) + n);
(3) All elements hash to the same value } [2007, 2 Marks]
(4) Each element hashes to a different value. (a) 2
(n ) (b) (n log2 n)
(a) 1 only (b) 2 only
(c) (log2 n) (d) (log2 log2 n)
(c) 1 and 2 (d) 3 or 4
66. Consider the following graph :
61. The tightest lower bound on the number of comparisons,
in the worst case, for comparison – based sorting is of 2
the order of [2004, 1 Mark]
(a) n (b) n2 b d
1 4
(c) n log n (d) n log n2 1
62. Consider the following three claims : a 3 2 3 f
5
1. (n + k)m = (nm), where k and m are constants 6
n+1 n c 4 e
2. 2 = O(2 )
3. 22n + 1 = O(2n) 7
Which of these claims are correct? [2003, 1 Mark]
(a) 1 and 2 (b) 1 and 3 Which one of the following cannot be the sequence of
(c) 2 and 3 (d) 1, 2 and 3 edges added, in that order, to a minimum spanning tree
63. Consider the following graph : [2003, 1 Mark] using Kruskal’ algorithm? [2006, 2 Marks]
(a) (a – b), (d – f), (b – f), (d – c), (d – e)
(b) (a – b), (d – f), (d – c), (b – f), (d – e)
a (c) (d – f), (a – b), (d – c), (b – f), (d – e)
(d) (d – f), (a – b), (b – f), (d – e), (d – c)
67. A set X can be represented by an array x [n] as follows
1, if i X
x[i]
0 , otherwise
e b f
Consider the following algorithm in which x, y and z are
h Boolean arrays of size n :
algorithm zzz (x[], y[], z []) {
int i;
for (i = 0; i < n; + + i )
z [i] = (x[i] ^ ~ y [i] (~ x [i] ^ y [i])
g }
The set Z computed by the algorithm is
[2006, 2 Marks]
Among the following sequences
(a) X Y (b) X Y
1. abeghf 2. abfehg
3. abfhge 4. afghbe (c) (X – Y) (Y – X) (d) (X – Y) (Y – X)
13
83. We have a binary heap on n elements and wish to insert n 89. Consider the following functions:
more elements (not necessarily one after another) into this f(n) = 2n
heap. The total time required for this is g(n) = n!
[2008, 2 Marks] h(n) = n logn
(a) (log n) (b) (n) Which of the following statements about the asymptotic
(c) (n log n) (d) (n2) behaviour of f(n), g(n) and h(n) is true? [2008, 2 Marks]
84. You are given the postorder traversal, P, of a binary search (a) f(n) = O(g(n)); g(n) = O(h(n))
tree on the n elements 1, 2, ..., n. You have to determine the (b) f(n) = (f(n)); g(n) = O(h(n))
unique binary search tree that has P as its postorder traversal. (c) g(n) = O(f(n)); h(n) = O(f(n))
What is the time complexity of the most efficient algorithm (d) h(n) = O(f(n)); g(n) = (f(n))
for doing this? [2008, 2 Marks] 90. The Breadth First Search algorithm has been implemented
(a) (log n) using the queue data structure. One possible order of visiting
(b) (n) the nodes of the following graph is [2008, 1 Mark]
(c) (n log n)
(d) None of the above, as the tree cannot be uniquely
determined M N O
–3
b e
2 2
1 –5 1 1
85. a c h f R Q P
2 3 2 3
2 (a) MNOPQR (b) NQMPOR
d g
(c) QMNPRO (d) QMNPOR
91. The most efficient algorithm for finding the number of
Dijkstra’s single source shortest path algorithm when run connected components in an undirected graph on n vertices
from vertex a in the above graph, computers the correct and m edges has time complexity [2008, 1 Mark]
shortest path distance to [2008, 2 Marks] (a) (n) (b) (m)
(a) only vertex (b) vertices a, e, f, g, h (c) (m + n) (d) (mn)
(c) vertices a, b, c, d (d) all the vertices 92. In quick sort, for sorting n elements, the (n/4) the smallest
86. Consider the Quick sort algorithm. Suppose there is a element is selected as pivot using an O(n) time algorithm.
procedure for finding a pivot element which splits the list What is the worst case time complexity of the quick sort?
into two sub-lists into two-sub-lists each of which contains [2009, 2 Marks]
at least one-fifth of the elements. Let T(n) be the number of (a) (n) (b) (n log n)
comparisons required to sort n elements. Then (c) (n2) (d) (n2 log n)
93. Consider the following graph: [2009, 2 Marks]
(a) T n 2T n / 5 n [2008, 2 Marks]
(b) T n 2T n / 5 T 4n / 5 n
b 2 e
5
5
(c) T n 2T 4n / 5 n
6 6
(d) T n 2T n / 2 n a d 3 g
94. The keys 12, 18, 13, 2, 3, 23, 5 and 15 are inserted into an 99. What is the time complexity of Bellman-Ford single-
initially empty hash table of length 10 using open addressing source shortest path algorithm on a complete graph of n
vertices? [2013, 1 Mark]
with has function h(k) = k mod 10 and linear probing. What
(a) (n2) (b) (n2 log n)
is the resultant has table? [2009, 2 Marks] (c) (n3) (d) (n3 log n)
(a) 0 (b) 0 100. Consider the following operation along the Enqueue and
1 1
Dequeue operations on queues, where k is a global
parameter.
2 2 2 12
Multi-Dequeue(Q){
3 23 3 13 m=k
4 4 while (Q is not empty) and (m > 0){ Dequeue(Q)
5 15 5 5 m=m–1
6 6 }
7 7 }
8 18 8 18
What is the worst case time complexity of a sequence of
n queue operations on an initially empty queue?
9 9
[2013, 2 Marks]
(c) (d) 0 (a) (n) (b) (n + k)
0
(c) (nk) (d) (n2)
1 1
101. Consider the following function:
2 12 2 12, 2 int unknown (int n) {
13, 3, int i, j, k=0;
3 13 3
23 for (i=n/2; i<=n; i++)
4 2 4 for (j=2; j<=n; j=j*2)
5 3 5 5, 15 k = k + n/2;
6 return (k);
6 23
7 }
7 5
The return value of the function is
8 18 8 18
[2013, 2 Marks]
9
9 15 (a) (n2) (b) (n2 log n)
95. The running time of an algorithm is represented by the (c) (n3) (d) (n3 log n)
following recurrence relation [2009, 2 Marks] 102. An operating system uses the Banker’s algorithm for
deadlock avoidance when managing the allocation of three
n , n 3 resource types X, Y, and Z to three processes P0, P1, and
T n n P2. The table given below presents the current system state.
T cn, otherwise
3 Here, the Allocation matrix shows the current number of
Which one of the following represents the time complexity resources of each type allocated to each process and the
Max matrix shows the maximum number of resources of
of the algorithm?
each type required by each process during its execution.
(a) (n) (b) (n log n)
(c) (n2) (d) (n2 log n) Allocation Max
96. Two alternative packages A and B are available for
processing a database having 10 k records. Package A X Y Z X Y Z
requires 0.0001 n2 time units and package B requires 10n P0 0 0 1 8 4 3
log10n time units to process n records. What is the smallest P1 3 2 0 6 2 0
value of k for which package B will be preferred over A? P2 2 1 1 3 3 3
[2010, 1 Mark]
(a) 12 (b) 10 There are 3 units of type X, 2 units of type Y and 2 units of
(c) 6 (d) 5 type Z still available. The system is currently in a safe state.
97. Which one of the following is the tightest upper bound Consider the following independent requests for additional
that represents the number of swaps required to sort n resources in the current state:
numbers using selection sort? [2013, 1 Mark] REQ1: P0 requests 0 units of X, 0 units of Y and 2 units of Z
(a) O(log n) (b) O(n) REQ2: P1 requests 2 units of X, 0 units of Y and 0 units of Z
(c) O(n log n) (d) O(n2) Which one of the following is TRUE?
98. Which one of the following is the tightest upper bound [2014, Set-1, 2 Marks]
that represents the time complexity of inserting an object (a) Only REQ1 can be permitted.
into a binary search tree of n nodes? [2013, 1 Mark] (b) Only REQ2 can be permitted.
(a) O(1) (b) O(log n) (c) Both REQ1 and REQ2 can be permitted.
(c) O(n) (d) O(n log n) (d) Neither REQ1 nor REQ2 can be permitted.
16
103. Suppose a polynomial time algorithm is discovered that array as the pivot. Then the tightest upper bound for the
correctly computes the largest clique in a given graph. In worst case performance is [2014, Set-3, 1 Mark]
this scenario, which one of the following represents the (a) O (n2) (b) O (n log n)
correct Venn diagram of the complexity classes P, NP and (c) (n log n) (d) O (n3)
NP Complete (NPC)? [2014, Set-1, 2 Marks] 107. Consider a hash table with 100 slots. Collisions are resolved
using chaining. Assuming simple uniform hashing, what is
NP the probability that the first 3 slots are unfilled after the first
3 insertions? [2014, Set-3, 2 Marks]
P
(a) (97×97×97)/1003 (b) (99×98×97)/1003
(a) (c) (97×96×95)/1003 (d) (97×96×95)/(3!×1003)
Weight of edge be 1.
A to B will cost only 1 neglecting the weight of
other edges
Graph 2
E1
Number of nodes in the at most twice of the right A B
subtree.
E5 E2
D C
E3
24
Here, A to B will not cost only 1 as they are not
connected. So, they needs to be connected. Index Hash value
54. (b) Starting from vertex a 4322 2
{(a, b), (a, c), (a, d), (a, c)} min = (a, c) = 1
{(a, b), (a, d), (a, e), (c, d)} min = (a, d) = 2 1334 4
{(a, b), (a, e), (c, d), (b, d), (d, h)} min = (b, d) = 3 1471 1
(c, d) not selected since it make cycle 9679 9
{(a, b), (a, e), (d, h), (b, g)} min = (b, g)=2
{(a, b), (a, e), (d, h), (g, h), (g, j), (g, i)} (g, h) =8 1989 9
{(a, e), (d, h), (g, j), (g, i), (h, i), (h, f), (e, h)} (h, i) = 4 6171 1
{(a, e), (d, h), (g, j), (g, i), (h, f), (e, h)(e, i), (f, i), (j, i)} min 6173 3
= (e, i) = 2
4199 9
{(a, e), (d, h), (g, j), (g, i), (h, f), (e, h), (f, i), (j, i), (e, f)} = 4
{(a, e), (d, h), (g, j), (g, i), (e, h), (f, i), (j, i), (e, f)} (j, i) = 5 By the table above, it is observed that statement 1
8 15 19 14 8 9 5 11 and statement 2 are correct.
Sum 1 + 2 + 3 + 2 + 8 + 4 + 2 + 4 + 5 61. (c) Sorting worst case occurs when arrays are reverse
= 31 sorted, we need to select every element once & for
Hence (b) is correct option. every element min no. of comparison might be log 2n.
55. (b) Sequence asbscsaedsceesfsbedegseefehsgehe So overall min. complexity 0(n log n)
No. of rooms 0 1 2 3 2 3 2 3 4 3 2 3 2 1 2 1 0 Hence (c) is correct option.
Maximum no. of rooms required at a time = 4 option 62. (a) Statement 1 is correct
(b). Consider k to be constant
Here the logic is very simple increase the no. of room f(n) = (n + k)m
if some activity start & decrease by 1 if activity f(n) = (1 + n)m
ends. f(n) = O(nm)
56. (d) Here A during initialization gives the adjacency Statement 2 is correct
matrix for directed graph G(V, E). And for very (j,k) f(n) = 2n+1
we calculate A[j,k], which stores maximum of the sum f(n) = 2n.2
of edges making a simple path. f(n) = O2n
So if there exists a simple path from j to k . A[j,k] Statement 3 is incorrect
contain no. of edges in that path. f(n) = 22n+1
a b c f(n) = 22n.2
a 0 1 1 f(n) = O22n
b 0 0 1 Therefore, we can see that the only statement 3 is false.
c 0 0 0 63. (d) DFS traversal takes the path to the end & then move
57. (c ) Here the fragment of code contains for loop which to other branch.
goes from 1 to n. a
Since due to given conditions m < n.
So complexity of code is (n) e b f
Hence (c) is correct option.
58. (d) The C function given above is resursive. h
g
The output of the program thus, obtained is
10
8 5
1
2
Order a be f c h g d
a b= 1 ac= 3 ab= 6
3 ae = 2 af= 0 a g = 3
4
ah = 2
82. (c) This is a formula to calculate the total number of nodes. Since there is no - ve cycle so Dijkstra gives correct
It is 2h + 1 – 1.
result for all vertices.
Let consider some examples to prove this.
1. Simplest could be taking the binary tree of h (height) 86. (b) Pivot element is found in Quick sort in every iteration
= 0. all the elements to its left are smaller than & all in the
Now, the binary tree of height h will have only 1 node. right are greater than it. So if 1/5th of sorted sequence
is the pivot. So sequence is divided into 1/5th & 4/5th
Using formula 2 ^ (0 + 1) – 1 = 1. Hence, the formula is of the sequence. So recursion will be
correct. T(n) = T(n/5) + T(4n/5) + n
2. Binary tree of h (height) = 2
87. (a) In B tree the data is stored at leaves only a particular
1 node can have maximum. 3 keys, so when 4th insertion
comes first split is required, during 7th second split &
3 so on, so for 10 insertions max. 3 splits are required.
2
We can prove it mathematically.
7 No. of split < = 1 + logm/2[n/2]
4 5 6 Here m order = 4 n = 10 b = 3
Using formula 2 ^ (2 + 1) – 1 = 7. Hence, the formula is K <= 1+ log2 [10/3] = 1 + log 2[4]
correct. K<= B
83. (b) Heaps are implemented as simple arrays, to insert n
88. (b) Since all the elements are sorted so we can apply
more elements each element take (1) time. So total
binary search here efficiently. In BS the size of array
time would be (n).
required to compare reduces by n/2 in every iteration.
84. (b) To construct a BST from post order we also require
Here since the sequence is sorted so the same element
in-order traversal since given the elements are 1 2.......n
would come Consecutive.
So their sorted order would be in order. Using both 89. (d) Since
BST can be constructed in a linear scan. So it will take f(n) = 2n
only 4n time. g(n) = n!
h(n) = n logn
85. (d) We apply Dijkstra Algorithm. It can also be shown as
f(n) = O (2n)
28
g(n) = O(n!) Complexity of this algorithm is same as 1 DFS run
h(n) = O (nlogn)
0(m + n) since
Now,
As per the asymptotic order of function n log n C2 n DFS is the basis of articulation point.
for all n n 0 92. (b) Pivot in guide sort is the index which is sorted in that
Let us assume C = 1 and n 0 = 2 run, all the elements in its left are smaller than it &
It comes out to be 2 log 2 22 elements greater than it are on its right side.
h(n) = O(f(n)) one result So the recursion becomes.
Now, T(n) = T(n/4) + T(3n/4) + n
g(n) = n! & f(n) = 2n
As per the asymptotic order of function Solution to this recursion is (nlogn)
93. (d) Kruskal’s algorithm, arranging edges in ascending
n! C2n for n n 0
Let us assume C = 1 and n = 4 order.
{2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6}
24 24
16
g(n) = (f(n)) second result
Therefore, the two results are
h(n) = O(f(n)); g(n) = (f(n))
90. (c) Applying BFS algorithm on the following figure
M N O (a)
R Q P
Let start form Q
Q comes in queue first (b)
Changing the status of the Q’s child to 1
Queue obtained, Q | M | N | P
Changing the status of the M’s child to 1
Queue obtained, Q | M | N | P | R
Changing the status of the N’s child to 1
Queue obtained Q | M | N | P | R | O
The queue’s final status is as per the table below
Q M N O P R
2 1 1 1 1 (c)
2 2 1 1 1
2 2 2 1 1 1
M N O
(d)
R Q P
(5, 6), (6, 4), (6, 5) and (6, 6) and (1, 12) is connected only
to (1, 11), (2, 11) and (2, 12). 129. 6
So, different vertices are connected to different number of
vertices. However we can visualize this easily using 6
following diagram:– +
3 3
–
+
1 2 3 4 5 6 7 8 9 10 11 12 2 –1 2
1
1 + – – +
2
1 1 0 1 1 0 1 1
3
130. 6
4
5 a 2
6 2 1 2 1
7 b c
8 2 2
9 A 1 1 2 1
10 B d e
11 2
2
12 Edges picked to make MST is given the double line.
In the right side of MST, we could either pick ‘d’ or ‘e’
In the left side we could either pick ‘a’, ‘b’ or ‘c’ in MST.
There are two options for one edge to be picked and three
Each cell of the table represents corresponding vertex option for other edge to be picked.
of the graph. For example the cell ‘A’ represents vertex Total possible MSTs = 2 × 3 = 6
(9, 0) of the graph, similarly ‘B’ represents vertex (10, 131. 3
2) of the graph. a * b * (ba) * a *
Now, we easily see that there are three kind of vertices Length 0 is present (as it accepts )
in the graph (or table): Length 1 is present (a, b)
(i) Corner vertices which are connected to ‘3’ neighbours. Length 2 is present (aa, ab, ba, bb)
Length 3 is not present (bab not present)
No. of such vertices = 4
it is 3
Total no. of edges for such vertices = 4 × 3 = 12
132. 110
(ii) Vertices in first/ last row of first/last column except It takes (log n) time to determine numbers n1 and n2 in
corner vertices, which are connected to ‘5’ neighbours balanced binary search tree T such that
each. 1. n1 is the smallest number greater than or equal to
No. of such vertices = 40 L and there is no predecessor n 1 of n1 such that n 1
Total no. of edges for such vertices = 40 × 5 = 200 is equal to n1.
(iii) Internal cells (vertices) that are connected to ‘8’ 2. n2 is the largest number less than or equal to H and
neighbours each. there is no successor of n 2 of n2 such that is equal
No. of such vertices = 100 to n2.
Total no. of edges for these vertices = 100 × 8 = 800 Since thee are m elements between n 1 and n 2, it takes ‘m’
Edge total of all above cases = 12 + 200 + 800 = 1012 time to add elements between n1 and n2.
So time complexity is O (log n + m)
However in above calculation each edge is counted
So the given expression becomes O (n 0log n + m log0 n)
twice, so, finally total no. of edges in the graph =
And a + 10b + 100c + 1000d = 0 + 10 × 1 + 100 × 1 + 1000 × 1
1012 = 10 + 100 = 110
= 506. Because a = 0, b = 1, c = 1 and d = 0
2