Skip to main content
Introduction to Data Structures By: Abdul Ghaffar
Contents Introduction Queues Stacks  Linked lists Trees
Basic Terminology Data Raw facts and figures are called data. Information Data with given attributes, or meaningful or processed data is called  information Group & Elementary data items If a data item can be divided into sub items then it is called group item else it is called elementary item. Entity An entity is something that has certain attributes or properties which may be assigned values.
Basic Terminology Entity Set Entities with similar attributes form an entity set . Hierarchy of data organization Field A field is a single elementary unit of information representing an attribute of an entity. Record A record is collection of field  values of a given entity. File A file is a collection of records of the entities in a given entity set
Basic Terminology Primary Key If the value in certain field may uniquely identity the record in the file then such a field is called primary key
Basic Terminology Data Structures The logical and mathematical model of a particular organization of data is called Data structure Essential to implement most algorithms Data Structures + Algorithms = Programs Computer languages support their creation Defined using “primitive types” and language constructs Steps the in study of Data Structures Logical or mathematical description of the structure Implementation of the structure on a computer Quantitative analysis of the structure (time & Space)
Data Structures Arrays A list of finite number n of similar data elements referenced respectively by a set of n consecutive numbers One-Dimensional Two-Dimensional Three-Dimensional
Data Structures Linked List A linked list is a linear collection of data elements, called nodes, where linear order is given by means of pointers. 7 next head 11 next 14 next 18 next NULL
Data Structures Trees The data structure which reflects hierarchical relationship between various elements is called a rooted tree or simply Tree. 17 15 14 9 6 5 8
Data Structures Stack A stack is a linear list in which insertion and deletion can take place only at one end (LIFO) 9 1 2 3 4 5 6 7 8 9 11 7 18 14 S top
Data Structures Queue A queue is a linear list in which deletion & insertion can not take place at the same end (FIFO) 1 2 3 4 5 6 7 8 9 11 7 18 14 Q head tail
Data Structures Graph  The data structure which reflects relationship between pairs of elements is called a graph.
Data Structures Data Structure Operations Traversing Searching Inserting Deletion Sorting Merging MINIMUM(S) MAXIMUM(S) IsEMPTY(S) PRINT(S) COUNT(S)
Algorithm Algorithm An algorithm is a finite step by step list of well defined instructions for solving a particular problem.
Algorithm Example
Algorithm Control Structures Sequence logic Selection logic Single  alternative If condition, then [Module A] [End of if structure]
Algorithm Double Alternative If condition, then [Module A] Else [Module B] [End of If structure]
Algorithm Multiple Alternatives If condition, then [Module A] Else if  condition2,  then [Module B] Else if  condition3, then [Module C] Else if  condition4, then [Module D] Else  [Module E] [End of if structure]
Algorithm Example
Algorithm Control Structures Iteration logic Repeat for K=R to S by T [Module] [End of loop] Repeat while condition [Module] [End of loop]
Algorithm Example
Algorithm Complexity of Algorithm The complexity of an algorithm f(n) is the function which gives the ruining time or space in term of the input size. Time-Space trade-off The Time-Space trade-off refers to a choice between algorithmic solution of a data processing problem that allows one to decrease the running time of an algorithmic solution by increasing the space to store the data and vice versa. Linear Search C(n) = (n+1)/2 Binary Search C(n) = log 2  n
Algorithm Binary Search