









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










Module 3: Implementation of Data Structures
Module Overview
Computer programs usually operate on tables of data (information). To realize efficient algorithms and programs, it is very important to supply pre-knowledge of data types to the compiler in order to avoid storage allocation problems (i.e. problem of dynamic storage allocation).
The amount of storage allocated, say to a variable, will have to be chosen according to the size of the range of values, and their relationships, that the variables may assume. Therefore, to use a computer properly, we need to understand the structural relationships present within data as well as the basic techniques for representing and manipulating such structure within a computer.
The data elements to be manipulated by a program are required to be associated with a type, which in turn is required to be made explicit by a declaration from the very beginning. From initial programming experience, one can recall that the standard primitive data types are; integer, real, Boolean, character, and set. The data type characterizes the set of values to which elements, such as constants, variables, expressions, or functions, belong to.
In general, the design of computer representations depends on the desired functions of the data as well as on its intrinsic properties (relationships). This module discusses the basic sets by which data stored in the computer memory can be manipulated. The sets are held in data structures depending on their intrinsic operability. They can change over time by growing or shrinking. Therefore, this module shows the several types of operations that can be performed on sets, such as insertion, deletion, or test of membership, and illustrates them as they apply to the basic data structures of stacks, queues, linked lists, and trees.
In this module, we shall be discussing the following study units:
Study Unit 1: Stacks and Queues
Study Unit 2: Linked Lists and Trees
Study Unit 1: Stack and Queue Data Structure
Expected Duration: # week
Introduction
The elementary data structures, which form many complex data structures, are identified with respect to the principal operations to be performed, just as it is notable that computer memories are distinguished by their intended applications. Here, the elementary data structures of interest are those of stacks, queues, linked lists, and rooted trees. We, therefore, consider some of the basic operations involving these data structures. Learning Outcomes for Study Unit 1
At the end of this study unit, you should be able to;
1.1 Define and use correctly the words in bold (SAQ 1.1).
1.2 List and explain the operations on stack (SAQ 1.2).
1.3 List and explain the operations on queue (SAQ1.3).
1.1 What does Stack Data Structure mean?
// Alternative Pseudocode
POP (S)
In-text Question: What is another name for pop operation in stack?
Solution: Delete
1.3 Queue data Structure and associated Operations
1.3.1 Meaning of Queue Data Structure
1.3.2 Operations on Queues The following pseudocodes can be used to implement the basic operations of a queue. Considering a queue Q, an array Q [1,…, n] where n is the length of queue.
(1) ENQUEUE (Q, x)
ENQUEUE = (Q, x)
(2) DEQUEUE ( Q )
Optimal design of heat exchanger networks, Editor(s): Wilfried Roetzel, Xing Luo, Dezhen Chen, Design and Operation of Heat Exchangers and their Networks, Academic Press, 2020, Pages 231-317, ISBN 9780128178942, https://doi.org/10.1016/B978-0-12-817894-2.00006-
Wang FS., Chen LH. (2013) Genetic Algorithms. In: Dubitzky W., Wolkenhauer O., Cho KH., Yokota H. (eds) Encyclopedia of Systems Biology. Springer, New York, NY. https://doi.org/10.1007/978-1-4419-9863-7_ Fred Glover (1986). "Future Paths for Integer Programming and Links to Artificial Intelligence". Computers and Operations Research. 13 (5): 533– 549,https://doi.org/10.1016/0305-0548(86)90048- Optimization of Preventive Maintenance Program for Imaging Equipment in Hospitals, Editor(s): Zdravko Kravanja, Miloš Bogataj, Computer-Aided Chemical Engineering, Elsevier, Volume 38, 2016, Pages 1833-1838, ISSN 1570-7946, ISBN 9780444634283, https://doi.org/10.1016/B978-0-444-63428-3.50310-6. Glover, Fred, and Gary A Kochenberger. Handbook Of Metaheuristics. Kluwer Academic Publishers, 2003. Kirkpatrick, S., Gelatt, C., & Vecchi, M. (1983). Optimization by Simulated Annealing. Science, 220 (4598), 671-680. Retrieved November 25, 2020, from http://www.jstor.org/stable/ Brief review of static optimization methods, Editor(s): Stanisław Sieniutycz, Jacek Jeżowski, Energy Optimization in Process Systems and Fuel Cells (Third Edition), Elsevier, 2018, Pages 1-41, ISBN 9780081025574, https://doi.org/10.1016/B978-0-08-102557-4.00001-3. NIU, M., WAN, C. & Xu, Z. A review on applications of heuristic optimization algorithms for optimal power flow in modern power systems. J. Mod. Power Syst. Clean Energy 2, 289– 297 (2014), https://doi.org/10.1007/s40565-014-0089- J. L. Wang, Y. H. Lin and M. D. Lin, "Application of heuristic algorithms on groundwater pumping source identification problems," 2015 IEEE International Conference on Industrial Engineering and Engineering Management (IEEM), Singapore, 2015, pp. 858-862, https://doi.org/10.1109/IEEM.2015.7385770. Matott, L. Shawn, et al. “Application of Heuristic Optimization Techniques and Algorithm Tuning to Multilayered Sorptive Barrier Design.” Environmental Science & Technology, vol. 40, no. 20, 2006, pp. 6354–6360., https://doi.org/10.1021/es052560+.
Larranaga P, Calvo B, Santana R, Bielza C, Galdiano J, Inza I, Lozano JA, Armananzas R, Santafe G, Perez A, Robles V (2006) Machine learning in bioinformatics. Brief Bioinform 7(1):86– 112
Study Unit 2: Linked List and Tree Data Structures
Expected Duration: # week
Introduction
In this module, we shall be discussing another interesting linear data structure called linked lists. The implementation of linked list is different from stacks and queues. We shall also be looking at a more advanced data structure known as Tree data structure.
Learning Outcomes for Study Unit 2
At the end of this study unit, you should be able to; 2.1 Define and use correctly the words in bold (SAQ 2.1) 2.2 List and explain the operations on Linked lists (SAQ 2.2). 2.3 List and explain the types and operations on Tree data structure (SAQ 2.3). 2.4 List the operations on Tree data structure (SAQ 2.4) 2.5 List the application areas of Tree data Structure (SAQ 2.5). . 2.1 The Meaning of Linked Lists
Illustration
(a) L. head (^) / 9 16 4 /
L.head previous denotes the previous attribute of the object that L.head points to. The running time of LIST-INSERT on a list of n-elements is O (1) (big Oh of 1).
(3) LIST-DELETE (L, x)
In-text Question: What determines the order in a linked list Pointer or array indices? Solution: Pointer
2.3 Tree Data Structure
A tree data structure stores and organises data in a hierarchical structure. The tree data structure starts with a root node and has descendant branches. It has nodes connected by edges, where each node has a value, and some nodes have child nodes while others don't. This type of data structure resembles a tree, hence its name. A tree data structure helps organise a data hierarchy and is a non-linear data structure. Moreover, it helps in accessing data faster because it is non-linear.
2.4 Types of Tree Data Structure The various types of the tree data structure are: a. Binary Tree The binary tree in data structure is one where every element or parent node has up to two children. Hence, each node could have 1, 2, or 0 children. The two children are called the left child and the right child. The properties of a binary tree are:
It is either an empty tree or consists of nodes - root node, right subtree, and left subtree. The topmost node in the binary tree data structure is called the root. The nodes that don't have children are called terminal or leaf nodes. The tree's height is measured as the longest distance between the root node and a leaf node. The depth of the node is equal to the length of the path to its root.
b. Binary Search Tree Every node in the binary search tree has a key and associated value. This provides quick addition, lookup, and removal. It also has a maximum of two nodes, like binary trees. However, every binary search tree is a binary tree, but not vice versa. The difference between the two is that in a binary search tree, the left child node's value is less than the parent's, while the right side node's value is higher. The properties of a binary search tree are: The value of the root node must be higher than the value in all the nodes of the left subtree. The value of the root node must be higher than all the values in nodes of a right subtree.
c. AVL Tree In a tree data structure, the AVL (Adelson, Velskii, and Landis who are the inventors) tree is a binary tree that is self-balanced after checking the balance factor of every mode. Hence, the right and left subtree heights must be balanced. The balance factor could be either 0.1 or -1. The biggest difference between the left subtree and the right subtree should be 1. If the difference between the subtrees is more than 1, the trees must be re-balanced using the rotation techniques. The properties of an AVL tree are: i. The difference between the height of any two child subtrees should be at most one. ii. The balance factor is the difference between the left subtree's height and the right subtree's height. iii. The -1 balance factor states that the right subtree is one level higher than the left subtree. iv. The 0 balance factor states that the left and right subtree heights are equal.
Searching: It is a simple process to search in a binary tree to check if the current node value matches the required value. The process can be repeated to the right and left subtrees with a recursive algorithm until a match is found. Deletion: Deleting is a tricky process in a tree data structure. When we delete a node, complications may occur to the right and left children. A deleted node is a leaf node that occurs. Thus, the deletion process of a node includes: Checking if the root is NULL. Searching for an item in the left and right subtree and recursing it. Deleting the root node of a tree. In-text Question: What is the difference between a Binary Tree and a Binary Search Tree? Solution: The difference between the two is that in a binary search tree, the left child node's value is less than the parent's, while the right side node's value is higher.
2.5 Applications of a Tree Data Structure The tree data structure stores the data in a hierarchical manner. The nodes are arranged at multiple levels. Thus, the application of a tree data structure is: i. Information in the computer is stored hierarchically. There are multiple folders in a drive, and each folder has many sub-folders. The files include images, documents etc. ii. It is easy to search for a node in a tree data structure. Operations like insertion and deletion are easy to perform. iii. The tree data structure is used to store data in the routing tables. iv. Programmers also use syntax trees to verify the syntax of the programs they write.
Data structures are the building blocks of a programming language. They are used for simple and complex computations in various areas of computer science. Having strong knowledge of tree data structures is important as they are the foundation of writing code. Hence, this knowledge can help one secure well-paying jobs.
2.6 Summary of Study Unit 2 In this unit, you have learned the following;
2.7 Self-Assessment Questions (SAQs) for Study Unit 2 Now that you have completed this study session, you can check to see how well you have achieved its Learning Outcomes by answering the following questions. SAQ 2.1 (Tests learning outcome 2.1)
Engineering and Engineering Management (IEEM), Singapore, 2015, pp. 858-862, https://doi.org/10.1109/IEEM.2015.7385770. Matott, L. Shawn, et al. “Application of Heuristic Optimization Techniques and Algorithm Tuning to Multilayered Sorptive Barrier Design.” Environmental Science & Technology, vol. 40, no. 20, 2006, pp. 6354–6360., https://doi.org/10.1021/es052560+. Larranaga P, Calvo B, Santana R, Bielza C, Galdiano J, Inza I, Lozano JA, Armananzas R, Santafe G, Perez A, Robles V (2006) Machine learning in bioinformatics. Brief Bioinform 7(1):86– 112
Notes to the Self- Assessment Questions (SAQs) for Study Unit 1 SAQ 1.1 (Tests learning outcome 1.1)