Class Review
Figure 6.1: The software life cycle
Figure 6.2: The development phase of the software life cycle
Figure 6.3: A structure chart for a simple Internet “mail order” business Oversee 检查
Figure 6.4: A class diagram for a simple Internet “mail order” business
Figure 6.6: A collaboration diagram of a simple Internet “mail order” business
6.5 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)
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.
Figure 6. 10: A dataflow diagram of a simple Figure 6.10: A dataflow diagram of a simple Internet “mail order” business
Figure 6.11: An entity-relationship diagram Rectangle: entity Diamond: relationship Arrows: types of relationships that may occur among entities
答疑:每周五下午3:00-4:00
Ch. 7 Data Structures Arrays. Lists. Stacks. Queues. Trees. Customized data types. Object-oriented programming.
Storage Containers ( General ) Containers such as vectors, lists are storage structures that provide ways to access data and insert/delete items.
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.
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.
Figure 7.1: Novels arranged by title but linked according to authorship (detailed example)
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.
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
A search tree holding airbill numbers The tree holds 8 elements. Any search requires at most 3 movements along a path from the root.
7.2 Arrays One dimensional arrays. Multidimensional arrays. Row major order Column major order Address polynomial
Figure 7. 2: The array of Readings stored in Figure 7.2: The array of Readings stored in memory starting at address x
Figure 7.3: A two-dimensional array with four rows and five columns stored in row major order
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
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).
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
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.
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.
Question What if in column major order?
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])
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 )
Figure 11-4 Processing an array
Homework Page306 1-4 Turn in next Friday! SayGoodbyeToPirate
Class Review
Storage Containers ( General ) Containers such as vectors, lists are storage structures that provide ways to access data and insert/delete items.
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.
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.
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
Q & A I still don’t know the row major order address polynomial.
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.
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
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.
Figure 7.4: Names stored in memory as a contiguous list animation example
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 .
Figure 7.5: The structure of a linked list Create example
List Operation Printing a linked List Inserting an entry into a linked List Deleting an entry from a linked List Algorithm and Program
Figure 7.6: Deleting an entry from a linked list Animation example
Figure 7.7: Inserting an entry into a linked list Animation example
Figure 7.8: A procedure for printing a linked list
7.4 Stacks Last-in first-out. Push and pop. Using stacks for maintaining procedure calls. Other applications
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
Push operation in a stack Figure 7(a) Push operation in a stack Push
Pop operation in a stack Figure 7 (b) Pop operation in a stack Pop animation example
Backtracking (回溯) Backtracking means finding our way out of a system by reversing the actions taken to get in.
Figure 7.9: Nested procedures terminating in the opposite order to that in which they were requested Real example
Figure 4.15: TargetValue: Bill
Figure 4.16: TargetValue: David
Figure 4.17: (continued) TargetValue: David
Figure 4.17 TargetValue: David
Figure 7.10: Using a stack to print a linked list in reverse order Alfred Bob Carol
Figure 7.10: Using a stack to print a linked list in reverse order (continued)
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
The address of the top entry is stored in an additional memory cell known as the stack pointer.
Figure 7.12: A stack in memory
7.5 Queues First-in first-out. Head and tail. Circular queue. Applications
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 )
Figure 7(c) Queue representation
Figure 7(d) Enqueue operation grape
Figure 7(e) Dequeue operation plum animation example
Figure 7.13: A queue implemented with head and tail pointers
Figure 7.14: A queue “crawling” through memory
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.
Figure 7.15: A circular queue (a) containing the letters F through O as actually stored in memory
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
Homework Page 310 3,4 Page 314 3,4 Page 317 1-3 Turn in next Friday.
Class Review
Figure 7.4: Names stored in memory as a contiguous list animation example
Figure 7.5: The structure of a linked list Create example
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.
Linked List Nodes Removal is like Insertion in reverse. 80 Main Index Contents Linked List Nodes Removal is like Insertion in reverse.
Doubly linked lists
7.4 Stacks Last-in first-out. Push and pop. Using stacks for maintaining procedure calls. Other applications
Push operation in a stack Figure 7(a) Push operation in a stack Push
Pop operation in a stack Figure 7 (b) Pop operation in a stack Pop animation example
Figure 7.9: Nested procedures terminating in the opposite order to that in which they were requested Real example
Figure 7.12: A stack in memory
Figure 7(c) Queue representation
Figure 7.14: A queue “crawling” through memory
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
Class Review
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
Figure 7.16: An example of an organization chart
Another example: regedit Computer System Another example: regedit
Representation of a tree Figure 7(f) Representation of a tree
Figure 7.17: Tree terminology
Depth: the number of horizontal layers within in. Figure 7(g) Tree terminology Depth: the number of horizontal layers within in.
Tree Node Level and Path Length 97 Main Index Contents Tree Node Level and Path Length Depth 4
Figure 7(h) Subtrees
Tree implementation Binary Tree : A kind of trees in which each node has at most two children. Linked structure Contiguous Block
Figure 7(I) Binary tree
Examples of binary trees Figure 7(j) Examples of binary trees
Figure 7.18: The structure of a node in a binary tree
Figure 7.19: The conceptual and actual organization of a binary tree using a linked storage system
104104 Main Index Contents
Figure 7.20: A tree stored without pointers
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
Binary Tree Package Package: A collection of program To develop a storage system along with a collection of procedures to perform needed operations.
Depth-first traversal of a binary tree Figure 7(k) Depth-first traversal of a binary tree
Preorder traversal of a binary tree Figure 7(l) Preorder traversal of a binary tree
Inorder traversal of a binary tree Figure 7(m) Inorder traversal of a binary tree
Postorder traversal of a binary tree Figure 7(n) Postorder traversal of a binary tree
Breadth-first traversal of a binary tree Figure 7(o) Breadth-first traversal of a binary tree
Figure 7.22: The letters A through M arranged in an ordered tree
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
Figure 7. 24: The successively smaller trees Figure 7.24: The successively smaller trees considered by the procedure in Figure 7.23 when searching for the letter J
Figure 7.25: Printing a search tree in alphabetical order
Figure 7.26: A procedure for printing the data in a binary tree
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)
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
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
Figure 7(p) Expression tree
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.
EmployeeType DistManager, SalesRep1, SalesRep2 User-defined types typedef struct {char Name[8]; int Age; float SkillRating; } EmployeeType EmployeeType DistManager, SalesRep1, SalesRep2
Abstract data type Abstract data types - encompasses both the storage system and the associated operations. P329
Figure 7.29: A stack of integers implemented in C++
Figure 7.30: A stack of integers implemented in Java and C#
7.8 Pointers in Machine Language Immediate addressing Direct addressing Indirect addressing
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.
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
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.
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
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.
Summary Immediate addressing : op-codes 2 Direct addressing: op-codes 1 Indirect addressing: op-codes D and E
Homework Page334 1-4 Hand in next Wednesday?
Discussion 3
See you next time !