Data Structures PDF
Document Details
Uploaded by EnviousSeaborgium6248
The University of Winnipeg Collegiate
Ratna Choudhury
Tags
Related
- Data Structures & Algorithms Lecture Notes 1 PDF
- Data Structures and Algorithms Study Guide (Sorsogon State University)
- Introduction to Java Programming and Data Structures (2019) by Y. Daniel Liang - PDF
- Data Structures & Algorithm Past Paper (July 2024) PDF
- Data Structures and Algorithms with Python and C++ PDF
- Data Structures and Algorithms(All Sessions) PDF
Summary
This document is a lecture on data structures covering basic terminology, characteristics, operations, and examples of linear and non-linear structures. The document is related to computer science and programming.
Full Transcript
Data Structures Ratna Choudhury The University of Winnipeg Collegiate What is Data? Data is information optimized for processing and movement, facts and figures stored in computers. Basic Terminology Data − Data are values or collections of values. Data Item - A data item is...
Data Structures Ratna Choudhury The University of Winnipeg Collegiate What is Data? Data is information optimized for processing and movement, facts and figures stored in computers. Basic Terminology Data − Data are values or collections of values. Data Item - A data item is a single unit of value. Group Items - They are data items that have been subdivided into sub-items. Elementary items - Data items that cannot be split are referred to be Elementary Items. Attribute and Entity - An entity is anything that has attributes or qualities that may be assigned values. Entity Set - An entity set is made up of entities with comparable properties. Field - A field is a single elementary unit of information that represents an entity's attribute. Record - A record is a collection of a specific entity's field values. File - A file is a collection of records representing the entities in a specific entity set. Data Structure Data structures are a specific way of organizing data in a specialized format on a computer so that the information can be organized, processed, stored, and retrieved quickly and effectively. They are a means of handling information, rendering the data for easy use. Every application, piece of software, or programs foundation consists of two components: algorithms and data. Data is information, and algorithms are rules and instructions that turn the data into something useful to programming. Data Structure Operations The following are the most frequent operations that may be done on data structures: 1. Searching - Searching entails locating a certain piece inside a specified data structure. When the needed ingredient is discovered, it is termed a success. Searching is an operation that may be done on data structures such as arrays, linked lists, trees, graphs, and so on. Data Structure Operations 2. Sorting - Sorting is the process of ordering all data elements in a data structure in a certain order, such as ascending or descending order. 3. Insertion - entails adding new data items to the data structure. 4. Deletion -The data elements in the data structure can be deleted. 5. Updating - We can update or replace existing data structure parts. Characteristics of Data Structures Data Structure is the systematic way used to organise the data. The characteristics of Data Structures are: Linear or Non-Linear This characteristic arranges the data in sequential order, such as arrays, graphs etc. Static and Dynamic Static data structures have fixed formats and sizes along with memory locations. The static characteristic shows the compilation of the data. Characteristics of Data Structures Time Complexity The time factor should be very punctual. The running time or the execution time of a program should be limited. The running time should be as less as possible. The less the running time, the more accurate the device is. Characteristics of Data Structures Correctness Each data must definitely have an interface. Interface depicts the set of data structures. Data Structure should be implemented accurately in the interface. Space Complexity The Space in the device should be managed carefully. The memory usage should be used properly. The space should be less occupied, which indicates the proper function of the device. Execution Time Cases There are three situations that are commonly used to compare the execution time of various data structures in a relative way. Worst Case - This is the circumstance in which a specific data structure operation takes the longest time possible. Average Case - This is a scenario that depicts the average execution time of a data structure action. Best Case -This is the scenario displaying the shortest feasible execution time of a data structure operation. Linear Data Structures Data elements in a linear data structure are linked to one another in a sequential arrangement, with each element linked to the elements in front of and behind it. In this manner, a single run can traverse the structure. Linear data structures consist of four types. They are: Stack Array Queue Linked list Stack The linear data structure stores the data elements in the ‘first-in/ last-out’ or the ‘last-in/ first out’ order. These orders are known as FILO and LIFO orders, respectively. By using Stack, the element can be added and removed simultaneously from the same end. In Python, Stack can be developed in the following ways. 1.Queue.LifoQueue 2.List 3.Collections.deque In Stack, the terms ‘Push’ and ‘Pop’ are used instead of ‘insert’ and ‘delete’. Array It is the collection of similar data types that are stored in the Contiguous Memory Locations. Arrays are used in Python as well. Arrays work on the scale of 0 to (n-1), where ‘n’ denotes the size of the array. Arrays are of two types. They are: 1.One-dimensional Array 2.Multi-dimensional Array Queue The queue is a linear data structure that follows the FIFO order. FIFO stands for First In and First Out. The order is that the elements which are inserted first are to be removed first. The properties of Queue data structure are: 1.Inserting an element 2.Deleting the element 3.Time of access. Linked List Linked Lists separate the data structures that are stored consecutively. The last node of a data structure will be linked to the first node of the next data structure. The first element of any data structure is known as the Head of the List. The linked list helps in memory allocation, stores data in internal structure etc. There are three types of Linked Lists. They are: 1.Single Linked List 2.Double Linked List 3.Circular Linked List Non-Linear Data Structures The data structure in which the data elements are randomly arranged. The elements are non-arranged sequentially. The data elements are present at different levels. In Non-linear data structures, there are different paths for an element to reach the other element. The data elements in the non-linear data structures are connected to one or more elements. There are two types of non-linear data structures. They are: Tree Data Structure Graph Data Structure Tree Data Structure Tree data structures are completely different from the arrays, stacks, queues and linked lists. Tree data structures are hierarchic. The tree data structure collects the nodes together to depict and stimulate the sequence. Tree data structure does not store the data sequentially. It stores the data on multiple levels. The top node of the Tree Data Structure is known as the Root Node. Any type of data can be stored in the root node. Each node shall definitely contain the data. The branches in the Tree Data Structure are known as the children. Tree Data Structure The different parts of the Tree Data Structure are: 1.Root Node 2.Child Node 3.Edge 4.Siblings 5.Leaf Node 6.Internal Nodes 7.Height of the tree 8.Degree of the Node Graph Data Structure In Graph Data Structure, one node is simply connected to the other node through the edge of the graph. The Graph Data Structure obviously uses Non-linear data structures which are not sequentially arranged. The graph data structures consist of edges and nodes represented by E and V, respectively. Graph Data Structures do not have root nodes. It does not have a standard order of arranging the data. Every tree is also known as the graph with n-1 edges where ‘n’ represents the total number of vertices in the graph. There are various categories in the graphs such as undirected, unweighted, directed and weighted. Graph Data Structure The different parts of the graph are as follows. 1.Vertex 2.Edges 3.Directed Edge 4.Undirected Edge 5.Weighted Edge 6.Degree 7.Indegree 8.Outdegree Linear vs Non-linear Data Structures Parameter Linear Data Structure Non-linear Data Structure In the case of a non-linear data structure, the data pieces are ordered non- In the case of a linear data structure, the data items are stored in a linear Arrangement of the data elements linearly and attached hierarchically. The data elements are linked to several order. Every element is linked to the first and next elements in the sequence. items. Categories A linear data structure can be an array, a stack, a linked list, or a queue. Non-linear data structures include trees and graphs. There are several layers involved in this arrangement. As a result, the Levels The linear data structure consists of a single level. It has no hierarchy. elements are organized hierarchically. Because linear data has only one level, traversing each data item needs only non-linear data structure data elements cannot be retrieved in a single run. It Traversal one run. is necessary to traverse many runs. Memory usages Memory use is inefficient in this case. Memory is used very efficiently in this case. Image processing and artificial intelligence both make use of non-linear data Applications Linear data structures are mostly utilized in software development. structures. The time complexity of a non-linear data structure frequently remains Time Complexity The time complexity of a linear data structure grows as the input size grows. constant as the input size increases. A non-linear data structure can have a one-to-one or one-to-many Relationships Only one form of relationship between the data pieces is possible. connection between its pieces. Data Types Data types are the basic elements in the classification of the data. Data types are used in the transmission of information between the programmer and the compiler. There are different data types. Boolean In computer programs, there are three types of data such as numbers, text and booleans. Boolean is a data type, and the value in the boolean can be either false or true or positive or negative. A boolean type of data proves whether the data is valid or invalid. Boolean values have two possible states such as True or False. In the binary system, the values 0 and 1 are used. Boolean expressions deal with algebra, logical values and binary variables. Integer The integer data type stores both positive numbers and negative numbers along with zero. The integer data type uses all these integers to maintain precision. All the arithmetic operations can be efficiently done through integer data types. If the value of data is beyond the numerical range of the integer then it is the case that the database server cannot store the value. However, integer data type consumes four(4) bytes of storage per value. Floating-Point Numbers A floating-point data type approximates real values using a formula in order to allow a trade-off between range and precision. Due to the need for quick processing speeds, systems with extremely small and very large real numbers are frequently found to use floating-point calculation. An exponent in a fixed base is typically used to scale a number and approximate its representation to a specific number of significant digits. Fixed-Point Numbers Binary words are used to store numbers in digital electronics. A fixed- length string of bits (1s and 0s) is a binary word. The data type determines how these 1s and 0s are interpreted by hardware elements and software processes. There are two different data types for binary numbers: fixed- point and floating-point. Both signed and unsigned fixed-point data formats are available. There is no sign bit. Therefore the binary word does not typically explicitly express whether a fixed-point value is signed or unsigned. In contrast, the architecture of the computer implicitly defines the sign information. Binary words are used to store numbers in digital electronics. A fixed- length string of bits (1s and 0s) is referred to as a binary word. The data type determines how these 1s and 0s are interpreted by hardware elements and software processes. There are two different data types for binary numbers: fixed-point and floating-point. Character Character information is stored in a fixed-length field by the CHAR data type. Data can be a string of letters, integers, and other characters that are supported by the code set of your database locale, whether they are single-byte or multibyte characters. Strings with a fixed length or a variable length can be used to hold character data. Variable-length strings are not extended; fixed-length strings are right-extended with spaces on output. Pointers Blocks of memory that are dynamically allocated are managed and stored using pointers. Data objects or arrays of objects are stored in such alliances. The heap or free store, which is a memory space provided by the majority of structured and object-oriented languages, is where objects are dynamically allocated. String A string data type consists of a series of characters, either in the form of a literal constant or a variable. The latter can either be constant in length or allow its elements to alter (after creation). An array data structure of bytes (or words) is frequently used to create a string, which is typically thought of as a sort of data and contains a succession of items, typically characters, using some kind of character encoding. How Are Data Structures Used? Implementing the physical representations of abstract data types uses data structures. When creating effective software, data structures are a key component. They are also essential to the design of algorithms and the use of those algorithms in software. The data structures are used in different aspects. Storing Data When providing the set of attributes and matching structures that will be used to store records in a database management system, data structures are utilised to efficiently persist data. Managing Resources and Services Data structures, including linked lists for memory allocation, file directory management and file structure trees, as well as process scheduling queues, are used to allow core operating system (OS) resources and functions. Data Exchange Information shared across applications, such as TCP/IP packets, is organised using data structures. Ordering and Sorting Binary search trees, sometimes referred to as ordered or sorted binary trees, are data structures that offer practical ways to sort things, such as character strings used as tags. Programmers can control objects arranged in a given priority using data structures like priority queues. Indexing To index items, such as those kept in a database, even more complex data structures like B-trees are utilised. Searching B-trees, hash tables, and binary search trees are standard techniques used to generate indexes that speed up the process of finding a particular item. Scalability Data structures are used by big data applications to allocate and manage data storage across distributed storage sites, assuring performance and scalability. To make querying easier, several big data programming environments, like Apache Spark, offer data structures that replicate the fundamental structure of database entries. Choosing a Data Structure The steps to be used in choosing the data structure are given below. 1) The first step in determining the basic operations that must be supported is to analyse the problem. Inserting a data item into the data structure, deleting a data item from the data structure, and finding a specific data item are examples of basic operations. 2)Identify the resource constraints for each operation and quantify them. 3) Determine which data structure best meets these requirements. Supported Operations If the underlying data type of an attribute can be translated into one of the kinds for which an operation is supported, processes between the data types not included in the table can be carried out. Data can have numbers added or subtracted from them. The number of days to be added or removed is represented by integers. For instance, since IEG INT8 is turned into IEG DOUBLE and the addition of IEG DOUBLE and IEG MONEY is supported, the addition of IEG INT8 and IEG MONEY is possible. Computational Complexity Computational complexity is a metric for how much time and memory (resources) a specific algorithm uses when it is executed. Before developing the code, computer scientists can forecast an algorithm's execution time and memory needs using mathematical metrics of complexity. For programmers implementing and choosing algorithms for practical applications, these predictions are essential guides. Programming Elegance One of those things that are simple to recognise but difficult to define is an elegant programme. It uses words effectively without resorting to obfuscation. It is succinct without employing complicated code. It strikes a balance between the concepts of simplicity and explicitness, coding complexity while staying superficial to read and understand. Writing the coding equivalent of flawless writing is every programmer's ultimate ambition. There is no "magic solution" or one solution to this issue. Coding standards can be used to aid, but they must be founded on a solid framework that ensures the core of the matter is conveyed to the programmer and reflected in the code. Data Types and Their Relationship With Data Structures Abstract. Abstract data is defined by how it behaves. This type encompasses graphs, queues, stacks, and sets. Composite (or Compound). Composite data comprises combined primitive data types and includes arrays, classes, records, strings, and structs. They may also consist of other composite types. Data Types and Their Relationship With Data Structures Primitive. Primitive data is classified as basic data and consists of Boolean, characters, integers, pointers, and fixed- and floating-point numbers. These data types are the building blocks of data structures. Data types tell the interpreter or the computer how the programmer plans on using the data. Furthermore, data analysts can choose from different data structure classifications. The trick is to select the structure best suited for your needs and situation. Advantages of Data Structures 1. Data structure facilitates effective data storage in storage devices. 2. The use of data structures makes it easier to retrieve data from a storage device. 3. The data structure allows for the effective and efficient processing of both little and big amounts of data. 4. Manipulation of vast amounts of data is simple when a proper data structure technique is used. 5. The use of a good data structure may assist a programmer to save a lot of time or processing time while performing tasks such as data storage, retrieval, or processing. Advantages of Data Structures 6. Most well-organized data structures, including stacks, arrays, graphs, queues, trees, and linked lists, have well-built and pre-planned approaches for operations such as storage, addition, retrieval, modification, and deletion. The programmer may totally rely on these facts while utilising them. 7. Data structures such as arrays, trees, linked lists, stacks, graphs, and so on are thoroughly verified and proved, so anybody may use them directly without the need for study and development. If you opt to design your own data structure, you may need to do some study, but it will almost certainly be to answer a problem that is more sophisticated than what these can supply. 8. In the long term, data structure utilization might merely encourage reusability.