Presentation is loading. Please wait.

Presentation is loading. Please wait.

Class Review.

Similar presentations


Presentation on theme: "Class Review."— Presentation transcript:

1 Class Review

2 Figure 6.1: The software life cycle

3 Figure 6.2: The development phase of the software life cycle

4 Figure 6.3: A structure chart for a simple Internet “mail order” business
Oversee 检查

5 Figure 6.4: A class diagram for a simple Internet “mail order” business

6 Figure 6.6: A collaboration diagram of a simple Internet “mail order” business

7 Tools of the Trade Dataflow diagrams (数据流图)- a pictorial representation of data paths. (often used in modularity design) Entity-relationship diagrams (实体联系图)- a pictorial representation of the items of information (entities) within the system and the relationships between these pieces of information. (often used in object-oriented system)

8 The benefits of dataflow diagram
Data dictionaries - a central depository of information about the data items appearing throughout the system. Enhancing communication between the potential user of the system. Establishing uniformity throughout the system.

9 Figure 6. 10: A dataflow diagram of a simple
Figure 6.10: A dataflow diagram of a simple Internet “mail order” business

10 Figure 6.11: An entity-relationship diagram
Rectangle: entity Diamond: relationship Arrows: types of relationships that may occur among entities

11 答疑:每周五下午3:00-4:00

12 Ch. 7 Data Structures Arrays. Lists. Stacks. Queues. Trees.
Customized data types. Object-oriented programming.

13 Storage Containers ( General )
Containers such as vectors, lists are storage structures that provide ways to access data and insert/delete items.

14 7.1 Data Structure Basics Abstraction Again
The topic of data structures explores ways in which users can be shielded from the details of actual data storage, and be allowed to access information as though it were stored in more convenient form.

15 Static Versus Dynamic Structures
Whether the shape or size of data structure changes over time Pointers A pointer variable is a memory cell ( or blocks of memory cells). In case of data structure, pointers are used to record the location where the data are stored.

16 Figure 7.1: Novels arranged by title but linked according to authorship
(detailed example)

17 Storage Containers ( Lists )
list container each element has a reference that identifies the next item in the list. Adding a new item involves breaking a link in the chain and creating two new links to connect the item.

18 Storage Containers ( Maps )
maps use a tree structure to store data. A is a container that stores elements as nodes emanating from a root. TREE T W N D F B Root G H

19 A search tree holding airbill numbers
The tree holds 8 elements. Any search requires at most 3 movements along a path from the root.

20 7.2 Arrays One dimensional arrays. Multidimensional arrays.
Row major order Column major order Address polynomial

21 Figure 7. 2: The array of Readings stored in
Figure 7.2: The array of Readings stored in memory starting at address x

22 Figure 7.3: A two-dimensional array with four rows and five columns stored in row major order

23 In C language, the entries are arranged by row major order
Figure 11-8 Memory layout In C language, the entries are arranged by row major order

24 Row ( Column) major order
The array is static in the sense that its size does not vary as updates are made. We can therefore calculate the amount of storage area needed for the entire array and reserve blocks of contiguous memory cells of that size, then store the array row(Column) by row( Column).

25 Eg. In most 32 bit computers each integer occupies 4 memory cells
Row major order x: the address of the cell containing the entry in the first row and first column c: the number of columns The address of the entry in the ith row and jth column will be: m: the number of memory cells occupied by each entry x+[(c×(i-1))+(j-1)] ×m (start from [1,1]) Eg. In most 32 bit computers each integer occupies 4 memory cells

26 Address polynomial (地址多项式)
The preceding calculation can be generalized to obtain a process that can be used by translators to convert references in terms of row and column positions into actual memory addresses.

27 x+(c( i-1)) +( j-1 ) (start from [1,1])
If we let c represent the number of columns in an array( which is the numbers of entries in each row) then the address of the entry in the ith row and the jth column will be x+(c( i-1)) +( j-1 ) (start from [1,1]) assumes that each entry occupies only one memory cell Where the x is the address of the cell containing the entry in the first row and the first column. That formula is called address polynomial.

28 Question What if in column major order?

29 Column major order x: the address of the cell containing the entry in the first row and first column r: the number of rows m: the number of memory cell each entry occupies The address of the entry in the ith row and jth column will be: x+[(r×(j-1))+(i-1)] ×m (start from [1,1])

30 Practice example int bookid[6,5]
The translator will reserve 30 successive memory cells (suppose each integer occupies only one memory cell) bookid[2,3]  6 Put data 6 in 2th row, 3th column of array bookid, which is x+(5( 2-1)) +( 3-1 )

31 Figure 11-4 Processing an array

32 Homework Page Turn in next Friday! SayGoodbyeToPirate

33 Class Review

34 Storage Containers ( General )
Containers such as vectors, lists are storage structures that provide ways to access data and insert/delete items.

35 Pointers A pointer variable is a memory cell ( or blocks of memory cells). In case of data structure, pointers are used to record the location where the data are stored.

36 7.1 Data Structure Basics Abstraction Again
The topic of data structures explores ways in which users can be shielded from the details of actual data storage, and be allowed to access information as though it were stored in more convenient form.

37 In C language, the entries are arranged by row major order
Figure 11-8 Memory layout In C language, the entries are arranged by row major order

38 Q & A I still don’t know the row major order address polynomial.

39 x+(c( i-1)) +( j-1 ) (start from [1,1])
If we let c represent the number of columns in an array( which is the numbers of entries in each row) then the address of the entry in the ith row and the jth column will be x+(c( i-1)) +( j-1 ) (start from [1,1]) assumes that each entry occupies only one memory cell Where the x is the address of the cell containing the entry in the first row and the first column. That formula is called address polynomial.

40 Eg. In most 32 bit computers each integer occupies 4 memory cells
Row major order x: the address of the cell containing the entry in the first row and first column c: the number of columns The address of the entry in the ith row and jth column will be: m: the number of memory cells occupied by each entry x+[(c×(i-1))+(j-1)] ×m (start from [1,1]) Eg. In most 32 bit computers each integer occupies 4 memory cells

41 7.3 Lists lists A list is a collection of entries that appear in a sequential order. Contiguous lists - static structure Entire list is stored in one large block of memory,with successive entries following each other in contiguous memory cells.

42 Figure 7.4: Names stored in memory as a contiguous list
animation example

43 Linked List (链表) Using pointer to find the next unit, stored unit can be scattered in whole stored area. Usually, A linked list has a head pointer to point its beginning position and has a Nil pointer to point its end .

44 Figure 7.5: The structure of a linked list
Create example

45 List Operation Printing a linked List Inserting an entry into a linked List Deleting an entry from a linked List Algorithm and Program

46 Figure 7.6: Deleting an entry from a linked list
Animation example

47 Figure 7.7: Inserting an entry into a linked list
Animation example

48 Figure 7.8: A procedure for printing a linked list

49 7.4 Stacks Last-in first-out. Push and pop.
Using stacks for maintaining procedure calls. Other applications

50 Stack is a list, in which all insertions and deletions are performed at the same end of the structure.The last entry entered will be the first entry removed. ---Last-in first-out structure( LIFO) Push : inserting an object on a stack Pop: Deleting an object from a stack

51 Push operation in a stack
Figure 7(a) Push operation in a stack Push

52 Pop operation in a stack
Figure 7 (b) Pop operation in a stack Pop animation example

53 Backtracking (回溯) Backtracking means finding our way out of a system by reversing the actions taken to get in.

54 Figure 7.9: Nested procedures terminating in the opposite order to that in which they were requested
Real example

55 Figure 4.15: TargetValue: Bill

56 Figure 4.16: TargetValue: David

57 Figure 4.17: (continued) TargetValue: David

58 Figure 4.17 TargetValue: David

59 Figure 7.10: Using a stack to print a linked list in reverse order
Alfred Bob Carol

60 Figure 7.10: Using a stack to print a linked list in reverse order
(continued)

61 Figure 7. 11: A procedure (using an auxiliary
Figure 7.11: A procedure (using an auxiliary stack) for printing a linked list in reverse order

62 The address of the top entry is stored in an additional memory cell known as the stack pointer.

63 Figure 7.12: A stack in memory

64 7.5 Queues First-in first-out. Head and tail. Circular queue.
Applications

65 A queue is a list in which all insertions are made at one end and all deletions are performed at the other. Queue has head pointer and tail pointer ( or, rear )

66 Figure 7(c) Queue representation

67 Figure 7(d) Enqueue operation grape

68 Figure 7(e) Dequeue operation plum animation example

69 Figure 7.13: A queue implemented with head and tail pointers

70 Figure 7.14: A queue “crawling” through memory

71 A problem remains with the storage system as described thus far
A problem remains with the storage system as described thus far. If left unchecked,the queue crawls slowly through memory like a glacier, destroying any other data in its path.

72 Figure 7.15: A circular queue (a) containing the letters F through O as actually stored in memory

73 Figure 7.15: A circular queue (b) in its conceptual form in which the last cell in the block is “adjacent” to the first cell animation example

74 Homework Page 310 3,4 Page ,4 Page Turn in next Friday.

75 Class Review

76 Figure 7.4: Names stored in memory as a contiguous list
animation example

77 Figure 7.5: The structure of a linked list
Create example

78 Linked List Nodes Each Node is like a piece of a chain
79 Main Index Contents Linked List Nodes Each Node is like a piece of a chain To insert a new link, break the chain at the desired location and simply reconnect at both ends of the new piece.

79 Linked List Nodes Removal is like Insertion in reverse. 80 Main Index
Contents Linked List Nodes Removal is like Insertion in reverse.

80 Doubly linked lists

81 7.4 Stacks Last-in first-out. Push and pop.
Using stacks for maintaining procedure calls. Other applications

82 Push operation in a stack
Figure 7(a) Push operation in a stack Push

83 Pop operation in a stack
Figure 7 (b) Pop operation in a stack Pop animation example

84 Figure 7.9: Nested procedures terminating in the opposite order to that in which they were requested
Real example

85 Figure 7.12: A stack in memory

86 Figure 7(c) Queue representation

87 Figure 7.14: A queue “crawling” through memory

88 Figure 7.15: A circular queue (b) in its conceptual form in which the last cell in the block is “adjacent” to the first cell animation example

89 Class Review

90 7.6 Trees Trees - an organization chart; e.g., family tree and company’s organization . Root node, leaf nodes, arc, subtrees. Parent, children, siblings. Depth of a tree. Tree implementation. Binary tree. Applications

91 Figure 7.16: An example of an organization chart

92 Another example: regedit
Computer System Another example: regedit

93 Representation of a tree
Figure 7(f) Representation of a tree

94 Figure 7.17: Tree terminology

95 Depth: the number of horizontal layers within in.
Figure 7(g) Tree terminology Depth: the number of horizontal layers within in.

96 Tree Node Level and Path Length
97 Main Index Contents Tree Node Level and Path Length Depth 4

97 Figure 7(h) Subtrees

98 Tree implementation Binary Tree : A kind of trees in which each node has at most two children. Linked structure Contiguous Block

99 Figure 7(I) Binary tree

100 Examples of binary trees
Figure 7(j) Examples of binary trees

101 Figure 7.18: The structure of a node in a binary tree

102 Figure 7.19: The conceptual and actual organization of a binary tree using a linked storage system

103 104104 Main Index Contents

104 Figure 7.20: A tree stored without pointers

105 Figure 7. 21: A sparse, unbalanced tree shown in
Figure 7.21: A sparse, unbalanced tree shown in its conceptual form and as it would be stored without pointers Another example

106 Binary Tree Package Package: A collection of program To develop a storage system along with a collection of procedures to perform needed operations.

107 Depth-first traversal of a binary tree
Figure 7(k) Depth-first traversal of a binary tree

108 Preorder traversal of a binary tree
Figure 7(l) Preorder traversal of a binary tree

109 Inorder traversal of a binary tree
Figure 7(m) Inorder traversal of a binary tree

110 Postorder traversal of a binary tree
Figure 7(n) Postorder traversal of a binary tree

111 Breadth-first traversal of a binary tree
Figure 7(o) Breadth-first traversal of a binary tree

112 Figure 7.22: The letters A through M arranged in an ordered tree

113 Figure 7. 23: The binary search as it would appear
Figure 7.23: The binary search as it would appear if the list were implemented as a linked binary tree

114 Figure 7. 24: The successively smaller trees
Figure 7.24: The successively smaller trees considered by the procedure in Figure when searching for the letter J

115 Figure 7.25: Printing a search tree in alphabetical order

116 Figure 7.26: A procedure for printing the data in a binary tree

117 Figure 7. 27: Inserting the entry M into the list
Figure 7.27: Inserting the entry M into the list B, E, G, H, J, K, N, P stored as a tree (continued)

118 Figure 7. 27: Inserting the entry M into the list
Figure 7.27: Inserting the entry M into the list B, E, G, H, J, K, N, P stored as a tree

119 Figure 7. 28: A procedure for inserting a new entry
Figure 7.28: A procedure for inserting a new entry in a list stored as a binary tree

120 Figure 7(p) Expression tree

121 7.7 Customized Data Types(定制数据类型)
User-defined types - allow programmers to define additional data types using the primitive types and structures as building blocks. Abstract data types - encompasses both the storage system and the associated operations.

122 EmployeeType DistManager, SalesRep1, SalesRep2
User-defined types typedef struct {char Name[8]; int Age; float SkillRating; } EmployeeType EmployeeType DistManager, SalesRep1, SalesRep2

123 Abstract data type Abstract data types - encompasses both the storage system and the associated operations. P329

124 Figure 7.29: A stack of integers implemented in C++

125 Figure 7.30: A stack of integers implemented in Java and C#

126 7.8 Pointers in Machine Language
Immediate addressing Direct addressing Indirect addressing

127 Question How to write a program in the machine language described in Appendix C to pop an entry off a stack and place that entry in a general-purpose register? Add another op-code D. DRXY is an instruction that means to load register R with the contents of the memory cell whose address is found at address XY.

128 Figure 7. 31: Our first attempt at expanding the
Figure 7.31: Our first attempt at expanding the machine language in Appendix C to take advantage of pointers

129 Redesign op-code D. Based on the above instruction, we still have to subtract one from the stack pointer. Redesign op-code D as DR0S, which means to load register R with the contents of the memory cell pointed to by register S.

130 Figure 7. 32: Loading a register from a memory
Figure 7.32: Loading a register from a memory cell that is located by means of a pointer stored in a register

131 Further expand Appendix C
Add an op-code E ER0S means to store the contents of register R in the memory cell pointed to by register S.

132 Summary Immediate addressing : op-codes 2
Direct addressing: op-codes 1 Indirect addressing: op-codes D and E

133 Homework Page Hand in next Wednesday?

134 Discussion 3

135 See you next time !


Download ppt "Class Review."

Similar presentations


Ads by Google