The document provides an introduction to data structures, explaining basic terminology such as data, entities, and information, as well as the classification of data structures into primitive and non-primitive types. It discusses various data structures like arrays, linked lists, trees, stacks, queues, and graphs, along with their operations including traversing, searching, inserting, deleting, sorting, and merging. Additionally, it highlights the importance of algorithm efficiency in terms of time and space complexity.
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
6 views
Introduction to Data Structures v2 12042022
The document provides an introduction to data structures, explaining basic terminology such as data, entities, and information, as well as the classification of data structures into primitive and non-primitive types. It discusses various data structures like arrays, linked lists, trees, stacks, queues, and graphs, along with their operations including traversing, searching, inserting, deleting, sorting, and merging. Additionally, it highlights the importance of algorithm efficiency in terms of time and space complexity.
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26
Introduction to
Data Structures
Ms. Divya Verma
Assistant Professor,IT Contents: Introduction to Data Structures Classification Operations of Data Structures Basic Terminology: Elementary Data Organizations 1)Data: Simply values or set of values. Data item refers to a single unit of values. Data items that are divided into sub items are called group items,those that are not are called elementary items. Example-Employee’s name may be divided into first name,middle name and the last name. Collections of data are frequently organized into a hierarchy of fields,records and files. II) Entity: Something that has certain attributes or properties which may be assigned values. The values may be either numeric or non numeric. Example:
Attribute Name RollNo. Marks
Values ABC 001 90 DEF 002 100 Entities with similar attributes form an entity set. Each attribute of an entity set has a range of values. III)Information: Meaningful or processed data. IV)Field: A single elementary unit of information representing an attribute of an entity. V)Record: Collection of field values of a given entity. VI)File: Collection of records of the Records may be classified according to length: i) fixed-length records Ii) variable-length records In fixed-length records, all the records contain the same data items with the same amount of space assigned to each data item. In variable-length records, file records may contain different lengths. The organization of data into fields, records and files may not be complex enough to maintain and efficiently process certain collections of data. For this reason, data are also organized into more complex types of structures. The study of such data structures, which forms the subject matter, includes the following three steps: Logical or mathematical description of the structure Implementation of the structure. Quantitative analysis of the structure that determines the memory needed to store the structure and the time requirement to process the structure. Data Structures: Introduction Way of collecting and organizing data in such a way that we can perform operations on these data in an efficient way. Defn: Logical or mathematical model of a particular organization of data is called a data structure. The choice of a particular data model depends on two considerations- It must be rich enough in structure to mirror the actual relationships of the data in the real world. It must be simple enough that one can effectively process the data when necessary. Classification of Data Structures: Primitive: Basic data types such as integer, real, character and boolean are primitive data types. These data types consists of characters that cannot be divided. Directly operated upon by machine level instructions. Non-primitive: Example: processing of complex numbers- not many computers are capable of doing arithmetic on complex numbers. Linked-lists, stacks, queues, trees etc are examples. Based on the structure and arrangement of data, non-primitive data structures are further classified into linear and non-linear. Linear: Elements form a sequence or a linear list. Data is arranged in a linear fashion although the way they are stored in memory may not be sequential. Non-linear: data is not arranged in sequence. The insertion and deletion of data is therefore not possible in a linear fashion. Arrays The simplest type of data structure is a linear or one-dimensional array. A list of finite number n of similar data elements referenced respectively by a set of n consecutive elements,usually 1,2,3...n. Example: if A is an array,then elements of A are denoted by a1,a2,a3,....an Or A(1),A(2),A(3),....A(N) Or A[1],A[2],A[3],....A[N] Hence the number k in A[k] is called the subscript and A[k] is called the subscripted variable. 2-Dimensional array is a collection of similar data elements where each element is referenced by two subscripts. Example: Matrices. Example:
1) Lets consider an array named
student consisting of 5 elements. Then each element can be referenced by a subscript. Student Abc student[1] Def student[2] Ghi student[3] Jkl student[4] Mno student[5] 2)Similarly, 2-D array is denoted by 2 subscripts,one for the row and the other one for the column.
1stsubscript denotes the store and 2nd
denotes department. Sales[1,1]=2872 rows -> horizontal lines Sales[1,3]=3211 columns-> vertical lines Sales[3,2]=1017 Linked Lists Collection of different nodes where each node is connected to the next node. Example: The data here is stored in a table using 2 columns but this is not efficient. Another way of storing the data is to have a separate array for the salesperson and an entry (called a pointer) in the customer file which gives the location of each customer’s salesperson.
Here,a pointer is used to
point to the location of the corresponding salesperson. An integer used as a pointer require less space than a name,hence it saves space. Suppose the firm wants the list of customers for a salesperson,then the entire customer file would have to be searched. Another way would now be to have a set of pointers give the position of the customers. The main disadvantage of this representation is that each salesperson may have may pointers and the set of pointers will change as customers are added/deleted. Another very effective means to store the data is through linked lists. The salesperson has one pointer which points to the first customer,whose pointer in turn points to the 2nd customer and so on,with the salesperson’s last customer indicated by 0. Trees Used to store the data of hierarchical relationships Stacks LIFO i.e Last in First Out. Insertions and deletions can take place only at one end. i.e. Top. Example: Book shelf Queue FIFO i.e. First In First Out Linear list in which deletions can take place only at one end i.e. Front of the list and insertions take place only at rear of the list. Example: Queue waiting at the bus stop. Graphs Data sometimes contain a relationship between elements which is not hierarchical in nature. Data Structure Operations Data contained in data structures is processed by means of certain operations. The particular data structure that one chooses depends largely on the frequency with which specific operations are performed. 1)Traversing: accessing each element exactly once so that certain elements can be processed. 2)Searching: finding the location of the record with a given key value, or finding the location of all records which satisfy one or more conditions. 3) Inserting: adding a new record to the structure. 4)Deletion: Removing a record from the structure. 5)Sorting:arranging the records in some logical order. 6)Merging:combining the records in two different sorted files into a single sorted files. Algorithm-Time Space Trade off Algorithm is a well defined list of steps for solving a particular problem. The time and space it uses are two major measures of the efficiency of an algorithm. The complexity of an algorithm is the function which gives the running time or space in terms of the input size.