Presentation is loading. Please wait.

Presentation is loading. Please wait.

Perform DFS from A A B C D E F G. Perform BFS from A A B C D E F G.

Similar presentations


Presentation on theme: "Perform DFS from A A B C D E F G. Perform BFS from A A B C D E F G."— Presentation transcript:

1 Perform DFS from A A B C D E F G

2 Perform BFS from A A B C D E F G

3 Several Topological Orderings CSI CSII CSIII CS2813 CS4833 CSI, CS 2813, CSII, CS 4833, CSIIIor CS I, CS 2813, CSII, CSIII, CS 4833or CSI, CSII, CS 2813, CS 4833, CSIIIetc........

4 Linear Probing Hash(89,10) = 9 (hash function is key (89) % 10) Hash(18,10) = 8 Hash(49,10) = 9 Hash(58,10) = 8 Hash( 9,10) = 9 After Insert 89 0 1 2 3 4 5 6 7 8 9 89 After Insert 18 0 1 2 3 4 5 6 7 8 18 9 89 After Insert 49 0 49 1 2 3 4 5 6 7 8 18 9 89 After Insert 58 0 49 1 58 2 3 4 5 6 7 8 18 9 89 After Insert 9 0 49 1 58 2 9 3 4 5 6 7 8 18 9 89

5 Quadratic Probing Hash(89,10) = 9 Hash(18,10) = 8 Hash(49,10) = 9 Hash(58,10) = 8 Hash( 9,10) = 9 After Insert 89 0 1 2 3 4 5 6 7 8 9 89 After Insert 18 0 1 2 3 4 5 6 7 8 18 9 89 After Insert 49 0 49 1 2 3 4 5 6 7 8 18 9 89 After Insert 58 0 49 1 2 58 3 4 5 6 7 8 18 9 89 After Insert 9 0 49 1 2 58 3 9 4 5 6 7 8 18 9 89

6 Relational Algebra An Example Consider the example of parts that are shipped by various suppliers from warehouses in various cities where they are stored to jobs in different cities: SUPPLIER s# name status city S1 Smith 20 London S2 Jones 10 Paris S3 Blake 30 Paris S4 Clark 20 London S5 Adams 30 Athens PART p# name color weight city * P1 nut red 12 London P2 bolt green 17 Paris P3 screw blue 17 Rome P4 screw red 14 London P5 cam blue 12 Paris P6 cog red 19 London JOB j# name city J1 sorter Paris J2 punch Rome J3 reader Athens J4 console Athens J5 collator London J6 terminal Oslo * City where part is stored (example from: C.J. Date, An Introduction to Database Systems, Addison-Wesley, 1990)

7 Relational Algebra An Example  Find information about all red parts:  color = red ( PART ) u Find information about all red parts weighing more than 15 lbs:   (color = red) AND (weight > 15) ( PART )  Find names of all red parts:  name (  color = red ( PART ) )  Find names of suppliers with who are located in cities where screws are stored:  S.name (  P.name=screw ( SUPPLIER S.city = P.city PART ) )

8 Relational Algebra An Example SHIPMENT s# p# j# qty S1 P1 J1 200 S1 P1 J4 700 S2 P3 J1 400 S2 P3 J2 200 S2 P3 J3 200 S2 P3 J4 500 S2 P3 J5 600 S2 P3 J6 400 S2 P5 J2 100 S3 P3 J1 200 S3 P4 J2 500 S4 P6 J3 300 S5 P2 J2 200 S5 P2 J4 100 S5 P5 J5 500 S5 P6 J2 200 S5 P1 J4 100 S5 P3 J4 200 S5 P4 J4 800 S5 P5 J4 400 S5 P6 J4 500 Find names of suppliers who shipped more that 500 red parts Get part numbers for parts supplied by a supplier in London. Find Smith’s jobs that use red parts Find names of parts shipped by Jones for jobs in London Find names of red parts sent by London suppliers to Paris jobs

9 Analysis of Nested Loops EXAMPLE 1: for (int i = 0; i < n; i++)// n*O(n) = O(n 2 ) for (int j=0; j<n;j++)// n*O(1) = O(n) x++;// O(1) EXAMPLE 2: for (int i = 0; i < n; i++) for (int j=i; j<n;j++) x++;// O(1) T(n) = n+(n-1) + (n-2)+…+ 1 = n(n+1)/2 = O(n 2 )

10 Summing blocks of statements for (int i = 0; i < n; i++)// O(n 2 ) for (int j=0; j<n;j++) x++; for (int i = 0; i < n; i++)// O(n) x++; T(n) = O(n 2 ) + O(n) = O(n 2 + n) = O(n 2 )

11 Loops with different limits for (int i = 0; i < n; i++)// n*O(m) = O(mn) for (int j=0; j<m; j++)// m*O(1) = O(m) x++;// O(1) O(mn)

12 More complex loops for (i = 1;i < n; i *=2) x++; for (i=n; i > 0; i/=2) x++; Repetitive halving or doubling results in logarithmic complexity. Both loops are O( log n)

13 Allocating Free Blocks: Strategies first fit - Traverse the list to find available block large enough; allocate from first such block found best fit - Traverse the list to find the smallest available block that is large enough; allocate from it worst fit - Traverse list to find largest available block and allocate from it (if large enough)


Download ppt "Perform DFS from A A B C D E F G. Perform BFS from A A B C D E F G."

Similar presentations


Ads by Google