0% found this document useful (0 votes)
5 views

ADSA Notes

The document contains notes on advanced data structures and algorithms, covering topics such as partitioning, the Kernighan-Lin algorithm, and various optimization problems like the knapsack problem and the traveling salesman problem. It also discusses randomized algorithms, min-cut algorithms, and the complexity of certain problems, including NP-complete problems. Additionally, it includes examples of dynamic programming methods for calculating the longest common subsequence and matrix chain multiplication.

Uploaded by

harsha konduru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

ADSA Notes

The document contains notes on advanced data structures and algorithms, covering topics such as partitioning, the Kernighan-Lin algorithm, and various optimization problems like the knapsack problem and the traveling salesman problem. It also discusses randomized algorithms, min-cut algorithms, and the complexity of certain problems, including NP-complete problems. Additionally, it includes examples of dynamic programming methods for calculating the longest common subsequence and matrix chain multiplication.

Uploaded by

harsha konduru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Advanced data

Structures and

algorithms
Notes
Mus
>
Splay Notes :
-

Partitioning
>
-

stays at
different levels of partitioning

h or
hypergraph
-usually with vertex
weight/size
>
usually weighted edges
- .

straintspartitioning
s

(K-way partitioning)
>
-

MaximumCapacity of
each
partitiono
maximum allowable
difference between
partition
.

objective odes to
partitions subject
.
to constraints such that
there

cutsize minimized
is

Fractabil,ity p-complete .

Kernighan Lin (KL)


algorithm
>
-
-

calculation.
Gain
>
-
Fontusios -

Matthesus
algorithm
>
-

Weighted event
scheduling
> Matrix chain
Multiplication
-

Booth
-
& Wallace
multiplies
>
-
storisius matrix
multiplication ?
> show that no
of paranthesis grows
at
(4/ ?
-

Longest subsequence
>
-

common

The
knapsack problem
>
-

O knapsack problem

Randomized Las
Vegas (Always
correct solution)
>
Algorithm >
gives
-

Montecarlo incorrect solution


>
(May give
> Randomized
Quicksort
↓I
onesided Trosidas
e

-min-cut
algorithm
-
Kargar algorithm partition
>
-

Karnighan Lin algorithm ↓ Y


>
-

Fedusia Matthesus Balanced Unbalanced


Simulated
Annealing
-

>
-

Simulated Evolution
>
probability computing Michael M
.
-

Markov's
>
Inequality
.
-

Chebyshev's Inequality
>
-

Chernoff's bound
.

>
-

Weighted vertex cover


problem (WVC)
>
Travelling salesman
problem (TSP)
-

> Hamiltonian cycle problem (HCP)


-

-> Eulerian
graph
The
K-clustering problem
>
-

# knapsack problem

- circuit SAT
(Questions willcome
Sop POS
format

>
polynomial Reducibility
-

NP-complete problems
>
-

>
-
3- SAT

>
3-colorability problem
-

>
- The
clique problem
>Vertex cover
problem
-
shortest path with Hedge
b for v
path s-x
① => every
,

② b Bellman-Ford Algorithm O(mn)

③ b

#min
C -
+ 1 = 33

, = 1

13 11 10

-

---
⑤ b

⑦ C

111/
⑧ a Randomized Select
Algorithm Oct.
worst A
but case
- 0(n) .

⑨ (9) True

every bipartite
(b) False becoz Not
graph
is tree But tree is
every
.

bipartite graph .

False An undirected have


( graph can

multile path possible .


(d) True As M5T have
unique
edge to connect .
(No
cycles .

false plogs
es as => n)
logn .

Oth
complexity
So , is Time

False
(f) it solved .
DP
as is
using 2-D ,

True
(g)
as minimum
M5T
edge is the
part
of
(h) True

i True

false Cas AXL & Retre is


O(legn))
(j) .


Common
LCS7
Longest Subsequence
.

Time
=>
Complexity of LCS
for Dynamic method : -MXn

if

S
k or t
[FCs (KIst
= 0 = 0

Les (1 A]
,
=
+]
if 10 , 30, A

max[LC5 (k-1 , AJ ,
LCS (k -1)
,

if 170 , 130 , Un = ya

t

max
subsequent
length
.

A
Subsequence :
=> Time
complexity of LCS
for recursive method :

nxzm or mx2"

E
1 + (C8(i 1) if i
j j
- 1 -

=
,

mar (LCS (i -1 j)
LCS ,

if i
j
= ,

225(i
, j 1))
-

123456
if i = 0
,

j
.
= 0

Q X =
BDGABA
Y = ABC BDA
⑭ 3
13
5)
[S2
LCs (6 6) 1+ LC5 (5 - 25
,
=
, , 2) = man
3

(LCS
LCs (5 5) ,
= mar (4, 53
, 2

I
LC5 (5 4) 3 2C5 (2 3)
GLC5(1 3) 1
,
,
=
man ,
2

[25(3
5)2 LC5 (2, 2) I
LOS (4 5) ,
= may ,

S
LC5 (4 , 4)2 (C5 (4 , 1) = 1 + LC5 (3 07
,

3 # ⑧
LCs (5 , 4) =
1 + LCS (4 3) 2
,
-
LC5(1 , 2) = 1 + LC5(0, 1) -

z O
LCs (3 5) ,
=
man

((C512
LC5 (3
, 5)

4)2
,
2 LC5(2 , 1) =
man
&LC5
LC5 (2, 0)
(1 1178 ,

o
,

z O
(C5 (44)
(105(3 4)2 LC5(3 , 1)
man Las
=
,
= man ,

LCS (4, 31 2
I

(2C5 (2C510
225 (3 ,) =
man (3 3)2 , LC5(1 / 3) = man , 3)0
LC5 (2 , 4) I LC5 (1 , 2) 1

z
3)
E (LCSto
LC5 (4 , 3) =
mas LCS (3 3) .
2
LC5 (1 , 1) = man ,

28(10)
2C5(4, 2) 1

Las (24,5) = 1 + 1C5 (1 , 4)1


(333) 2)
substring
V
LC5 = 1 + Los (2 , mak

[15(1
*
431
length
=4
LCs (2 , 4) = mar , .
LC5 (2 , 3) 1

205" (4 2)
(LC5(b 2)
Substringe BCBA
=
, man ,

(C8(4 1) ,
I

205"<1 , 4) = 1 + LCS (0, 3)


O

I p
225 (2 2) man

&Les c,0
=
,
chain
=> Given a
of matrices (A ,, Az -
--Ax]
where A has dimensions Pix XPi ,

Fully
parenthesize the
product A2---An Al ,

in a
way that minimizes the number
of multiplications
scalar . Give the recursive
solution
for minimizing the cost of
parenthesizing the Matrix Ai Ai 1---Aj and .
+

compute
Al XA2 x A3 X A4
wher ,
Al : 2X4 A2 : 4x12 A3 : 12X4 A4 : 4x10

- The
following recursive solution is

Emin
i
[i
g if =
j
e
j]
=
,

[c(i , ) +
e (k ,
j
+

Pipe
AiXA2 X Az XA4

-
2x44X12 12x44X10


=
min [0 + 0 + 2x4x123 96 =

min(e (2 p xpzXP33

t
c (3 37
↓ (2 3)
,
=
, 2) +
, +
,

=
min[0 + 0 +
4x12X43 = 192 .

C (3,4) = m [ e(3 3) , + c(4 4) ,


+ P2XPzXP+ ]
= min 20 + 0 + 12x4X103 = 480

mintboxbo- (1 , 3)
,A
= = 0 + 192 + 2x4X4 = 224
c (1 , 23 + c (3 3)
, + prxb2xP3
1 < 3 -1
C(
2k4
,) =

meet
E c (2 3) , + c(4, 4) + P
, XPzXP4
0 = 480 + 48 = 96

192 + 0 4X4X10
=
+ = 192 + 160 =
352

min
S F
0 + 352 + 2 x4 X 1 0 = 352 + 80 =
432

e ,) =
9) + 480 + 2x12x10 = 96 + 480 + 240 = 816

1 < k <4 c (1 , 3) + c (4 4]
,
+ Po XPzX Pr
2 + 00 = 22

Parenthesization .

S 3

(2A , xAcxAs) X A

An
Que Karger min-cut algorithm : -

o
>
To collapse the edge Cr v) create node
-

we a new
, ,

Ey replace any edge of the form


,

En wa or
, Ev ws ,
with a new
edgecur ,
we
and
Mand
v
then delete the
original virtices .

Min cut
>
Karger :-
-

1: Run
return
the
the
guessing
smallest
algo many . times and

guess
.

Only wayis for Karger algo return the


2: to
wrong
answer
if Karger-min-cut algo fails N times

in a row
.

Karger Min Cut (G) :

mink

i
for 1 to N .:
=

i = Guess Min Cut (4)

mink
if 1x1 < .

mink = 1x1

mina = X .

return mink .
Applying min-cut-algo to
given ques :

rapsing↓
( , 4) Yater pai

- collapsing 20

collapsing Ga

#D a re
final graph
after applying
the
algorithm
.

Qubi-

F y2
=> expression for
firstly deriving its Boolean the above circuit :

Yo yay - %
=

Now * 5
y
=
,
yy
=
y5xys
-

y
= x , nx4 , y2
=
T

yz
=
nxn T yq
=
(4 144)
,
*
42

T
-


y5
=

77 2
x(uznx)
=

>5]
Now , (((4 , 2x4Xx2) /Ev(Uza ** )) <

ye
=

Now in CNF : -Conjuctive Normal Form "


for
yo
to be .

using the following identify :-

(an b) y c =
(avc)n(byc) .

%o
=
((k xx2) n (44YX2)]
, /zvU3) NLT2 vn] nT5

the circuit
Now for to be satisfiable following conditions
must be hold true :

I Tre
(k2VU , ) >
-

must be true

(x2 XX4) >


-

True True
(V *) >
-
True
then for (x2X4 , ) >
-

true

considering/
true l = then , I, can be
anything

(O2Vx) >
-

true since we let xe-true


.

(v) >
-

for this to be true :-

-False >

is >
-
true
so,
Iuse
(2 YUz) >
-

for this to be true

y has to be true

#-
true .

Hence , 41 >
-

True/false
42 - True

3 - True
44 >
-
False
45 - False

for all these


input our circuit will be satisfied
.

Ques +
WSCP
by pricing method : -Given
diagram
is :

w
b
w(S1) =
So the WSCP that :-
,
says
i/p = a set X =
Ex , x2 ,
- - - - - -
kn] of n elements .

a
family f =

[A ,, 12 , As ---- Sny of m subsets

of u and w(f) =
weights of each

subset If .

w(f) > 0 .

Pre-condition =f covers a i .

.
e

o p = a subset eef! that covers be Uses

Goal :- Minimize the weight of set cover C:

w(e)= was

Now
coming
to our
question : .
-

w(s)

-

·
&

③>
- 12

>
-
15

⑮ > 10

-
Now the optimal solution :

Copt
=
[S2 , Az , 15]

W(Coptl = 9 + 12 + 10 = 31 .

Now approx WSCP


by ispricing method :-

the
algorithm as
follows :

E
N = ( *
uncovered elements)
c d
= ( set cover)

while U :

select sef that minimizes pricp .

=it
a

noo
s demn

u = v -
S

c = c S

return C

#
Running the above
algorithm ,
ituati
#
on

p
=
2475 , >
-

% = 2 -
X-

Ya
v
2

2X3 > 9/4 2 25


-

= .

2 *4 Ss
> 12/3 4
-

X5
Sk > 15/2 = 7 5
X6
- .

X7 Sq
Xf
>
-
1 % =
3 .
33

itration o
d
& p =

u
2 K 1, a
,

2
9/2 = 4 5 .

12/1 = 12

15/1 = 15
4 5 .

Us
4 .

5 s
1 %
/r = 5

RT
Rf

iteration
Erd
ice x
p =
,
Si a

2
R2
52 es

5i as
Sy

Sk
12/1 =
12

4 5 1/1 =
15
XS
.

x7 S5 10/1 = 10
E
1048
-
4th iteration
-

Price : -

24 ,
Si
D
2xz S2 s

e-in
s
53 e

In -

12x7
10 Up

EPi(ki) w(l) 4
2 + 2 + 54-
Now 2 + 2
= = + .

4
. 5 + 12+ 10

(c)
39 =

algorithm
using
Etopt = 31
.

=> Que: Karnigham Lin (KL)


algorithm : E
determining the Minimum Cut :-

-Given graph :-

a
Step
I
-p
I
find the pair of verti where
cut size decreases :

Let us take :
vertise pair (H , ED

se
Now cut =
2 .

#Nowagain taking pai


a verter s


Now cut =
1

So 2-1
gain
=

= 1 .

So ,
here also : -cut has been decreased
Hence also accepted
, this
swapping is .

Now if we
swap more
pair of vertices
,
will
definitely the
then cut increase
.

This
I is the minimum that we can

get .
proteo
verters cover
for
-

above =
⑦2

[B(4) ,
C(2) ,
e(2)}.

*
total weight = 8 .= c

c =
0 .

Now ,
approximation algo, verte cover : -

1st
edge > (A C)
-

e =
qU[A CY ,

⑦-----

·
2nd
edge ,
c =
&A CSU (B D)
,
,

C =
[A , C , B D3 > total
weight
-

>
-

3 + 2 + 4# 4
·

> 13 = C

-

----------
des
Here
,
co =
13
*
C = 8

s
>
pans
-

C cost of solution

of optimal
*
c >
-
cost solution
For minimization : -

i
for

maximizati
I
STATION
·

·
S1 ,5

LINE-I

e Exit

Entry
- ⑫

5
X
5
654

S 52 ,

STATION
2 S2 , 3

STATION
52 , 4

STATION
S2 ,

STATION
5

if j
detai
=
2
Fli] =

[F/j-1)
min +
Rej F2/j-c] + +
, ,
+
is a] if j22
E/j) =Let Feli-t] + + y
,
-

1
+
azifj22
For j = 1

# 11] 8
= e + au =
2+ 6
,
=

5+ 8 13
F(1] e + 22
=
= =

For j = 2

F(2) = min GFC1] + 42


,
F2(1] + te + &123
,

= min
[0 + 8 ,
13 + 2 + 8]
= 16

GE [11 + &22 , F(1] +A, c am2)


+
F2(2) = min

= min
[15 + 5 0 + + 6),
2

= 16

You might also like