SlideShare a Scribd company logo
Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s
BLG 336E – Analysis of Algorithms II
Practice Session 3
Atakan Aral
Istanbul Technical University – Department of Computer Engineering
25.03.2014
Atakan Aral Istanbul Technical University – Department of Computer Engineering
BLG 336E – Analysis of Algorithms II
Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s
Outline
1 Dijkstra Algorithm
Problem
Solution
2 Street Lights
Problem
Solution
3 MST and Shortest Path
True or False?
4 Median of Two DB’s
Problem
Solution
Atakan Aral Istanbul Technical University – Department of Computer Engineering
BLG 336E – Analysis of Algorithms II
Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s
Problem
[Midterm 2013] Compute the shortest path from node 4 to
node 1 in the following undirected graph using the greedy
algorithm we learned in the class.
3 5
2
4
6
1
2
7
9 3
5
4
Atakan Aral Istanbul Technical University – Department of Computer Engineering
BLG 336E – Analysis of Algorithms II
Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s
Solution
3 5
2
4
6
1
2
7
9 3
5
4
d(4) : {∞, ∞, ∞, 0, ∞}, s : {4}
d(4) : {∞, 2, ∞, 0, 7}s : {4, 2}
d(4) : {6, 2, 11, 0, 5}, s : {4, 2, 5}
d(4) : {6, 2, 10, 0, 5}, s : {4, 2, 5, 1}
d(4) : {6, 2, 10, 0, 5}, s : {4, 2, 5, 1, 3}
Atakan Aral Istanbul Technical University – Department of Computer Engineering
BLG 336E – Analysis of Algorithms II
Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s
Problem
Local government wants to reduce operating costs of road
lighting.
Not every road will be illuminated at night.
For safety, there will be at least one illuminated path
between all junctions.
Suggest an algorithm to optimize the road lighting
What is the maximum saving without endangering the
citizens?
Atakan Aral Istanbul Technical University – Department of Computer Engineering
BLG 336E – Analysis of Algorithms II
Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s
Problem
Input contains the junctions and the roads connecting them
As well as, the cost of illuminating each road.
File format is as follows:
7 11
0 1 7
0 3 5
1 2 8
1 3 9
1 4 7
2 4 5
3 4 15
3 5 6
4 5 8
4 6 9
5 6 11
Atakan Aral Istanbul Technical University – Department of Computer Engineering
BLG 336E – Analysis of Algorithms II
Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s
Solution
3 4
1 2
5
6
5
9
11
0
6
8
5
8
9 7
15
7
g
Atakan Aral Istanbul Technical University – Department of Computer Engineering
BLG 336E – Analysis of Algorithms II
Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s
Solution
3 4
1 2
5
6
5
9
11
0
6
8
5
8
9 7
15
7
g
Atakan Aral Istanbul Technical University – Department of Computer Engineering
BLG 336E – Analysis of Algorithms II
Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s
Solution
3 4
1 2
5
6
5
9
11
0
6
8
5
8
9 7
15
7
g
Atakan Aral Istanbul Technical University – Department of Computer Engineering
BLG 336E – Analysis of Algorithms II
Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s
Solution
3 4
1 2
5
6
5
9
11
0
6
8
5
8
9 7
15
7
g
Atakan Aral Istanbul Technical University – Department of Computer Engineering
BLG 336E – Analysis of Algorithms II
Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s
Solution
3 4
1 2
5
6
5
9
11
0
6
8
5
8
9 7
15
7
g
Atakan Aral Istanbul Technical University – Department of Computer Engineering
BLG 336E – Analysis of Algorithms II
Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s
Solution
3 4
1 2
5
6
5
9
11
0
6
8
5
8
9 7
15
7
g
Atakan Aral Istanbul Technical University – Department of Computer Engineering
BLG 336E – Analysis of Algorithms II
Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s
Solution
3 4
1 2
5
6
5
9
11
0
6
8
5
8
9 7
15
7
Total cost: 90 – Optimized cost: 39 – Saving: 51
Atakan Aral Istanbul Technical University – Department of Computer Engineering
BLG 336E – Analysis of Algorithms II
Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s
True or False?
Let G be an arbitrary connected, undirected graph with a
positive distinct cost c(e) on every edge e.
Let T be a MST of G. If we replace edge cost c(e) with
c(e) ∗ c(e) , T must still be MST for G.
Same is valid for c(e) + 5.
It is also valid if negative costs are allowed.
2 4
3
MST depends only on the order of the costs, actual values
are not important as long as order is the same.
Atakan Aral Istanbul Technical University – Department of Computer Engineering
BLG 336E – Analysis of Algorithms II
Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s
True or False?
Let G be an arbitrary connected, directed graph with a
positive cost c(e) on every edge e.
Let P be the shortest path between node s and node t in
G. If we replace edge cost c(e) with c(e)2, P must still be
shortest path between node s and node t in G.
Same is valid for c(e) + 5.
e
t
2
s
2
3
e
t
2
s
2
5
For shortest paths, actual values of the costs do matter.
Atakan Aral Istanbul Technical University – Department of Computer Engineering
BLG 336E – Analysis of Algorithms II
Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s
Problem
You are interested in analyzing some hard-to-obtain data
from two separate databases A and B.
Each database contains n numerical values and you may
assume that no two values are the same.
Determine the median of this set of 2n values
Only way you can access these values is through queries
to the databases: In a single query, you can specify a
value i to one of the two databases, and the chosen
database will return the ith smallest value that it contains.
Since queries are expensive, you would like to compute
the median using as few queries as possible.
Give an algorithm that finds the median value using at
most O(logn) queries.
Atakan Aral Istanbul Technical University – Department of Computer Engineering
BLG 336E – Analysis of Algorithms II
Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s
Solution
Formulation
Let k = n/2 then A(k) and B(k) are the medians of
databases A and B. We are looking for C(n) where C is the
merged database.
If A(k) < B(k) then:
B(k) > A(1), A(2), ..., A(k)
B(k) > B(1), B(2), ..., B(k − 1)
B(k) is greater than at least 2k − 1 elements.
B(k) ≥ C(n) so no need to consider
B(k + 1), B(k + 2), ..., B(n)
Atakan Aral Istanbul Technical University – Department of Computer Engineering
BLG 336E – Analysis of Algorithms II
Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s
Solution
Formulation
Let k = n/2 then A(k) and B(k) are the medians of
databases A and B. We are looking for C(n) where C is the
merged database.
If A(k) < B(k) then:
A(k) < B(k), B(k + 1), ..., B(n)
A(k) < A(k + 1), A(k + 2), ..., A(n)
A(k) is less than at least 2n − 2k − 1 elements.
A(k) ≤ C(n) so no need to consider
A(1), A(2), ..., A(k − 1)
Atakan Aral Istanbul Technical University – Department of Computer Engineering
BLG 336E – Analysis of Algorithms II
Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s
Solution
Otherwise, if A(k) > B(k) then:
A(k) > B(1), B(2), ..., B(k)
A(k) > A(1), A(2), ..., A(k − 1)
A(k) ≥ C(n) so no need to consider
A(k + 1), A(k + 2), ..., A(n)
Similarly,
B(k) < A(k), A(k + 1), ..., A(n)
B(k) < B(k + 1), B(k + 2), ..., B(n)
B(k) ≤ C(n) so no need to consider B(1), B(2), ..., B(k −1)
Atakan Aral Istanbul Technical University – Department of Computer Engineering
BLG 336E – Analysis of Algorithms II
Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s
Solution
median: n, a = 0, b = 0
1 if n == 1 then
2 return min(A(1), B(1))
3 end
4 k = n/2 ;
5 if A(a + k) < B(b + k) then
6 return median(k, a + n/2 , b)
7 end
8 else
9 return median(k, a, b + n/2 )
10 end
Array size is halved at each recursion. So the complexity is
O(logn).
Atakan Aral Istanbul Technical University – Department of Computer Engineering
BLG 336E – Analysis of Algorithms II

More Related Content

What's hot

Dynamic approach to k means clustering algorithm-2
Dynamic approach to k means clustering algorithm-2Dynamic approach to k means clustering algorithm-2
Dynamic approach to k means clustering algorithm-2
IAEME Publication
 
HW2-1_05.doc
HW2-1_05.docHW2-1_05.doc
HW2-1_05.doc
butest
 
Aes cryptography algorithm based on intelligent blum blum-shub prn gs publica...
Aes cryptography algorithm based on intelligent blum blum-shub prn gs publica...Aes cryptography algorithm based on intelligent blum blum-shub prn gs publica...
Aes cryptography algorithm based on intelligent blum blum-shub prn gs publica...
zaidinvisible
 

What's hot (20)

N41049093
N41049093N41049093
N41049093
 
Dynamic approach to k means clustering algorithm-2
Dynamic approach to k means clustering algorithm-2Dynamic approach to k means clustering algorithm-2
Dynamic approach to k means clustering algorithm-2
 
Vol 16 No 2 - July-December 2016
Vol 16 No 2 - July-December 2016Vol 16 No 2 - July-December 2016
Vol 16 No 2 - July-December 2016
 
Low complexity low-latency architecture for matching
Low complexity low-latency architecture for matchingLow complexity low-latency architecture for matching
Low complexity low-latency architecture for matching
 
Text encryption
Text encryptionText encryption
Text encryption
 
Pg3426762678
Pg3426762678Pg3426762678
Pg3426762678
 
OPTIMIZED REVERSIBLE VEDIC MULTIPLIERS
OPTIMIZED REVERSIBLE VEDIC MULTIPLIERSOPTIMIZED REVERSIBLE VEDIC MULTIPLIERS
OPTIMIZED REVERSIBLE VEDIC MULTIPLIERS
 
240164036 ee2092-4-2011-matrix-analysis
240164036 ee2092-4-2011-matrix-analysis240164036 ee2092-4-2011-matrix-analysis
240164036 ee2092-4-2011-matrix-analysis
 
HW2-1_05.doc
HW2-1_05.docHW2-1_05.doc
HW2-1_05.doc
 
Multiple Valued Logic for Synthesis and Simulation of Digital Circuits
Multiple Valued Logic for Synthesis and Simulation of Digital CircuitsMultiple Valued Logic for Synthesis and Simulation of Digital Circuits
Multiple Valued Logic for Synthesis and Simulation of Digital Circuits
 
Colombo14a
Colombo14aColombo14a
Colombo14a
 
Optimising Data Using K-Means Clustering Algorithm
Optimising Data Using K-Means Clustering AlgorithmOptimising Data Using K-Means Clustering Algorithm
Optimising Data Using K-Means Clustering Algorithm
 
Experimental study of Data clustering using k- Means and modified algorithms
Experimental study of Data clustering using k- Means and modified algorithmsExperimental study of Data clustering using k- Means and modified algorithms
Experimental study of Data clustering using k- Means and modified algorithms
 
Private datawarehouse queries
Private datawarehouse queriesPrivate datawarehouse queries
Private datawarehouse queries
 
DESIGN OF PARITY PRESERVING LOGIC BASED FAULT TOLERANT REVERSIBLE ARITHMETIC ...
DESIGN OF PARITY PRESERVING LOGIC BASED FAULT TOLERANT REVERSIBLE ARITHMETIC ...DESIGN OF PARITY PRESERVING LOGIC BASED FAULT TOLERANT REVERSIBLE ARITHMETIC ...
DESIGN OF PARITY PRESERVING LOGIC BASED FAULT TOLERANT REVERSIBLE ARITHMETIC ...
 
Parallel KNN for Big Data using Adaptive Indexing
Parallel KNN for Big Data using Adaptive IndexingParallel KNN for Big Data using Adaptive Indexing
Parallel KNN for Big Data using Adaptive Indexing
 
IRJET- Finding Dominant Color in the Artistic Painting using Data Mining ...
IRJET-  	  Finding Dominant Color in the Artistic Painting using Data Mining ...IRJET-  	  Finding Dominant Color in the Artistic Painting using Data Mining ...
IRJET- Finding Dominant Color in the Artistic Painting using Data Mining ...
 
Design of High speed Low Power Reversible Vedic multiplier and Reversible Div...
Design of High speed Low Power Reversible Vedic multiplier and Reversible Div...Design of High speed Low Power Reversible Vedic multiplier and Reversible Div...
Design of High speed Low Power Reversible Vedic multiplier and Reversible Div...
 
Aes cryptography algorithm based on intelligent blum blum-shub prn gs publica...
Aes cryptography algorithm based on intelligent blum blum-shub prn gs publica...Aes cryptography algorithm based on intelligent blum blum-shub prn gs publica...
Aes cryptography algorithm based on intelligent blum blum-shub prn gs publica...
 
IRJET- Review Paper on Radix-2 DIT Fast Fourier Transform using Reversible Gate
IRJET- Review Paper on Radix-2 DIT Fast Fourier Transform using Reversible GateIRJET- Review Paper on Radix-2 DIT Fast Fourier Transform using Reversible Gate
IRJET- Review Paper on Radix-2 DIT Fast Fourier Transform using Reversible Gate
 

Viewers also liked

Unit26 shortest pathalgorithm
Unit26 shortest pathalgorithmUnit26 shortest pathalgorithm
Unit26 shortest pathalgorithm
meisamstar
 
Intel core i3, i5, i7 , core2 duo and atom processors
Intel core i3, i5, i7 , core2 duo and atom processorsIntel core i3, i5, i7 , core2 duo and atom processors
Intel core i3, i5, i7 , core2 duo and atom processors
FadyMorris
 
All pairs shortest path algorithm
All pairs shortest path algorithmAll pairs shortest path algorithm
All pairs shortest path algorithm
Srikrishnan Suresh
 
Dijkstra's algorithm
Dijkstra's algorithmDijkstra's algorithm
Dijkstra's algorithm
gsp1294
 
Unix command-line tools
Unix command-line toolsUnix command-line tools
Unix command-line tools
Eric Wilson
 

Viewers also liked (13)

Graphs
GraphsGraphs
Graphs
 
2.3 shortest path dijkstra’s
2.3 shortest path dijkstra’s 2.3 shortest path dijkstra’s
2.3 shortest path dijkstra’s
 
Top-k shortest path
Top-k shortest pathTop-k shortest path
Top-k shortest path
 
Unit26 shortest pathalgorithm
Unit26 shortest pathalgorithmUnit26 shortest pathalgorithm
Unit26 shortest pathalgorithm
 
Multi-core processor and Multi-channel memory architecture
Multi-core processor and Multi-channel memory architectureMulti-core processor and Multi-channel memory architecture
Multi-core processor and Multi-channel memory architecture
 
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
Shortest path (Dijkistra's Algorithm) & Spanning Tree (Prim's Algorithm)
 
Intel core i3, i5, i7 , core2 duo and atom processors
Intel core i3, i5, i7 , core2 duo and atom processorsIntel core i3, i5, i7 , core2 duo and atom processors
Intel core i3, i5, i7 , core2 duo and atom processors
 
All pairs shortest path algorithm
All pairs shortest path algorithmAll pairs shortest path algorithm
All pairs shortest path algorithm
 
Dijkstra's algorithm
Dijkstra's algorithmDijkstra's algorithm
Dijkstra's algorithm
 
Intel Core i7 Processors
Intel Core i7 ProcessorsIntel Core i7 Processors
Intel Core i7 Processors
 
Intel I3,I5,I7 Processor
Intel I3,I5,I7 ProcessorIntel I3,I5,I7 Processor
Intel I3,I5,I7 Processor
 
Unix command-line tools
Unix command-line toolsUnix command-line tools
Unix command-line tools
 
An in-building multi-server cloud system based on shortest Path algorithm dep...
An in-building multi-server cloud system based on shortest Path algorithm dep...An in-building multi-server cloud system based on shortest Path algorithm dep...
An in-building multi-server cloud system based on shortest Path algorithm dep...
 

Similar to Analysis of Algorithms II - PS3

Analysis of Algorithms II - PS2
Analysis of Algorithms II - PS2Analysis of Algorithms II - PS2
Analysis of Algorithms II - PS2
AtakanAral
 
Analysis of Algorithms II - PS5
Analysis of Algorithms II - PS5Analysis of Algorithms II - PS5
Analysis of Algorithms II - PS5
AtakanAral
 
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
IJCER (www.ijceronline.com) International Journal of computational Engineerin...IJCER (www.ijceronline.com) International Journal of computational Engineerin...
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
ijceronline
 
Final Project Report
Final Project ReportFinal Project Report
Final Project Report
Riddhi Shah
 
Grds international conference on pure and applied science (9)
Grds international conference on pure and applied science (9)Grds international conference on pure and applied science (9)
Grds international conference on pure and applied science (9)
Global R & D Services
 

Similar to Analysis of Algorithms II - PS3 (20)

Analysis of Algorithms II - PS2
Analysis of Algorithms II - PS2Analysis of Algorithms II - PS2
Analysis of Algorithms II - PS2
 
Analysis of Algorithms II - PS5
Analysis of Algorithms II - PS5Analysis of Algorithms II - PS5
Analysis of Algorithms II - PS5
 
2.03.Asymptotic_analysis.pptx
2.03.Asymptotic_analysis.pptx2.03.Asymptotic_analysis.pptx
2.03.Asymptotic_analysis.pptx
 
POWER GATING STRUCTURE FOR REVERSIBLE PROGRAMMABLE LOGIC ARRAY
POWER GATING STRUCTURE FOR REVERSIBLE PROGRAMMABLE LOGIC ARRAYPOWER GATING STRUCTURE FOR REVERSIBLE PROGRAMMABLE LOGIC ARRAY
POWER GATING STRUCTURE FOR REVERSIBLE PROGRAMMABLE LOGIC ARRAY
 
POWER GATING STRUCTURE FOR REVERSIBLE PROGRAMMABLE LOGIC ARRAY
POWER GATING STRUCTURE FOR REVERSIBLE PROGRAMMABLE LOGIC ARRAYPOWER GATING STRUCTURE FOR REVERSIBLE PROGRAMMABLE LOGIC ARRAY
POWER GATING STRUCTURE FOR REVERSIBLE PROGRAMMABLE LOGIC ARRAY
 
Arithmetic Operations in Multi-Valued Logic
Arithmetic Operations in Multi-Valued LogicArithmetic Operations in Multi-Valued Logic
Arithmetic Operations in Multi-Valued Logic
 
Implementation of Low Power and Area-Efficient Carry Select Adder
Implementation of Low Power and Area-Efficient Carry Select AdderImplementation of Low Power and Area-Efficient Carry Select Adder
Implementation of Low Power and Area-Efficient Carry Select Adder
 
Arithmetic Operations in Multi-Valued Logic
Arithmetic Operations in Multi-Valued Logic   Arithmetic Operations in Multi-Valued Logic
Arithmetic Operations in Multi-Valued Logic
 
Efficient Design of Reversible Multiplexers with Low Quantum Cost
Efficient Design of Reversible Multiplexers with Low Quantum CostEfficient Design of Reversible Multiplexers with Low Quantum Cost
Efficient Design of Reversible Multiplexers with Low Quantum Cost
 
A Simulink model for modified fountain codes
A Simulink model for modified fountain codesA Simulink model for modified fountain codes
A Simulink model for modified fountain codes
 
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
IJCER (www.ijceronline.com) International Journal of computational Engineerin...IJCER (www.ijceronline.com) International Journal of computational Engineerin...
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
 
Design and implementation of address generator for wi max deinterleaver on fpga
Design and implementation of address generator for wi max deinterleaver on fpgaDesign and implementation of address generator for wi max deinterleaver on fpga
Design and implementation of address generator for wi max deinterleaver on fpga
 
Final Project Report
Final Project ReportFinal Project Report
Final Project Report
 
Unit 2
Unit 2Unit 2
Unit 2
 
Multiuser detection new
Multiuser detection newMultiuser detection new
Multiuser detection new
 
OTP, Phishing, QR code, Shares, Visual Cryptography.
OTP, Phishing, QR code, Shares, Visual Cryptography.OTP, Phishing, QR code, Shares, Visual Cryptography.
OTP, Phishing, QR code, Shares, Visual Cryptography.
 
kalaivaanar_NSK_V3.ppt
kalaivaanar_NSK_V3.pptkalaivaanar_NSK_V3.ppt
kalaivaanar_NSK_V3.ppt
 
Grds international conference on pure and applied science (9)
Grds international conference on pure and applied science (9)Grds international conference on pure and applied science (9)
Grds international conference on pure and applied science (9)
 
A novel vedic divider based crypto-hardware for nanocomputing paradigm: An ex...
A novel vedic divider based crypto-hardware for nanocomputing paradigm: An ex...A novel vedic divider based crypto-hardware for nanocomputing paradigm: An ex...
A novel vedic divider based crypto-hardware for nanocomputing paradigm: An ex...
 
Unit 2
Unit 2Unit 2
Unit 2
 

More from AtakanAral

Resource Mapping Optimization for Distributed Cloud Services - PhD Thesis Def...
Resource Mapping Optimization for Distributed Cloud Services - PhD Thesis Def...Resource Mapping Optimization for Distributed Cloud Services - PhD Thesis Def...
Resource Mapping Optimization for Distributed Cloud Services - PhD Thesis Def...
AtakanAral
 
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
AtakanAral
 
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
AtakanAral
 
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Proposal]
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Proposal]Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Proposal]
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Proposal]
AtakanAral
 

More from AtakanAral (18)

Subgraph Matching for Resource Allocation in the Federated Cloud Environment
Subgraph Matching for Resource Allocation in the Federated Cloud EnvironmentSubgraph Matching for Resource Allocation in the Federated Cloud Environment
Subgraph Matching for Resource Allocation in the Federated Cloud Environment
 
Quality of Service Channelling for Latency Sensitive Edge Applications
Quality of Service Channelling for Latency Sensitive Edge ApplicationsQuality of Service Channelling for Latency Sensitive Edge Applications
Quality of Service Channelling for Latency Sensitive Edge Applications
 
Resource Mapping Optimization for Distributed Cloud Services - PhD Thesis Def...
Resource Mapping Optimization for Distributed Cloud Services - PhD Thesis Def...Resource Mapping Optimization for Distributed Cloud Services - PhD Thesis Def...
Resource Mapping Optimization for Distributed Cloud Services - PhD Thesis Def...
 
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
 
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
 
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
 
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
 
Software Engineering - RS4
Software Engineering - RS4Software Engineering - RS4
Software Engineering - RS4
 
Software Engineering - RS3
Software Engineering - RS3Software Engineering - RS3
Software Engineering - RS3
 
Software Engineering - RS2
Software Engineering - RS2Software Engineering - RS2
Software Engineering - RS2
 
Software Engineering - RS1
Software Engineering - RS1Software Engineering - RS1
Software Engineering - RS1
 
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Proposal]
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Proposal]Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Proposal]
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Proposal]
 
Improving Resource Utilization in Cloud using Application Placement Heuristics
Improving Resource Utilization in Cloud using Application Placement HeuristicsImproving Resource Utilization in Cloud using Application Placement Heuristics
Improving Resource Utilization in Cloud using Application Placement Heuristics
 
Analysis of Algorithms - 5
Analysis of Algorithms - 5Analysis of Algorithms - 5
Analysis of Algorithms - 5
 
Analysis of Algorithms - 3
Analysis of Algorithms - 3Analysis of Algorithms - 3
Analysis of Algorithms - 3
 
Analysis of Algorithms - 2
Analysis of Algorithms - 2Analysis of Algorithms - 2
Analysis of Algorithms - 2
 
Analysis of Algorithms - 1
Analysis of Algorithms - 1Analysis of Algorithms - 1
Analysis of Algorithms - 1
 
Mobile Multi-domain Search over Structured Web Data
Mobile Multi-domain Search over Structured Web DataMobile Multi-domain Search over Structured Web Data
Mobile Multi-domain Search over Structured Web Data
 

Recently uploaded

Recently uploaded (20)

Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 

Analysis of Algorithms II - PS3

  • 1. Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s BLG 336E – Analysis of Algorithms II Practice Session 3 Atakan Aral Istanbul Technical University – Department of Computer Engineering 25.03.2014 Atakan Aral Istanbul Technical University – Department of Computer Engineering BLG 336E – Analysis of Algorithms II
  • 2. Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s Outline 1 Dijkstra Algorithm Problem Solution 2 Street Lights Problem Solution 3 MST and Shortest Path True or False? 4 Median of Two DB’s Problem Solution Atakan Aral Istanbul Technical University – Department of Computer Engineering BLG 336E – Analysis of Algorithms II
  • 3. Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s Problem [Midterm 2013] Compute the shortest path from node 4 to node 1 in the following undirected graph using the greedy algorithm we learned in the class. 3 5 2 4 6 1 2 7 9 3 5 4 Atakan Aral Istanbul Technical University – Department of Computer Engineering BLG 336E – Analysis of Algorithms II
  • 4. Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s Solution 3 5 2 4 6 1 2 7 9 3 5 4 d(4) : {∞, ∞, ∞, 0, ∞}, s : {4} d(4) : {∞, 2, ∞, 0, 7}s : {4, 2} d(4) : {6, 2, 11, 0, 5}, s : {4, 2, 5} d(4) : {6, 2, 10, 0, 5}, s : {4, 2, 5, 1} d(4) : {6, 2, 10, 0, 5}, s : {4, 2, 5, 1, 3} Atakan Aral Istanbul Technical University – Department of Computer Engineering BLG 336E – Analysis of Algorithms II
  • 5. Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s Problem Local government wants to reduce operating costs of road lighting. Not every road will be illuminated at night. For safety, there will be at least one illuminated path between all junctions. Suggest an algorithm to optimize the road lighting What is the maximum saving without endangering the citizens? Atakan Aral Istanbul Technical University – Department of Computer Engineering BLG 336E – Analysis of Algorithms II
  • 6. Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s Problem Input contains the junctions and the roads connecting them As well as, the cost of illuminating each road. File format is as follows: 7 11 0 1 7 0 3 5 1 2 8 1 3 9 1 4 7 2 4 5 3 4 15 3 5 6 4 5 8 4 6 9 5 6 11 Atakan Aral Istanbul Technical University – Department of Computer Engineering BLG 336E – Analysis of Algorithms II
  • 7. Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s Solution 3 4 1 2 5 6 5 9 11 0 6 8 5 8 9 7 15 7 g Atakan Aral Istanbul Technical University – Department of Computer Engineering BLG 336E – Analysis of Algorithms II
  • 8. Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s Solution 3 4 1 2 5 6 5 9 11 0 6 8 5 8 9 7 15 7 g Atakan Aral Istanbul Technical University – Department of Computer Engineering BLG 336E – Analysis of Algorithms II
  • 9. Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s Solution 3 4 1 2 5 6 5 9 11 0 6 8 5 8 9 7 15 7 g Atakan Aral Istanbul Technical University – Department of Computer Engineering BLG 336E – Analysis of Algorithms II
  • 10. Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s Solution 3 4 1 2 5 6 5 9 11 0 6 8 5 8 9 7 15 7 g Atakan Aral Istanbul Technical University – Department of Computer Engineering BLG 336E – Analysis of Algorithms II
  • 11. Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s Solution 3 4 1 2 5 6 5 9 11 0 6 8 5 8 9 7 15 7 g Atakan Aral Istanbul Technical University – Department of Computer Engineering BLG 336E – Analysis of Algorithms II
  • 12. Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s Solution 3 4 1 2 5 6 5 9 11 0 6 8 5 8 9 7 15 7 g Atakan Aral Istanbul Technical University – Department of Computer Engineering BLG 336E – Analysis of Algorithms II
  • 13. Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s Solution 3 4 1 2 5 6 5 9 11 0 6 8 5 8 9 7 15 7 Total cost: 90 – Optimized cost: 39 – Saving: 51 Atakan Aral Istanbul Technical University – Department of Computer Engineering BLG 336E – Analysis of Algorithms II
  • 14. Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s True or False? Let G be an arbitrary connected, undirected graph with a positive distinct cost c(e) on every edge e. Let T be a MST of G. If we replace edge cost c(e) with c(e) ∗ c(e) , T must still be MST for G. Same is valid for c(e) + 5. It is also valid if negative costs are allowed. 2 4 3 MST depends only on the order of the costs, actual values are not important as long as order is the same. Atakan Aral Istanbul Technical University – Department of Computer Engineering BLG 336E – Analysis of Algorithms II
  • 15. Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s True or False? Let G be an arbitrary connected, directed graph with a positive cost c(e) on every edge e. Let P be the shortest path between node s and node t in G. If we replace edge cost c(e) with c(e)2, P must still be shortest path between node s and node t in G. Same is valid for c(e) + 5. e t 2 s 2 3 e t 2 s 2 5 For shortest paths, actual values of the costs do matter. Atakan Aral Istanbul Technical University – Department of Computer Engineering BLG 336E – Analysis of Algorithms II
  • 16. Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s Problem You are interested in analyzing some hard-to-obtain data from two separate databases A and B. Each database contains n numerical values and you may assume that no two values are the same. Determine the median of this set of 2n values Only way you can access these values is through queries to the databases: In a single query, you can specify a value i to one of the two databases, and the chosen database will return the ith smallest value that it contains. Since queries are expensive, you would like to compute the median using as few queries as possible. Give an algorithm that finds the median value using at most O(logn) queries. Atakan Aral Istanbul Technical University – Department of Computer Engineering BLG 336E – Analysis of Algorithms II
  • 17. Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s Solution Formulation Let k = n/2 then A(k) and B(k) are the medians of databases A and B. We are looking for C(n) where C is the merged database. If A(k) < B(k) then: B(k) > A(1), A(2), ..., A(k) B(k) > B(1), B(2), ..., B(k − 1) B(k) is greater than at least 2k − 1 elements. B(k) ≥ C(n) so no need to consider B(k + 1), B(k + 2), ..., B(n) Atakan Aral Istanbul Technical University – Department of Computer Engineering BLG 336E – Analysis of Algorithms II
  • 18. Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s Solution Formulation Let k = n/2 then A(k) and B(k) are the medians of databases A and B. We are looking for C(n) where C is the merged database. If A(k) < B(k) then: A(k) < B(k), B(k + 1), ..., B(n) A(k) < A(k + 1), A(k + 2), ..., A(n) A(k) is less than at least 2n − 2k − 1 elements. A(k) ≤ C(n) so no need to consider A(1), A(2), ..., A(k − 1) Atakan Aral Istanbul Technical University – Department of Computer Engineering BLG 336E – Analysis of Algorithms II
  • 19. Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s Solution Otherwise, if A(k) > B(k) then: A(k) > B(1), B(2), ..., B(k) A(k) > A(1), A(2), ..., A(k − 1) A(k) ≥ C(n) so no need to consider A(k + 1), A(k + 2), ..., A(n) Similarly, B(k) < A(k), A(k + 1), ..., A(n) B(k) < B(k + 1), B(k + 2), ..., B(n) B(k) ≤ C(n) so no need to consider B(1), B(2), ..., B(k −1) Atakan Aral Istanbul Technical University – Department of Computer Engineering BLG 336E – Analysis of Algorithms II
  • 20. Dijkstra Algorithm Street Lights MST and Shortest Path Median of Two DB’s Solution median: n, a = 0, b = 0 1 if n == 1 then 2 return min(A(1), B(1)) 3 end 4 k = n/2 ; 5 if A(a + k) < B(b + k) then 6 return median(k, a + n/2 , b) 7 end 8 else 9 return median(k, a, b + n/2 ) 10 end Array size is halved at each recursion. So the complexity is O(logn). Atakan Aral Istanbul Technical University – Department of Computer Engineering BLG 336E – Analysis of Algorithms II