Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 61b: Final Review Data Structures Steve Sinha and Winston Liaw.

Similar presentations


Presentation on theme: "CS 61b: Final Review Data Structures Steve Sinha and Winston Liaw."— Presentation transcript:

1 CS 61b: Final Review Data Structures Steve Sinha and Winston Liaw

2 Final Review 2 DISCLAIMER NOT We have NOT seen the exam. NOT We do NOT know the format of the exam What we are presenting is what we “think is important” for the exam

3 Steve Sinha and Winston Liaw Final Review 3 Review Topics Inheritance, Method Calls Asymptotic Analysis Data Structures  Binary Search Trees  B-Trees  Heaps  Hash Tables Graphs  DFS, BFS  Topological Sort  Dijkstra  Kruskal Sorting Skip Lists Threading, Synchronization

4 Steve Sinha and Winston Liaw Final Review 4 Inheritance/Method Calls Given the class definitions on the next slide, which lines in class foobarbaz are illegal?

5 Steve Sinha and Winston Liaw Final Review 5 Inheritance package foo; public class foo { static void f1() {…} protected boolean f2(int x) {…} private String f3(String s) {…} } package bar; import foo.foo; public class bar extends foo { protected boolean f3(int x) {…} } package foo; public class baz extends foo { private String f3(String s) {…} } package foo; import bar.bar; public class foobarbaz { static void main(String[] args) { foo f = new foo(); bar r = new bar(); baz z; r.f3(3); f.f2(3); z = (baz) f; f = new baz(); f.f2(3); z = (baz) f; z.f1(); r.f1(); ((foo) r).f1(); }

6 Steve Sinha and Winston Liaw Final Review 6 Inheritance/Method Calls Access table: Static methods called according to static type Child type can be assigned to parent variable without a cast, but the reverse requires one, and the dynamic types must match worldpackagechilddefiner public XXXX private X protected XXX XX

7 Steve Sinha and Winston Liaw Final Review 7 Inheritance package foo; public class foo { static void f1() {…} protected boolean f2(int x) {…} private String f3(String s) {…} } package bar; import foo.foo; public class bar extends foo { protected boolean f3(int x) {…} } package foo; public class baz extends foo { private String f3(String s) {…} } package foo; import bar.bar; public class foobarbaz { static void main(String[] args) { foo f = new foo(); bar r = new bar(); baz z; r.f3(3); // ILLEGAL f.f2(3); z = (baz) f; // ILLEGAL f = new baz(); f.f2(3); z = (baz) f; z.f1(); r.f1();// ILLEGAL ((foo) r).f1(); }

8 Steve Sinha and Winston Liaw Final Review 8 Asymptotic Analysis O– Upper bound/Worst case Ω– Lower bound θ– both o – strictly Upper bound More detail…

9 Steve Sinha and Winston Liaw Final Review 9 Asymptotic Analysis T(n) is O( f(n) ) if and only if there exists positive constants C and N such that T(n) = N n T(n) 5 f(n) f(n) T(n) = 4n f(n) = n 4n is O( n )

10 Steve Sinha and Winston Liaw Final Review 10 Asymptotic Analysis T(n) is O( f(n) ) if and only if there exists positive constants C and N such that T(n) = N N n T(n) C f(n)

11 Steve Sinha and Winston Liaw Final Review 11 Asymptotic Analysis T(n) is O( f(n) ) if and only if there exists positive constants C and N such that T(n) = N T(n) is Ω( f(n) ) if and only if there exists positive constants C and N such that T(n) >= C f(n) for all n >= N

12 Steve Sinha and Winston Liaw Final Review 12 Asymptotic Analysis T(n) is θ ( f(n) ) if and only if T(n) is O( f(n) ) and T(n) is Ω( f(n) ) Examples 5n 2 +1 is θ (n 2 ) 3n is O(n 2 ), but 3n is NOT θ (n 2 ) because 3n is not Ω(n 2 )

13 Steve Sinha and Winston Liaw Final Review 13 Asymptotic Analysis Problem Find the running time of the following code: int foo(int x) { int ans = 1; for (int i = 0; i < x; i++) { for (int j = 0; j < i; j++) { ans *= (i + j); } return ans; }

14 Steve Sinha and Winston Liaw Final Review 14 Asymptotic Analysis Solution The nested loops give away the answer: the outer loop executes x times, the inner loop an average of x/2 times, for a running time of O(x 2 ). int foo(int x) { int ans = 1; for (int i = 0; i < x; i++) { for (int j = 0; j < i; j++) { ans *= (i + j); } return ans; }

15 Steve Sinha and Winston Liaw Final Review 15 Trees: Binary Tree Tree: A B C DE F G Preorder :ABCEGFD Inorder :CEBAGDF Postorder: ECBDFGA What are the Pre-, In-, and Post- order traversals of this tree?

16 Steve Sinha and Winston Liaw Final Review 16 Trees: BST Problem Remove 8 from: 8 75 3 11 13 1 6 9

17 Steve Sinha and Winston Liaw Final Review 17 Trees: BST Problem Remove 8 from: 8 75 3 11 13 1 Replace with successor (left-most node in right subtree) 6 9

18 Steve Sinha and Winston Liaw Final Review 18 Trees: BST Solution Final tree: 9 75 3 11 13 1 6

19 Steve Sinha and Winston Liaw Final Review 19 Trees: B-Tree of Order 4 / 2-3-4 Tree Suggest a sequence of operations that would create the 2-3-4 tree. You can use removal as well as insertion. 5, 7 2, 468

20 Steve Sinha and Winston Liaw Final Review 20 Trees: 2-3-4 Tree Solution Insert: 4, 5, 6, 7, 8, 9, 2 Remove: 9 4, 5, 6

21 Steve Sinha and Winston Liaw Final Review 21 Trees: 2-3-4 Tree Solution Insert: 4, 5, 6, 7, 8, 9, 2 Remove: 9 4, 5, 6 Touch node size = 3

22 Steve Sinha and Winston Liaw Final Review 22 Trees: 2-3-4 Tree Solution Insert: 4, 5, 6, 7, 8, 9, 2 Remove: 9 5 6, 74

23 Steve Sinha and Winston Liaw Final Review 23 Trees: 2-3-4 Tree Solution Insert: 4, 5, 6, 7, 8, 9, 2 Remove: 9 5 6, 7, 84

24 Steve Sinha and Winston Liaw Final Review 24 Trees: 2-3-4 Tree Solution Insert: 4, 5, 6, 7, 8, 9, 2 Remove: 9 5 6, 7, 84 Touch node size = 3

25 Steve Sinha and Winston Liaw Final Review 25 Trees: 2-3-4 Tree Solution Insert: 4, 5, 6, 7, 8, 9, 2 Remove: 9 5, 7 468, 9

26 Steve Sinha and Winston Liaw Final Review 26 Trees: 2-3-4 Tree Solution Insert: 4, 5, 6, 7, 8, 9, 2 Remove: 9 5, 7 2, 468

27 Steve Sinha and Winston Liaw Final Review 27 Priority Queues – Problem Add 9, 76, 54, 3, 33, 21 to a max heap, using only the array based representation

28 Steve Sinha and Winston Liaw Final Review 28 Priority Queues – Insertion Insert at the last position in the heap Reheapify up: if the element is greater than its parent, swap them and repeat For an element at position n, its children are at 2n+1 and 2n+2 For an element at position n, its parent is at floor[(n-1)/2]

29 Steve Sinha and Winston Liaw Final Review 29 Priority Queues – Solution Add 9, 76, 54, 3, 33, 21 to a max heap, using only the array based representation 9… 012345…

30 Steve Sinha and Winston Liaw Final Review 30 Priority Queues – Solution Add 9, 76, 54, 3, 33, 21 to a max heap, using only the array based representation 976… 012345… 9… 012345…

31 Steve Sinha and Winston Liaw Final Review 31 Priority Queues – Solution Add 9, 76, 54, 3, 33, 21 to a max heap, using only the array based representation 76954… 012345…

32 Steve Sinha and Winston Liaw Final Review 32 Priority Queues – Solution Add 9, 76, 54, 3, 33, 21 to a max heap, using only the array based representation 769543… 012345…

33 Steve Sinha and Winston Liaw Final Review 33 Priority Queues – Solution Add 9, 76, 54, 3, 33, 21 to a max heap, using only the array based representation 76954333… 012345… 76335439… 012345…

34 Steve Sinha and Winston Liaw Final Review 34 Priority Queues – Solution 7633543921… 012345… 76 33 54 3921 Tree Representation Add 9, 76, 54, 3, 33, 21 to a max heap, using only the array based representation

35 Steve Sinha and Winston Liaw Final Review 35 Priority Queues – Problem 7633543921… 012345… Remove the max from the heap

36 Steve Sinha and Winston Liaw Final Review 36 Priority Queues – Removal Replace the max element with the last element in the heap Reheapify down: if one or both of its children is larger than it, swap with the larger of the children and repeat For an element at position n, its children are at 2n+1 and 2n+2 For an element at position n, its parent is at floor[(n-1)/2]

37 Steve Sinha and Winston Liaw Final Review 37 Priority Queues – Solution 7633543921… 012345… 335439… 012345… Remove the max from the heap

38 Steve Sinha and Winston Liaw Final Review 38 Priority Queues – Solution 21335439… 012345… 332139… 012345… Remove the max from the heap

39 Steve Sinha and Winston Liaw Final Review 39 Priority Queues – Solution 54332139… 012345… 54 33 21 39 Tree Representation Remove the max from the heap

40 Steve Sinha and Winston Liaw Final Review 40 Hash Table Problem Draw the structure of a size 7 hash table after insertion of keys with the following hash codes: 0, 95, 21, 6, 64, 74, 3, 54, 34, 75, 10.

41 Steve Sinha and Winston Liaw Final Review 41 Hash Tables High-level idea – 2 components 1. Big array called hash table of size M 2. Function h which maps keys to integer values For (key, item), use h(key) % M to find location of item in table Linked list in each entry that stores all items that map to that location (chaining)

42 Steve Sinha and Winston Liaw Final Review 42 Hash Table Solution Draw the structure of a size 7 hash table after insertion of keys with the following hash codes: 0, 95, 21, 6, 64, 74, 3, 54, 34, 75, 10. 0123456 0 21 643 10 95 74 54 75 6 34

43 Steve Sinha and Winston Liaw Final Review 43 Searches (BFS and DFS) BFS uses a queue, DFS uses a stack public void BFS/DFS(Node start) { Queue/Stack s = new Queue/Stack(); s.enqueue/push(start); while (!s.empty()) { Node n = s.dequeue/pop(); mark(n); for (all children that are not yet marked) { s.enqueue/push(child); }

44 Steve Sinha and Winston Liaw Final Review 44 Searches (BFS and DFS) Problem Perform BFS and DFS on the graph, starting at node 1 5 32 6 7 4 1

45 Steve Sinha and Winston Liaw Final Review 45 Searches (BFS and DFS) Solution Perform BFS and DFS on the graph, starting at node 1 5 32 6 7 4 1 BFS 1 2 5 3 4 6 7 DFS 1 2 3 4 5 6 7

46 Steve Sinha and Winston Liaw Final Review 46 Example graph Introduction Kiss Date I can’t say what goes in this box Flirt Hug Personal Ad Give me an ordering that I can do these in so that I don’t violate the dependencies (or my date).

47 Steve Sinha and Winston Liaw Final Review 47 Topological Sort Topological sorting gives us an ordering which won’t violate these dependencies.  Perform a DFS from each source (root), marking start and finish times.  Now, our ordering is simply the nodes we visited in decreasing finishing time.

48 Steve Sinha and Winston Liaw Final Review 48 Example graph Introduction Kiss Date I can’t say what goes in this box Flirt Hug Personal Ad 1.Personal Ad 2.Introduction 3.Flirt 4.Date 5.Hug 6.Kiss 7.Umm… 5/8 1/12 6/7 4/9 2/113/10 13/14

49 Steve Sinha and Winston Liaw Final Review 49 Dijkstra’s Algorithm Problem 5 32 6 7 4 1 10 6 3 13 5 1 12 8 16 4 2 3 7 9 Find the shortest distances to each node from node 1

50 Steve Sinha and Winston Liaw Final Review 50 Dijkstra’s Algorithm Set all distances initially to ∞, except the start node, which should be set to 0 Construct a min priority queue of the nodes, with their distances as keys Repeatedly remove the minimum element, updating each of its adjacent node’s distances if they are still in the queue and if the updated distance is less than the current distance

51 Steve Sinha and Winston Liaw Final Review 51 Dijkstra’s Algorithm Solution 5 32 6 7 4 1 10 6 3 13 5 1 12 8 16 4 2 3 7 9 P.Q. 1 (0) 2 (∞) 3 (∞) 4 (∞) 5 (∞) 6 (∞) 7 (∞) ∞ ∞ ∞ ∞ ∞ ∞ 0 Find the shortest distances to each node from node 1

52 Steve Sinha and Winston Liaw Final Review 52 Dijkstra’s Algorithm Solution 5 32 6 7 4 1 10 6 3 13 5 1 12 8 16 4 2 3 7 9 P.Q. x1 (0) 2 (3) 3 (9) 5 (13) 4 (∞) 6 (∞) 7 (∞) 13 ∞ 3 ∞ 9 ∞ 0 Find the shortest distances to each node from node 1

53 Steve Sinha and Winston Liaw Final Review 53 Dijkstra’s Algorithm Solution 5 32 6 7 4 1 10 6 3 13 5 1 12 8 16 4 2 3 7 9 P.Q. x1 (0) x2 (3) 3 (9) 5 (13) 4 (13) 6 (∞) 7 (∞) 13 ∞ 3 9 ∞ 0 Find the shortest distances to each node from node 1

54 Steve Sinha and Winston Liaw Final Review 54 Dijkstra’s Algorithm Solution 5 32 6 7 4 1 10 6 3 13 5 1 12 8 16 4 2 3 7 9 P.Q. x1 (0) x2 (3) x3 (9) 5 (10) 4 (11) 7 (16) 6 (∞) 10 ∞ 3 11 9 16 0 Find the shortest distances to each node from node 1

55 Steve Sinha and Winston Liaw Final Review 55 Dijkstra’s Algorithm Solution 5 32 6 7 4 1 10 6 3 13 5 1 12 8 16 4 2 3 7 9 P.Q. x1 (0) x2 (3) x3 (9) x5 (10) 4 (11) 7 (15) 6 (18) 10 18 3 11 9 15 0 Find the shortest distances to each node from node 1

56 Steve Sinha and Winston Liaw Final Review 56 Dijkstra’s Algorithm Solution 5 32 6 7 4 1 10 6 3 13 5 1 12 8 16 4 2 3 7 9 P.Q. x1 (0) x2 (3) x3 (9) x5 (10) x4 (11) 7 (14) 6 (15) 10 15 3 11 9 14 0 Find the shortest distances to each node from node 1

57 Steve Sinha and Winston Liaw Final Review 57 Dijkstra’s Algorithm Solution 5 32 6 7 4 1 10 6 3 13 5 1 12 8 16 4 2 3 7 9 P.Q. x1 (0) x2 (3) x3 (9) x5 (10) x4 (11) x7 (14) 6 (15) 10 15 3 11 9 14 0 Find the shortest distances to each node from node 1

58 Steve Sinha and Winston Liaw Final Review 58 Dijkstra’s Algorithm Solution 5 32 6 7 4 1 10 6 3 13 5 1 12 8 16 4 2 3 7 9 P.Q. x1 (0) x2 (3) x3 (9) x5 (10) x4 (11) x7 (14) x6 (15) 10 15 3 11 9 14 0 Find the shortest distances to each node from node 1

59 Steve Sinha and Winston Liaw Final Review 59 Kruskal’s Algorithm Problem 5 32 6 7 4 1 10 6 3 13 5 1 12 8 16 4 2 Find the MST of the graph, using Kruskal’s Algorithm

60 Steve Sinha and Winston Liaw Final Review 60 Kruskal’s Algorithm Put each node into a set by itself Sort all the edges in ascending order by their weights Pick the least-weight edge, if the edge connects two nodes in different sets, add the edge to the MST and merge the two sets

61 Steve Sinha and Winston Liaw Final Review 61 Kruskal’s Algorithm Solution 5 32 6 7 4 1 10 6 3 13 5 1 12 8 16 4 Edges 3-5 (1) 3-4 (2) 1-2 (3) 4-6 (4) 5-7 (5) 2-3 (6) 5-6 (8) 2-4 (10) 5-6 (12) 1-5 (13) 6-7 (16) 2 Find the MST of the graph, using Kruskal’s Algorithm

62 Steve Sinha and Winston Liaw Final Review 62 Kruskal’s Algorithm Solution 5 32 6 7 4 1 10 6 3 13 5 1 12 8 16 4 Edges x3-5 (1) 3-4 (2) 1-2 (3) 4-6 (4) 5-7 (5) 2-3 (6) 5-6 (8) 2-4 (10) 5-6 (12) 1-5 (13) 6-7 (16) 2 Find the MST of the graph, using Kruskal’s Algorithm

63 Steve Sinha and Winston Liaw Final Review 63 Kruskal’s Algorithm Solution 5 32 6 7 4 1 10 6 3 13 5 1 12 8 16 4 Edges x3-5 (1) x3-4 (2) 1-2 (3) 4-6 (4) 5-7 (5) 2-3 (6) 5-6 (8) 2-4 (10) 5-6 (12) 1-5 (13) 6-7 (16) 2 Find the MST of the graph, using Kruskal’s Algorithm

64 Steve Sinha and Winston Liaw Final Review 64 Kruskal’s Algorithm Solution 5 32 6 7 4 1 10 6 3 13 5 1 12 8 16 4 Edges x3-5 (1) x3-4 (2) x1-2 (3) 4-6 (4) 5-7 (5) 2-3 (6) 5-6 (8) 2-4 (10) 5-6 (12) 1-5 (13) 6-7 (16) 2 Find the MST of the graph, using Kruskal’s Algorithm

65 Steve Sinha and Winston Liaw Final Review 65 Kruskal’s Algorithm Solution 5 32 6 7 4 1 10 6 3 13 5 1 12 8 16 4 Edges x3-5 (1) x3-4 (2) x1-2 (3) x4-6 (4) 5-7 (5) 2-3 (6) 5-6 (8) 2-4 (10) 5-6 (12) 1-5 (13) 6-7 (16) 2 Find the MST of the graph, using Kruskal’s Algorithm

66 Steve Sinha and Winston Liaw Final Review 66 Kruskal’s Algorithm Solution 5 32 6 7 4 1 10 6 3 13 5 1 12 8 16 4 Edges x3-5 (1) x3-4 (2) x1-2 (3) x4-6 (4) x5-7 (5) 2-3 (6) 5-6 (8) 2-4 (10) 5-6 (12) 1-5 (13) 6-7 (16) 2 Find the MST of the graph, using Kruskal’s Algorithm

67 Steve Sinha and Winston Liaw Final Review 67 Kruskal’s Algorithm Solution 5 32 6 7 4 1 10 6 3 13 5 1 12 8 16 4 Edges x3-5 (1) x3-4 (2) x1-2 (3) x4-6 (4) x5-7 (5) x2-3 (6) 5-6 (8) 2-4 (10) 5-6 (12) 1-5 (13) 6-7 (16) 2 Find the MST of the graph, using Kruskal’s Algorithm

68 Steve Sinha and Winston Liaw Final Review 68 Kruskal’s Algorithm Solution 5 32 6 7 4 1 6 3 5 1 4 2 Find the MST of the graph, using Kruskal’s Algorithm

69 Steve Sinha and Winston Liaw Final Review 69 Disjoint Sets – Problem Given the following array representation of a disjoint sets data structure: [2 5 -3 5 3 -3 2 2 3 0] a) Draw the forest that this array represents. b) Give a sequence of union and find operations whose execution will convert the array to: [2 5 -3 2 5 2 2 2 2 0]

70 Steve Sinha and Winston Liaw Final Review 70 Disjoint Sets – Solution 0 1 2 3 4 5 6 7 8 9 [2 5 -3 5 3 -3 2 2 3 0] 2 5 / | \ / \ 0 6 7 1 3 / / \ 9 4 8

71 Steve Sinha and Winston Liaw Final Review 71 Disjoint Sets – Solution, cont. 2 5 / | \ / \ 0 6 7 1 3 / / \ 9 4 8 -----2------- / / | \ \ \ 0 6 7 5 3 8 | / \ 9 1 4 [2 5 -3 2 5 2 2 2 2 0] Find( 4 ) Union( 2, 5 ) Find( 8 )

72 Steve Sinha and Winston Liaw Final Review 72 Sorting Given the following steps, which sorting algorithms were used in each case? 13 27 89 26 9 37 5 1 38 1 27 89 26 9 37 5 13 38 1 5 89 26 9 37 27 13 38 1 5 9 26 89 37 27 13 38 1 5 9 13 89 37 27 26 38 1 5 9 13 26 37 27 89 38 1 5 9 13 26 27 37 89 38 1 5 9 13 26 27 37 38 89 13 27 89 26 9 37 5 1 38 13 27 26 9 37 5 1 38 89 1 13 27 26 9 37 5 38 89 1 5 13 27 26 9 37 38 89 1 5 9 13 27 26 37 38 89 1 5 9 13 26 27 37 38 89

73 Steve Sinha and Winston Liaw Final Review 73 Sorting Selection Sort Quick Sort 13 27 89 26 9 37 5 1 38 1 27 89 26 9 37 5 13 38 1 5 89 26 9 37 27 13 38 1 5 9 26 89 37 27 13 38 1 5 9 13 89 37 27 26 38 1 5 9 13 26 37 27 89 38 1 5 9 13 26 27 37 89 38 1 5 9 13 26 27 37 38 89 13 27 89 26 9 37 5 1 38 13 27 26 9 37 5 1 38 89 1 13 27 26 9 37 5 38 89 1 5 13 27 26 9 37 38 89 1 5 9 13 27 26 37 38 89 1 5 9 13 26 27 37 38 89

74 Steve Sinha and Winston Liaw Final Review 74 Sorting Do a radix sort on the following sequence, showing each step (1087 643 2532 954 8174 65 340 1752)

75 Steve Sinha and Winston Liaw Final Review 75 Sorting Step 1: sort by ones place (1087 643 2532 954 8174 65 340 1752) (340 2532 1752 643 954 8174 65 1087)

76 Steve Sinha and Winston Liaw Final Review 76 Sorting Step 2: sort by tens place (340 2532 1752 643 954 8174 65 1087) (2532 340 643 1752 954 65 8174 1087)

77 Steve Sinha and Winston Liaw Final Review 77 Sorting Step 3: sort by hundreds place (2532 340 643 1752 954 65 8174 1087) (65 1087 8174 340 2532 643 1752 954)

78 Steve Sinha and Winston Liaw Final Review 78 Sorting Step 4: sort by thousands place (65 1087 8174 340 2532 643 1752 954) (65 340 643 954 1087 1752 2532 8174)

79 Steve Sinha and Winston Liaw Final Review 79 Skip List Problem Write code for searching a skip list for a key. Assume a skip list node is defined as and that the skip list pointer references the top left node. class Node { Comparable key; Node left, right, up, down; }

80 Steve Sinha and Winston Liaw Final Review 80 Skip Lists 2D linked lists Bottom level contains all keys, and each subsequent level contains probabilistically half the keys of the previous level Each level starts at -∞ and ends at +∞ The keys in each level are in ascending order

81 Steve Sinha and Winston Liaw Final Review 81 Skip List Example -∞ ∞ ∞ ∞ ∞ -103918355984 -1091859 -109 9

82 Steve Sinha and Winston Liaw Final Review 82 Skip List Searching Start at top left node If the current key is equal to the search key, return the node If the next key is greater than the search key, go down and repeat search Otherwise go right and repeat search

83 Steve Sinha and Winston Liaw Final Review 83 Skip List Solution Write code for searching a skip list for a key Node search(Node n, Comparable key) { if (n.key.equals(key)) { return n; } else if (n.next.key.compareTo(key) > 0) { return search(n.down, key); } else { return search(n.next, key); }

84 Steve Sinha and Winston Liaw Final Review 84 Skip List Searching -∞ ∞ ∞ ∞ ∞ -103918355984 -1091859 -109 9 Search for 18 9 is not greater than 18, so move right

85 Steve Sinha and Winston Liaw Final Review 85 Skip List Searching -∞ ∞ ∞ ∞ ∞ -103918355984 -1091859 -109 9 Search for 18 ∞ is greater than 18, so move down

86 Steve Sinha and Winston Liaw Final Review 86 Skip List Searching -∞ ∞ ∞ ∞ ∞ -103918355984 -1091859 -109 9 Search for 18 ∞ is greater than 18, so move down

87 Steve Sinha and Winston Liaw Final Review 87 Skip List Searching -∞ ∞ ∞ ∞ ∞ -103918355984 -1091859 -109 9 Search for 18 18 is not greater than 18, so move right

88 Steve Sinha and Winston Liaw Final Review 88 Skip List Searching -∞ ∞ ∞ ∞ ∞ -103918355984 -1091859 -109 9 Search for 18 18 is equal to 18, so return node

89 Steve Sinha and Winston Liaw Final Review 89 Threading Motivations:  Modeling of simultaneous actions  Counteract I/O Latency Mechanism: Multiple threads of control  Shared memory space, multiple program counters Dangers:  Shared access to memory can result in conflicts  Multiple threads per processor can result in unequal time sharing (see scheduling) Conflict types:  WAR (write after read)  WAW (write after write)  RAW (read after write) How to avoid shared data conflicts? Locking Dangers of locking? Deadlock

90 Steve Sinha and Winston Liaw Final Review 90 Credits Thanks to CS 61b staff of  Fall 2001  Spring 2002  Summer 2002 Thanks to Amir and Jack Thanks to  CMU – MIT  Cornell – Johns Hopkins U for slide and example ideas

91 Steve Sinha and Winston Liaw Final Review 91 GOOD LUCK! (and may you not need it)


Download ppt "CS 61b: Final Review Data Structures Steve Sinha and Winston Liaw."

Similar presentations


Ads by Google