Download presentation
Presentation is loading. Please wait.
Published byClinton Grafton Modified over 10 years ago
1
Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence the selection of a computational strategy for a given data processing job. DATA STRUCTURES
2
DATA STRUCTERS 1- A List is a collection of sets of data elements. LIST and FILE have the same meaning. 2- Nodes : The sets of data contained in a list are referred to as Node. Each node will contain several related data items. A node is equivalent to a record.
3
DATA STRUCTERS The items within a node are required to be stored in storage locations, though the nodes themselves need not be adjacent to one another. 3- Field: Each of the items within a given node is said to occupy a field. A field can contain either a data item or a link [or pointer].
4
DEFINITION 4- The Link [ Pointer]: Contain the starting addresses of other nodes, thus creating a structural interrelationship among the nodes. 4
5
5 Novels arranged by title but linked according to authorship
6
DEFINITION The link tell us that the next node in the list has starting address of xxxx. A node need not be restricted to one link, multilinked nodes are common. Each of the nodes in a given list should contain the same number of links. 6
7
DEFINITION Linear Lists: A linear list is a list which the nodes are ordered in one dimensional arrangement. [ N1, N2, ---, Nr] Sequential linear list When Nodes are stored consecutive adjacent to one another. We refer to the list as sequential linear list.[M/C language, Computer programs, Magnetic tape data files are usually stored in the form of sequential linear list]. 7
8
LINKED LINEAR LIST Most searching, sorting, and merging operations can be carried out quite easily with sequential linear lists. The simple type of the linked list is the single linked linear list. Each node will contain one pointer, which indicates the starting address of the next node in the list. 8
9
9 The array of Readings stored in memory starting at address
10
10 A two-dimensional array with four rows and five columns stored in row major order
11
11 Names stored in memory as a contiguous list
12
12 A two-dimensional array with four rows and five columns stored in row major order
13
13 Names stored in memory as a contiguous list
14
14 The structure of a linked list
15
15 Deleting an entry from a linked list
16
16 Inserting an entry into a linked list
17
17 A procedure for printing a linked list
18
MULTIPLE LINKS If each node in the list contains several items, each of which should be ordered in some particular manner, then a different set of links is established for each item. Each set of links establishes a separate single linked linear list. 18
19
STACKS A stack is a list in which all insertions and deletions are performed at the same end of the structure. Stack known as last-in, first-out [LIFO] structures. 19
20
BACKTRACKING A classic application of a stack occurs when a program unit requests the execution of a procedure. If the procedure itself request the execution of another procedure, and so on. Stack is an ideal structure for such a system. This process is called Backtracking 20
21
21 Nested procedures terminating in the opposite order to that in which they were requested
22
BACKTRACKING Suppose we want to print the names in a linked list in a reverse order that is last name first. We can access the names only by following the link structure. Thus we need to use the stack. 22
23
23 Using a stack to print a linked list in reverse order (continue d)
24
24 Using a stack to print a linked list in reverse order
25
25 A procedure (using an auxiliary stack) for printing a linked list in reverse order
26
26 A stack in memory
27
27 Stacks Last-in first-out. Push and pop. Using stacks for maintaining procedure calls. Other applications???
28
QUEUES Queue is a list in which all insertions are performed at one end while all deletions are made at the other end. The end at which entries are removed is called the Head [ or sometimes the Front] of the queue. The end of the queue at which new entries are added is called the Tail[ or Rear]. 28
29
QUEUES QUEUE uses two memory cells to use as pointers instead of just one. Head Pointer Tail Pointer 29
30
30 A queue implemented with head and tail pointers
31
31 A queue crawling through memory
32
32 A circular queue (a) containing the letters F through O as actually stored in memory
33
33 A circular queue (b) in its conceptual form in which the last cell in the block is adjacent to the first cell
34
34 Queues First-in first-out. Head and tail. Circular queue.
35
TREES The last Data structure that we will consider is the tree, which is the structure reflected by an organization chart of a typical company. 35
36
36 An example of an organization chart
37
TREES Tree consists of a collection of nodes which are interconnected by branches to form a tree like configuration, as shown below: 37
38
38 Tree terminology
39
TREES The branches emanate downward from the nodes, The node is presented by a square. The top node is called the root of the tree. All of the remaining nodes are called either branch or terminal nodes. The branch nodes have branches emanating from them, the terminal nodes do not. 39
40
TREES The degree of a node is equal to the number of sub-trees that emanate from that node. Terminal nodes are therefore nodes of degree zero. All trees have two or more levels. The root is the 1 st level. The subsequent nodes increase in level as they branch out from the root. 40
41
BINARY TREE It is tree in which each node has at most two children. This trees are stored in memory using a linked structure with two pointer called: Left Child Pointer Right Child Pointer 41
42
42 The structure of a node in a binary tree
43
43 The conceptual and actual organization of a binary tree using a linked storage system
44
44 A tree stored without pointers
45
BINARY TREE Another alternative storage system The location of a nodes parent can be found by dividing the nodes position in the block by 2 while discarding any remainder [the parent of the node in position 7 would be the node in position 3] 45
46
BINARY TREES The location of a nodes sibling can be found by adding 1 to the location of a node in even position or subtract 1 from location of a node in an odd position. Node 4 ( 4+1)= 5 Node 3 ( 3- 1 )= 2 46
47
47 A sparse, unbalanced tree shown in its conceptual form and as it would be stored without pointers
48
Searching the list If the list were stored according to the linked list model, we would be forced to search the list in sequential fashion, a process could be very inefficient if the list should become long. We will seek an implementation that allows us to use the binary search algorithm. 48
49
Searching The List To apply this algorithm, our storage system must allows us to find the middle entry of successively smaller portion of the list. This can be done using linked binary tree. Ex. The list of letters [ A, B, C, D, E, F, G, H, I, J, K, L, and M ] 49
50
50 The letters A through M arranged in an ordered tree
51
51 The binary search as it would appear if the list were implemented as a linked binary tree
52
52 The successively smaller trees considered by the procedure in when searching for the letter J
53
53 Printing a search tree in alphabetical order
54
54 A procedure for printing the data in a binary tree
55
55 Inserting the entry M into the list B, E, G, H, J, K, N, P stored as a tree (continued)
56
56 Inserting the entry M into the list B, E, G, H, J, K, N, P stored as a tree
57
57 A procedure for inserting a new entry in a list stored as a binary tree
58
58 Trees Trees - an organization chart; e.g., family tree and companys organization. Root node, leaf nodes, arc, sub trees. Parent, children, siblings. Depth of a tree. Tree implementation. Binary tree.
59
59 A stack of integers implemented in C++
60
60 A stack of integers implemented in Java and C#
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.