Download presentation
Presentation is loading. Please wait.
1
Data Structures & Problem Solving
Appendix A Operators Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss © Addison Wesley
2
Figure A.1 Java operators listed from highest to lowest precedence
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
3
Data Structures & Problem Solving
Appendix B Graphical User Interfaces Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss © Addison Wesley
4
Figure B.1 A GUI that illustrates some of the basic Swing components
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
5
Figure B.2 Compressed hierarchy of Swing
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
6
Figure B.5 Five buttons arranged using BorderLayout
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
7
Data Structures & Problem Solving
Chapter 1 Primitive Java Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss © Addison Wesley
8
Figure 1.2 The eight primitive types in Java
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
9
Figure 1.4 Result of logical operators
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
10
Data Structures & Problem Solving
Chapter 2 Reference Types Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss © Addison Wesley
11
Figure 2.1 An illustration of a reference: The Point object stored at memory location 1000 is referenced by both point1 and point3. The point object stored at memory location 1024 is referenced by point2. The memory locations where the variables are stored are arbitrary. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
12
Figure 2.2 The result of point3=point2: point3 now references the same object as point2. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
13
Figure 2.3 (A) The result of call-by-value. (a) b is a copy of yesButton; (b) after b.setLabel("No"): changes to the state of the object referenced by b are reflected in the object referenced by yesButton because these are the same object. (continued) Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
14
Figure 2.3 (B) The result of call-by-value. (c) after b=null: change to the value of b does not affect the value of yesButton; (d) after the method returns, b is out of scope. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
15
Figure 2.5 (A) Array expansion, internally: (a) At the starting point, arr represents 10 integers; (b) after step 1, original represents the same 10 integers. (continued) Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
16
Figure 2.5 (B) Array expansion, internally: (c) after steps 2 and 3, arr represents 12 integers, the first 10 of which are copied from original ; and (d) after step 4, the 10 integers are available for reclamation. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
17
Figure 2.12 Common standard run-time exceptions
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
18
Figure 2.13 Common standard checked exceptions
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
19
Data Structures & Problem Solving
Chapter 3 Objects and Classes Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss © Addison Wesley
20
Figure 3.2 IntCell members: read and write are accessible, but storedValue is hidden. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
21
Figure 3.5 (A) javadoc output for Figure 3.4 (partial output) (continued) Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
22
Figure 3.5 (B) javadoc output for Figure 3.4 (partial output)
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
23
Figure 3.9 Packages defined in this text
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
24
Data Structures & Problem Solving
Chapter 4 Inheritance Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss © Addison Wesley
25
Figure 4.4 Memory layout with inheritance. Light shading indicates fields that are private, and accessible only by methods of the class. Dark shading in the Student class indicates fields that are not accessible in the Student class, but are nonetheless present. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
26
Figure 4.6 The Person hierarchy
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
27
Figure 4.10 The hierarchy of shapes used in an inheritance example
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
28
Figure 4.17 The hierarchy of exceptions (partial list)
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
29
Figure 4.37 Four types of class methods
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
30
Data Structures & Problem Solving
Chapter 5 Algorithm Analysis Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss © Addison Wesley
31
Figure 5.1 Running times for small inputs
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
32
Figure 5.2 Running times for moderate inputs
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
33
Figure 5.3 Functions in order of increasing growth rate
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
34
Figure 5.6 The subsequences used in Theorem 5.2
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
35
Figure 5.7 The subsequences used in Theorem 5.3. The sequence from p to q has a sum that is, at most, that of the subsequence from i to q. On the left-hand side, the sequence from i to q is itself not the maximum (by Theorem 5.2). On the right-hand side, the sequence from i to q has already been seen. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
36
Figure 5.9 Meanings of the various growth functions
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
37
Figure 5.10 Observed running times (in seconds) for various maximum contiguous subsequence sum algorithms Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
38
Figure 5.13 Empirical running time for N binary searches in an N-item array Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
39
Data Structures & Problem Solving
Chapter 6 The Collections API Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss © Addison Wesley
40
Figure 6.19 A simple linked list
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
41
Figure 6.20 The stack model: Input to a stack is by push, output is by top, and deletion is by pop. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
42
Figure 6.22 The queue model: Input is by enqueue, output is by getFront, and deletion is by dequeue. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
43
Figure 6.34 The priority queue model: Only the minimum element is accessible. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
44
Figure 6.38 A summary of some data structures
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
45
Data Structures & Problem Solving
Chapter 7 Recursion Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss © Addison Wesley
46
Figure 7.5 A stack of activation records
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
47
Figure 7.7 A trace of the recursive calculation of the Fibonacci numbers Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
48
Figure 7.8 A tree viewed recursively
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
49
Figure 7.9 A tree Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
50
Figure 7.12 A recursively drawn ruler
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
51
Figure 7.14 (a) A fractal star outline drawn by the code shown in Figure 7.15 (b) The same star immediately before the last square is added Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
52
Figure 7.19 Dividing the maximum contiguous subsequence problem into halves Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
53
Figure 7.21 Trace of recursive calls for recursive maximum contiguous subsequence sum algorithm for N = 8 elements Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
54
Figure 7.22 Some of the subproblems solved recursively in Figure 7.23
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
55
Figure 7.24 An alternative recursive algorithm for the coin-changing problem Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
56
Figure 7.30 Grid for Exercise 7.31
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
57
Data Structures & Problem Solving
Chapter 8 Sorting Algorithms Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss © Addison Wesley
58
Figure 8.3 Basic action of insertion sort (the shaded part is sorted)
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
59
Figure 8.4 A closer look at the action of insertion sort (the dark shading indicates the sorted area; the light shading is where the new element was placed). Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
60
Figure 8.5 Shellsort after each pass if the increment sequence is {1, 3, 5} Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
61
Figure 8.6 Running time (milliseconds) of the insertion sort and Shellsort for various increment sequences Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
62
Figure 8.10 (A) The steps of quicksort (continued)
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
63
Figure 8.10 (B) The steps of quicksort
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
64
Figure 8.11 Partitioning algorithm: Pivot element 6 is placed at the end. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
65
Figure 8.12 Partitioning algorithm: i stops at large element 8; j stops at small element 2. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
66
Figure 8.13 Partitioning algorithm: The out-of-order elements 8 and 2 are swapped. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
67
Figure 8.14 Partitioning algorithm: i stops at large element 9; j stops at small element 5. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
68
Figure 8.15 Partitioning algorithm: The out-of-order elements 9 and 5 are swapped. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
69
Figure 8.16 Partitioning algorithm: i stops at large element 9; j stops at small element 3. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
70
Figure 8.17 Partitioning algorithm: Swap pivot and element in position i. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
71
Figure 8.18 Original array Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
72
Figure 8.19 Result of sorting three elements (first, middle, and last)
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
73
Figure 8.20 Result of swapping the pivot with the next-to-last element
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
74
Data Structures & Problem Solving
Chapter 9 Randomization Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss © Addison Wesley
75
Figure 9.3 Distribution of lottery winners if the expected number of winners is 2 Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
76
Data Structures & Problem Solving
Chapter 10 Fun and Games Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss © Addison Wesley
77
Figure 10.1 A sample word search grid
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
78
Figure 10.10 Alpha–beta pruning: After H2a is evaluated, C2, which is the minimum of the H2’s, is at best a draw. Consequently, it cannot be an improvement over C1. We therefore do not need to evaluate H2b, H2c, and H2d and can proceed directly to C3. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
79
Figure 10.12 Two searches that arrive at identical positions
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
80
Figure 10.17 Alpha–beta pruning example for Exercise 10.2.
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
81
Data Structures & Problem Solving
Chapter 11 Stacks and Compilers Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss © Addison Wesley
82
Figure 11.1 Stack operations in a balanced-symbol algorithm
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
83
Figure 11.11 Steps in the evaluation of a postfix expression
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
84
Figure 11.12 Examples of using associativity to break ties in precedence Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
85
Figure 11.13 Infix to postfix conversion
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
86
Figure 11.23 Expression tree for (a+b)*(a-b)
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
87
Data Structures & Problem Solving
Chapter 12 Utilities Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss © Addison Wesley
88
Figure 12.1 A standard coding scheme
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
89
Figure 12.2 Representation of the original code by a tree
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
90
Figure 12.3 A slightly better tree
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
91
Figure 12.4 An optimal prefix code tree
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
92
Figure 12.5 Optimal prefix code
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
93
Figure 12.6 Initial stage of Huffman’s algorithm
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
94
Figure 12.7 Huffman’s algorithm after the first merge
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
95
Figure 12.8 Huffman’s algorithm after the second merge
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
96
Figure 12.9 Huffman’s algorithm after the third merge
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
97
Figure 12.10 Huffman’s algorithm after the fourth merge
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
98
Figure 12.11 Huffman’s algorithm after the fifth merge
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
99
Figure 12.12 Huffman’s algorithm after the final merge
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
100
Data Structures & Problem Solving
Chapter 13 Simulation Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss © Addison Wesley
101
Figure 13.1 The Josephus problem: At each step, the darkest circle represents the initial holder and the lightly shaded circle represents the player who receives the hot potato (and is eliminated). Passes are made clockwise. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
102
Figure (A) The priority queue for modem bank simulation after each step (continued) Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
103
Figure (B) The priority queue for modem bank simulation after each step Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
104
Data Structures & Problem Solving
Chapter 14 Graphs and Paths Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss © Addison Wesley
105
Figure 14.1 A directed graph.
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
106
Figure 14.2 Adjacency list representation of the graph shown in Figure 14.1; the nodes in list i represent vertices adjacent to i and the cost of the connecting edge. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
107
Figure 14.4 An abstract scenario of the data structures used in a shortest-path calculation, with an input graph taken from a file. The shortest weighted path from A to C is A to B to E to D to C (cost is 76). Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
108
Figure 14.5 Data structures used in a shortest-path calculation, with an input graph taken from a file; the shortest weighted path from A to C is A to B to E to D to C (cost is 76). Legend: Dark-bordered boxes are Vertex objects. The unshaded portion in each box contains the name and adjacency list and does not change when shortest-path computation is performed. Each adjacency list entry contains an Edge that stores a reference to another Vertex object and the edge cost. Shaded portion is dist and prev, filled in after shortest path computation runs. Dark arrows emanate from vertexMap. Light arrows are adjacency list entries. Dashed arrows are the prev data member that results from a shortest-path computation. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
109
Figure 14.16 The graph, after the starting vertex has been marked as reachable in zero edges Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
110
Figure 14.17 The graph, after all the vertices whose path length from the starting vertex is 1 have been found Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
111
Figure 14.18 The graph, after all the vertices whose shortest path from the starting vertex is 2 have been found Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
112
Figure 14.19 The final shortest paths
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
113
Figure 14.20 If w is adjacent to v and there is a path to v, there also is a path to w Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
114
Figure 14.21A Searching the graph in the unweighted shortest-path computation. The darkest-shaded vertices have already been completely processed, the lightest-shaded vertices have not yet been used as v, and the medium-shaded vertex is the current vertex, v. The stages proceed left to right, top to bottom, as numbered (continued). Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
115
Figure 14.21B Searching the graph in the unweighted shortest-path computation. The darkest-shaded vertices have already been completely processed, the lightest-shaded vertices have not yet been used as v, and the medium-shaded vertex is the current vertex, v. The stages proceed left to right, top to bottom, as numbered. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
116
Figure 14.23 The eyeball is at v and w is adjacent, so Dw should be lowered to 6. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
117
Figure 14.24 If Dv is minimal among all unseen vertices and if all edge costs are nonnegative, Dv represents the shortest path. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
118
Figure 14.25A Stages of Dijkstra’s algorithm. The conventions are the same as those in Figure (continued). Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
119
Figure 14.25B Stages of Dijkstra’s algorithm. The conventions are the same as those in Figure Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
120
Figure 14.28 A graph with a negative-cost cycle
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
121
Figure 14.30A A topological sort. The conventions are the same as those in Figure (continued). Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
122
Figure 14.30B A topological sort. The conventions are the same as those in Figure Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
123
Figure 14.31A The stages of acyclic graph algorithm. The conventions are the same as those in Figure (continued). Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
124
Figure 14.31B The stages of acyclic graph algorithm. The conventions are the same as those in Figure Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
125
Figure 14.33 An activity-node graph
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
126
Figure 14.34 An event-node graph
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
127
Figure 14.35 Earliest completion times
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
128
Figure 14.36 Latest completion times
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
129
Figure 14.37 Earliest completion time, latest completion time, and slack (additional edge item) Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
130
Figure 14.38 Worst-case running times of various graph algorithms
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
131
Data Structures & Problem Solving
Chapter 15 Inner Classes and Implementation of ArrayList Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss © Addison Wesley
132
Figure 15.6 Iterator/container relationship
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
133
Figure 15.7 Iterator/container with inner classes
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
134
Data Structures & Problem Solving
Chapter 16 Stacks and Queues Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss © Addison Wesley
135
Figure 16.1 How the stack routines work: (a) empty stack: (b) push(a); (c) push(b); and (d) pop() Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
136
Figure 16.8 Basic array implementation of the queue
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
137
Figure 16.9 Array implementation of the queue with wraparound
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
138
Figure 16.18 Linked list implementation of the Stack class
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
139
Figure 16.22 Skeleton for the linked list–based queue class
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
140
Figure 16.26 The enqueue operation for the linked list–based implementation Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
141
Data Structures & Problem Solving
Chapter 17 Linked Lists Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss © Addison Wesley
142
Figure 17.1 Basic linked list
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
143
Figure 17.2 Insertion in a linked list: Create new node (tmp), copy in x , set tmp’s next link, and set current’s next link Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
144
Figure 17.3 Deletion from a linked list
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
145
Figure 17.4 Using a header node for the linked list
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
146
Figure 17.5 Empty list when a header node is used
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
147
Figure 17.15 A doubly linked list
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
148
Figure 17.16 An empty doubly linked list
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
149
Figure 17.17 Insertion in a doubly linked list by getting new node and then changing pointers in the order indicated Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
150
Figure 17.18 A circularly and doubly linked list
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
151
Figure 17.31 (A) Commands for editor in Exercise 17.19 (continued)
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
152
Figure 17.31 (B) Commands for editor in Exercise 17.19 (continued)
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
153
Data Structures & Problem Solving
Chapter 18 Trees Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss © Addison Wesley
154
Figure 18.1 A tree, with height and depth information
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
155
Figure 18.2 A tree viewed recursively
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
156
Figure 18.3 First child/next sibling representation of the tree in Figure 18.1 Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
157
Figure 18.4 A Unix directory
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
158
Figure 18.6 The directory listing for the tree shown in Figure 18.4
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
159
Figure 18.7 The Unix directory with file sizes
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
160
Figure 18.9 A trace of the size method
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
161
Figure 18.11 Uses of binary trees: (a) an expression tree and (b) a Huffman coding tree Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
162
Figure 18.14 Result of a naive merge operation: Subtrees are shared.
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
163
Figure 18.15 Aliasing problems in the merge operation; t1 is also the current object. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
164
Figure 18.18 Recursive view used to calculate the size of a tree: ST = SL + SR + 1. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
165
Figure 18.20 Recursive view of the node height calculation: HT = Max (HL + 1, HR + 1) Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
166
Figure 18.23 (a) Preorder, (b) postorder, and (c) inorder visitation routes Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
167
Figure 18.25 Stack states during postorder traversal
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
168
Figure 18.33 Tree for Exercises 18.1 and 18.2.
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
169
Data Structures & Problem Solving
Chapter 19 Binary Search Trees Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss © Addison Wesley
170
Figure 19.39 A color flip at 50 induces a violation; because the violation is outside, a single rotation fixes it. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
171
Figure 19.40 Result of single rotation that fixes the violation at node 50 Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
172
Figure 19.41 Insertion of 45 as a red node
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
173
Figure 19.50 X has two black children, and both of its sibling’s children are black; do a color flip. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
174
Figure 19.51 X has two black children, and the outer child of its sibling is red; do a single rotation. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
175
Figure 19.52 X has two black children, and the inner child of its sibling is red; do a double rotation. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
176
Figure 19.53 X is black, and at least one child is red; if we fall through to the next level and land on a red child, fine; if not, we rotate a sibling and parent. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
177
Figure 19.54 AA-tree resulting from the insertion of 10, 85, 15, 70, 20, 60, 30, 50, 65, 80, 90, 40, 5, 55, and 35 Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
178
Figure 19.55 The skew procedure is a simple rotation between X and P.
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
179
Figure 19.56 The split procedure is a simple rotation between X and R; note that R’s level increases. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
180
Figure 19.57 After insertion of 45 in the sample tree; consecutive hori-zontal links are introduced, starting at 35. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
181
Figure 19.58 After split at 35; a left horizontal link at 50 is introduced. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
182
Figure 19.59 After skew at 50; consecutive horizontal nodes are introduced starting at 40. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
183
Figure 19.60 After split at 40; 50 is now on the same level as 70, inducing an illegal left horizontal link. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
184
Figure 19.61 After skew at 70; consecutive horizontal links are introduced, starting at 30. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
185
Figure 19.62 After split at 30; the insertion is complete.
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
186
Figure 19.63 When 1 is deleted, all nodes become level 1, thereby introducing horizontal left links. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
187
Figure 19.82 A 5-ary tree of 31 nodes has only three levels
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
188
Figure 19.83 A B-tree of order 5
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
189
Figure 19.84 The B-tree after insertion of 57 in the tree shown in Figure Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
190
Figure 19.85 Insertion of 55 in the B-tree shown in Figure causes a split into two leaves. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
191
Figure 19.86 Insertion of 40 in the B-tree shown in Figure causes a split into two leaves and then a split of the parent node. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
192
Data Structures & Problem Solving
Chapter 20 Hash Tables Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss © Addison Wesley
193
Figure 20.4 Linear probing hash table after each insertion
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
194
Figure 20.5 Illustration of primary clustering in linear probing (b) versus no clustering (a) and the less significant secondary clustering in quadratic probing (c). Long lines represent occupied cells, and the load factor is 0.7. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
195
Figure 20.6 A quadratic probing hash table after each insertion (note that the table size was poorly chosen because it is not a prime number). Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
196
Data Structures & Problem Solving
Chapter 21 A Priority Queue: The Binary Heap Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss © Addison Wesley
197
Figure 21.1 A complete binary tree and its array representation
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
198
Figure 21.2 Heap-order property
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
199
Figure 21.3 Two complete trees: (a) a heap; (b) not a heap
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
200
Figure 21.7 Attempt to insert 14, creating the hole and bubbling the hole up Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
201
Figure 21.8 The remaining two steps required to insert 14 in the original heap shown in Figure 21.7 Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
202
Figure 21.10 Creation of the hole at the root
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
203
Figure 21.11 The next two steps in the deleteMin operation
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
204
Figure 21.12 The last two steps in the deleteMin operation
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
205
Figure 21.15 Recursive view of the heap
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
206
Figure 21.17 Implementation of the linear-time buildHeap method
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
207
Figure 21.18 (a) After percolateDown(6); (b) after percolateDown(5)
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
208
Figure 21.19 (a) After percolateDown(4); (b) after percolateDown(3)
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
209
Figure 21.20 (a) After percolateDown(2); (b) after percolateDown(1) and buildHeap terminates Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
210
Figure 21.21 Marking the left edges for height 1 nodes
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
211
Figure 21.22 Marking the first left edge and the subsequent right edge for height 2 nodes Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
212
Figure 21.23 Marking the first left edge and the subsequent two right edges for height 3 nodes Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
213
Figure 21.24 Marking the first left edge and the subsequent two right edges for the height 4 node Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
214
Figure 21.25 Max heap after the buildHeap phase
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
215
Figure 21.26 Heap after the first deleteMax operation
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
216
Figure 21.27 Heap after the second deleteMax operation
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
217
Figure 21.29 Initial tape configuration
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
218
Figure 21.30 Distribution of length 3 runs to two tapes
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
219
Figure 21.31 Tapes after the first round of merging (run length = 6)
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
220
Figure 21.32 Tapes after the second round of merging (run length = 12)
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
221
Figure 21.33 Tapes after the third round of merging
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
222
Figure 21.34 Initial distribution of length 3 runs to three tapes
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
223
Figure 21.35 After one round of three-way merging (run length = 9)
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
224
Figure 21.36 After two rounds of three-way merging
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
225
Figure 21.37 The number of runs for a polyphase merge
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
226
Figure 21.38 Example of run construction
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
227
Data Structures & Problem Solving
Chapter 22 Splay Trees Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss © Addison Wesley
228
Figure 22.1 Rotate-to-root strategy applied when node 3 is accessed
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
229
Figure 22.2 Insertion of 4 using the rotate-to-root strategy
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
230
Figure 22.3 Sequential access of items takes quadratic time
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
231
Figure 22.4 The zig case (normal single rotation)
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
232
Figure 22.5 The zig-zag case (same as a double rotation); the symmetric case has been omitted Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
233
Figure 22.6 Zig-zig case (unique to the splay tree); the symmetric case has been omitted Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
234
Figure 22.7 Result of splaying at node 1 (three zig-zigs)
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
235
Figure 22.8 The remove operation applied to node 6: First, 6 is splayed to the root, leaving two subtrees; a findMax is performed on the left subtree, raising 5 to the root of the left subtree; then the right subtree can be attached (not shown). Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
236
Figure 22.9A Top-down splay rotations: (a) zig (continued)
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
237
Figure 22.9B Top-down splay rotations: (b) zig-zig (continued)
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
238
Figure 22.9C Top-down splay rotations: (c) zig-zag
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
239
Figure 22.10 Simplified top–down zig-zag
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
240
Figure 22.11 Final arrangement for top–down splaying
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
241
Figure (A) Steps in a top–down splay (accessing 19 in the top tree) (continued) Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
242
Figure (B) Steps in a top–down splay (accessing 19 in the top tree) (continued) Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
243
Data Structures & Problem Solving
Chapter 23 Merging Priority Queues Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss © Addison Wesley
244
Figure 23.1 Simplistic merging of heap-ordered trees: Right paths are merged. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
245
Figure 23.2 Merging of skew heap; right paths are merged, and the result is made a left path. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
246
Figure 23.3 Change in the heavy or light status of nodes after a merge
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
247
Figure 23.4 Abstract representation of a sample pairing heap
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
248
Figure 23.5 Actual representation of the pairing heap shown in Figure 23.4; the dark line represents a pair of links that connect nodes in both directions Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
249
Figure 23.6 (A) Recombination of siblings after a deleteMin. In each merge, the larger root tree is made the left child of the smaller root tree: (a) the resulting trees (continued) Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
250
Figure 23.6 (B) Recombination of siblings after a deleteMin. In each merge, the larger root tree is made the left child of the smaller root tree: (b) after the first pass (continued) Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
251
Figure 23.6 (C) Recombination of siblings after a deleteMin. In each merge, the larger root tree is made the left child of the smaller root tree: (c) after the first merge of the second pass (continued) Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
252
Figure 23.6 (D) Recombination of siblings after a deleteMin. In each merge, the larger root tree is made the left child of the smaller root tree: (d) after the second merge of the second pass Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
253
Figure 23.13 The compareAndLink method merges two trees
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
254
Data Structures & Problem Solving
Chapter 24 The Disjoint Set Class Data Structures & Problem Solving Using JAVA Second Edition Mark Allen Weiss © Addison Wesley
255
Figure 24.1 A 50 x 88 maze Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
256
Figure 24.2 Initial state: All walls are up, and all cells are in their own sets. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
257
Figure 24.3 At some point in the algorithm, several walls have been knocked down and sets have been merged. At this point, if we randomly select the wall between 8 and 13, this wall is not knocked down because 8 and 13 are already connected. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
258
Figure 24.4 We randomly select the wall between squares 18 and 13 in Figure 24.3; this wall has been knocked down because 18 and 13 were not already connected, and their sets have been merged. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
259
Figure 24.5 Eventually, 24 walls have been knocked down, and all the elements are in the same set. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
260
Figure 24.6 (a) A graph G and (b) its minimum spanning tree
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
261
Figure 24.7 (A) Kruskal’s algorithm after each edge has been considered. The stages proceed left-to-right, top-to-bottom, as numbered. (continued) Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
262
Figure 24.7 (B) Kruskal’s algorithm after each edge has been considered. The stages proceed left-to-right, top-to-bottom, as numbered. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
263
Figure 24.8 The nearest common ancestor for each request in the pair sequence (x, y), (u, z), (w, x), (z, w), and (w, y) is A, C, A, B, and y, respectively. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
264
Figure 24.9 The sets immediately prior to the return from the recursive call to D; D is marked as visited and NCA(D, v) is v’s anchor to the current path. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
265
Figure 24.10 After the recursive call from D returns, we merge the set anchored by D into the set anchored by C and then compute all NCA(C, v) for nodes v marked prior to completing C’s recursive call. Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
266
Figure 24.12 A forest and its eight elements, initially in different sets Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
267
Figure 24.13 The forest after the union of trees with roots 4 and 5
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
268
Figure 24.14 The forest after the union of trees with roots 6 and 7
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
269
Figure 24.15 The forest after the union of trees with roots 4 and 6
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
270
Figure 24.16 The forest formed by union-by-size, with the sizes encoded as negative numbers Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
271
Figure 24.17 Worst-case tree for N = 16
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
272
Figure 24.18 A forest formed by union-by-height, with the height encoded as a negative number Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
273
Figure 24.19 Path compression resulting from a find (14) on the tree shown in Figure 24.17 Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
274
Figure 24.22 Possible partitioning of ranks into groups
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
275
Figure 24.23 Actual partitioning of ranks into groups used in the proof Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
276
Figure 24.24 A graph G for Exercise 24.3
Data Structures & Problem Solving using JAVA/2E Mark Allen Weiss © Addison Wesley
277
Complexity and Big-O Notation
Example N! = # ways to put N objects in linear order. Generating all such orderings (permutations) on N objects takes at least N! time. Example Adding two n-bit integers at most 2n bit operations.
278
Time estimate for two methods
279
Time complexity
280
Order of a function
281
Definitions
282
Example
283
Example
284
Theorem
285
Proof
286
Example
287
Big-O is transitive
288
Corollary
289
Some common functions Decreasing order
290
Example
292
Example
293
Example
294
Example
295
Select a theta notation
296
Fibonacci sequence as the worst case for gcd
297
Comparing a gcd computation with Fibonacci seq.
62= 23=16+7 16=2.7+2 7=3.2+1 2=2.1+0 13=8+5 8=5+3 5=3+2 3=2+1 2=2.1+0
298
Theorem
300
Corollary
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.