Sorting - PowerPoint PPT Presentation

About This Presentation
Title:

Sorting

Description:

output: Points r and s, with r s, such that distance(r,s) is the shortest distance ... (a,b) d2 distance(w,z) if (d1 d2) then (r,s,d) (a,b,d1) else (r,s,d) ... – PowerPoint PPT presentation

Number of Views:37
Avg rating:3.0/5.0
Slides: 11
Provided by: cseLe
Category:
Tags: sorting

less

Transcript and Presenter's Notes

Title: Sorting


1
Sorting Example with Insertion Sort
i 5 A E M P X L E
i 1 E X A M P L E
i 2 E X A M P L E
i 6 A E L M P X E
i 3 A E X M P L E
i 7 A E E L M P X
i 4 A E M X P L E
2
Closest Pair Pseudo-code
  • ClosestPair(P1..n)
  • //input P1..n a collection of points sorted by
    the x coordinates
  • //output Points r and s, with r ? s, such that
    distance(r,s) is the shortest distance among all
    pairs of points in P

If (n 2) then return (P1,P2)
C1 ? Select(P1..mid,c,d) C2 ?
Select(Pmid1..n,c,d) for each k in C1 do
Cand ? candidates(k,C2,d) //at most 6 points
will be in D for each ca in Cand do if
distance(k,ca) lt d) then d ?
distance(k,ca) (r,s) ?
(k,ca) return (r,s)
mid ? floor(n/2) c ? (Pmid.x
Pmid1.x)/2 (a,b) ? ClosestPair(P1..mid) (w,z)
? ClosestPair(Pmid1..n) d1 ? distance(a,b) d2
? distance(w,z) if (d1 lt d2) then (r,s,d) ?
(a,b,d1) else (r,s,d) ?(w,z,d2)
3
Graph Representations
G (E,V)
D
E
A
F
C
B
G
H
Adjacency lists vs. Adjacency Matrix (Pages 29,
30)
V2
V k 2 E
Size
4
Depth-First Search
  • Initially all nodes are marked with 0 (non
    visited).
  • Every node that is visited will be marked with a
    value of 1 or more
  • The number marking a node indicates its depth
    relative to other marked nodes
  • Complexity

Adjacency Lists O(V E)
Adjacency Matrix O(V2)
5
Breadth-First Search
  • Initially all nodes are marked with 0 (non
    visited).
  • Every node that is visited will be marked with a
    value of 1 or more
  • Use a queue (FIFO policy) to control order of
    visits
  • Complexity

Adjacency Lists O(V E)
Adjacency Matrix O(V2)
6
Questions about Graphs
  • Is the graph connected?
  • Find the connected components of the graph
  • Is the graph acyclic?
  • Find articulation points
  • Find minimum-number of edges

7
Applications of Graphs
  • In many problems, the graphs are not constructed
    apriori because they would be extremely large.
  • In such situations while the system is solving a
    problem, it is constructing the graph as-needed.
  • Example of such a problem Computer-generated
    Game plan

8
Planning Simple Example
A B C
C A
B
Initial
Goal
(on A Table) (on C A) (on B Table) (clear B)
(clear C)
(on C Table) (on B C) (on A B) (clear A)
9
Search Space A Graph!
C
A
B
C
A
B
C
B
A
B
A
C
A
B
C
B
A
B
C
B
C
A
B
A
C
C
A
A
A
B
C
B
C
C
B
A
A
B
C
10
Homework (Optional)
  • 5.2 2, 1.b, 4, 6, 7, 10
Write a Comment
User Comments (0)
About PowerShow.com