3 data. software and data data data element – a single, meaningful unit of data. name social...

Post on 13-Dec-2015

220 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

33

Data

Software And DataSoftware And DataDataData

Data element– a single, meaningful unit of data.

Name Social Security Number

Data structure– a set of related data elements.– list, queue, linked list, array, stack, file

Fig. 3.18: Fig. 3.18: The most basic data structure The most basic data structure is a list. Each entry is called a node, and is a list. Each entry is called a node, and each node contains a single data each node contains a single data

elementelement..

C I M Q W

Fig. 3.19: Fig. 3.19: In a linked list, each node In a linked list, each node contains data plus a pointer to the next contains data plus a pointer to the next node. The data items need not be stored node. The data items need not be stored in adjacent memory locations because in adjacent memory locations because the pointers define the list’s logical order.the pointers define the list’s logical order.

C I M Q W

Fig. 3.20: To insert a node into a linkFig. 3.20: To insert a node into a linked ed list, locate the prior node, change its list, locate the prior node, change its pointer to the new node, and set the new pointer to the new node, and set the new node’s pointer to the next node. node’s pointer to the next node.

C I M Q W

P

Fig. 3.21: To delete a node from a Fig. 3.21: To delete a node from a linked linked list, change the appropriate pointer to list, change the appropriate pointer to “jump over” the deleted node.“jump over” the deleted node.

C I M Q W

Fig. 3.22a: Fig. 3.22a: A stack is a linked list in which A stack is a linked list in which all insertions and deletions occur at the all insertions and deletions occur at the top. Access to the stack is controlled by a top. Access to the stack is controlled by a single pointer. single pointer.

C I M Q W

S tack p o in te r

Fig. 3.22b: Fig. 3.22b: Because insertions and Because insertions and deletions occur only at the top, the last deletions occur only at the top, the last item added to the stack is the first item item added to the stack is the first item removed from the stack. removed from the stack.

C I M Q W

S tack p o in te r

Fig. 3.23a: Fig. 3.23a: A queue is a linked list in A queue is a linked list in which insertions occur at the rear and which insertions occur at the rear and deletions occur at the front. deletions occur at the front.

C I M Q W

F ro n t p o in te r R ea r p o in te r

Fig. 3.23b: Fig. 3.23b: Access to a queue is Access to a queue is controlled by two pointers, and the first controlled by two pointers, and the first item added to a queue is the first item item added to a queue is the first item removed. removed.

C I M Q W

F ro n t p o in te r R ea r p o in te r

Software And DataSoftware And DataDataData

Data File– The most familiar type of data structure– A set of data elements (fields)– A group of related fields (records)– A group of related records (file)

Fig. 3.24: FFig. 3.24: Fields are grouped to form ields are grouped to form records. A file is a set of related records.records. A file is a set of related records.

N a m e S treet a d d ress C ity S ta te Z ipco d e

M elin d a A tk in s 1 4 2 M ap le S t. O x fo rd O H 4 5 0 4 2C h arle s B ak e r 7 1 3 M ain S t. C in c in n a ti O H 4 5 7 0 3T h o m as B a te s 4 2 S o u th B lv d . A tlan ta G A 3 5 2 1 7L isa C am p an e lla 8 T o w er S q u a re S an Jo se C A 9 5 3 2 1S h en C h an S ta te R o u te 7 7 B in g h am to n N Y 1 2 7 5 6T h o m as G arc ia 4 7 3 D ix ie H ig h w ay L ex in g to n K Y 4 3 4 1 0

.

.

.A rth u r W h ite N o rth s id e M a ll O rlan d o F L 2 1 4 5 0

F ile

F ie ld s

R eco rd s

Software And DataSoftware And DataDataData

Data File (mainframe Processing)– The data is processed record by record– Programs are written to read a record, process its

fields, generate the appropriate output, and then read and process another record.

– Because only one record is in memory at a time, relatively little memory is needed.

Fig. 3.25: Fig. 3.25: A relative record number A relative record number indicates a record’s position relative to indicates a record’s position relative to the first record in the file.the first record in the file.

R ela tiv ereco rd 0

R e la tiv ereco rd 1

R e la tiv ereco rd 2

R e la tin ereco rd 3

R e la tiv ereco rd 4

R e la tiv e sec to r 0 1 2 3 4

Fig. 3.26: Fig. 3.26: Given the start of file address Given the start of file address and a relative record number, a physical and a relative record number, a physical disk address can be computed.disk address can be computed.

R ela tiv e A ctu a l d isk a d d ressreco rdn u m b er T ra ck S ec to r

0 3 0 1 1 3 0 2 2 3 0 3 3 3 0 4 4 3 0 5 5 3 0 6 6 3 0 7 7 3 0 8

... a n d so o n

Software and DataSoftware and DataAccess TechniquesAccess Techniques

Sequential access– accessing data in physical order.– Processing begins with relative record 0, then

moves to relative record 1, 2, and so on.Direct (random) access

– accessing data without regard for physical order.– Index– hashing

Fig. 3.27: Fig. 3.27: An index can be used to An index can be used to convert a logical key to a relative record convert a logical key to a relative record number.number.

K ey R ela tiv ereco rd

M elin d a A tk in s 0C h arle s B ak e r 1T h o m as B a te s 2L isa C am p an e lla 3S h en C h an 4T h o m as G arc ia 5

.

.

.

Software and DataSoftware and DataDatabase ManagementDatabase Management

Traditional files– data redundancy– data dependency

Database– centralized– single copy of each data element– programmer can ignore physical data structure

Fig. 3.28: Fig. 3.28: Many of the problems Many of the problems associated with traditional data access associated with traditional data access techniques can be solved by using a techniques can be solved by using a database.database.

A p p lica tio np ro g ra m A

A p p lica tio np ro g ra m B

A p p lica tio np ro g ra m C

D a ta b a sem a n a g em en t

sy stemD a ta b a se

top related