data structure is concerned with the various ways that data files can be organized and assembled....
TRANSCRIPT
![Page 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](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/1.jpg)
• 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
![Page 2: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/2.jpg)
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.
![Page 3: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/3.jpg)
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].
![Page 4: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/4.jpg)
DEFINITION
• 4- The Link [ Pointer]: Contain the starting addresses of other nodes, thus creating a structural interrelationship among the nodes.
4
![Page 5: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/5.jpg)
5
Novels arranged by title but linked according to authorship
![Page 6: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/6.jpg)
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
![Page 7: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/7.jpg)
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
![Page 8: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/8.jpg)
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
![Page 9: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/9.jpg)
9
The array of Readings stored in memory starting at address
![Page 10: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/10.jpg)
10
A two-dimensional array with four rows and five columns stored in row major order
![Page 11: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/11.jpg)
11
Names stored in memory as a contiguous list
![Page 12: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/12.jpg)
12
A two-dimensional array with four rows and five columns stored in row major order
![Page 13: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/13.jpg)
13
Names stored in memory as a contiguous list
![Page 14: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/14.jpg)
14
The structure of a linked list
![Page 15: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/15.jpg)
15
Deleting an entry from a linked list
![Page 16: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/16.jpg)
16
Inserting an entry into a linked list
![Page 17: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/17.jpg)
17
A procedure for printing a linked list
![Page 18: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/18.jpg)
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
![Page 19: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/19.jpg)
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
![Page 20: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/20.jpg)
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
![Page 21: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/21.jpg)
21
Nested procedures terminating in the opposite order to that in which they were requested
![Page 22: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/22.jpg)
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
![Page 23: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/23.jpg)
23
Using a stack to print a
linked list in
reverse order
(continued)
![Page 24: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/24.jpg)
24
Using a stack to print a
linked list in reverse
order
![Page 25: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/25.jpg)
25
A procedure (using an auxiliary stack) for printing a linked list in reverse order
![Page 26: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/26.jpg)
26
A stack in memory
![Page 27: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/27.jpg)
27
Stacks
• Last-in first-out.• Push and pop.• Using stacks for maintaining procedure calls.• Other applications???
![Page 28: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/28.jpg)
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
![Page 29: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/29.jpg)
QUEUES
• QUEUE uses two memory cells to use as pointers instead of just one .
• Head Pointer• Tail Pointer
29
![Page 30: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/30.jpg)
30
A queue implemented with head and tail pointers
![Page 31: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/31.jpg)
31
A queue “crawling” through memory
![Page 32: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/32.jpg)
32
A circular queue
(a) containing the letters F through
O as actually stored in memory
![Page 33: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/33.jpg)
33
A circular queue (b) in its conceptual form in which the last cell in the block is “adjacent” to the first cell
![Page 34: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/34.jpg)
34
Queues
• First-in first-out.• Head and tail.• Circular queue.
![Page 35: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/35.jpg)
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
![Page 36: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/36.jpg)
36
An example of an organization chart
![Page 37: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/37.jpg)
TREES
• Tree consists of a collection of nodes which are interconnected by branches to form a tree like configuration, as shown below:
37
![Page 38: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/38.jpg)
38
Tree terminology
![Page 39: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/39.jpg)
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
![Page 40: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/40.jpg)
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 1st level. The subsequent nodes increase in level as they branch out from the root.
40
![Page 41: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/41.jpg)
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
![Page 42: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/42.jpg)
42
The structure of a node in a binary tree
![Page 43: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/43.jpg)
43
The conceptual and actual organization of a binary tree using a linked storage system
![Page 44: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/44.jpg)
44
A tree stored without pointers
![Page 45: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/45.jpg)
BINARY TREE
• Another alternative storage system • The location of a node’s parent can be found
by dividing the node’s 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
![Page 46: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/46.jpg)
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
![Page 47: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/47.jpg)
47
A sparse, unbalanced tree shown in its conceptual form and as it would be stored
without pointers
![Page 48: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/48.jpg)
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
![Page 49: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/49.jpg)
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
![Page 50: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/50.jpg)
50
The letters A through M arranged in an ordered tree
![Page 51: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/51.jpg)
51
The binary search as it would appear if the list were implemented as a linked binary tree
![Page 52: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/52.jpg)
52
The successively smaller trees considered by the procedure in when searching for the letter
J
![Page 53: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/53.jpg)
53
Printing a search tree in alphabetical order
![Page 54: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/54.jpg)
54
A procedure for printing the data in a binary tree
![Page 55: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/55.jpg)
55
Inserting the entry M into the list B, E, G, H, J, K, N, P stored as a tree
(continued)
![Page 56: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/56.jpg)
56
Inserting the entry M into the list B, E, G, H, J, K, N, P stored as a tree
![Page 57: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/57.jpg)
57
A procedure for inserting a new entry in a list stored as a binary tree
![Page 58: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/58.jpg)
58
Trees
• Trees - an organization chart; e.g., family tree and company’s organization .
• Root node, leaf nodes, arc, sub trees.• Parent, children, siblings.• Depth of a tree.• Tree implementation.• Binary tree.
![Page 59: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/59.jpg)
59
A stack of integers implemented in C++
![Page 60: Data structure is concerned with the various ways that data files can be organized and assembled. The structures of data files will strongly influence](https://reader035.vdocument.in/reader035/viewer/2022062511/5518d249550346b31f8b5d54/html5/thumbnails/60.jpg)
60
A stack of integers implemented in Java and C#