Data Structure Using C What is a Data ? Data is a collection of raw facts or figures. Ex:- name of a student, age of an employee, color of room, any number, string, etc. Data are store in computer in the form of bits i.e. 0 or 1. In real life there are various types of data are involved. What is Information? It is the process data. What is Data Structure ? • Data Structure is a way for structuring data i.e. way of storing data in a computer so that:we can be used it efficiently. we can easily retrieve the data. we can easily modify the data. • Data structure is a collection of organized data along with its mathematical operations which are efficient. • Data Structure = Organized Data + Allowed Operation Data Structure consists of two thing:1. The type of structure that we are going to use to store data. 2. How efficiently we perform operations onto the data stored in structure so that it results in less execution time and amount of memory space they required. Classification of Data Structure based on data store Data structures may be Linear or Non-Linear. • Linear Data Structure :- Data items are arranged in a linear sequence . Ex:- Array and Linked list
• Non-Linear Data Structure :- Data items are not in linear sequence i.e. the elements are not accessed in sequential manner. Ex:- Tree and Graph. Data structures may be Homogeneous or Heterogeneous. • Homogeneous Data Structure :- Data items are of similar type . Ex:- Array • Heterogeneous Data Structure :- Data items are of different type. Ex:- Structure (Record). Data structures may be Static or Dynamic. • Static Data Structure :- The size of Data Structure is fixed at compilation time. Ex:- Array • Dynamic Data Structure :- The size of Data Structure can be expand or shrink as required during execution of program. Ex:- Linked List using pointer Classification of Data Structure based on manipulation of data Data Structure may be Primitive or Non-Primitive. • Primitive Data Structure :- Data structure using basic data type those are directly operated on data. Ex:- char ,int , float and double • Non-Primitive Data Structure : - Data structure using Derived Data type (group of data). Ex:- Array, Stack, etc.
Operation on Data Structure • Creating • Inserting • Modifying • Traversing • Searching • Deleting • Sorting • Merging • Copying • Concatenating • Splitting Abstract Data Types (ADT) An Abstract Data Type is a collection of values and a set of operations on those value. Ex:- Array, String, Stack ,Queue, etc. On String ADT we do the following operation :String Concatenation
String Length String Compare The basic idea is that the implementation of the operation is written once in the program and use that operation in other section of program to perform operation on that data type. Algorithm An algorithm is a finite sequence of instructions each of which have a clear meaning and can be executed with a finite time. An algorithm is a procedure for doing some task. An algorithm can be expressed in many kinds of notation, including natural language, pseudo code, flowchart and programming language. Properties of an Algorithm:1. Finiteness:- An algorithm must terminate after a finite number of steps. 2. Definiteness :- Each step of an algorithm must be precisely defined , the action to be carried out must be unambiguously. 3. Input : - An algorithm take zero or more number of input value. 4. Output :- An algorithm must give at least one output. 5. Effectiveness:- all the operation to be preformed in the algorithm must be sufficiently basic such that they can in principle be done exactly and in a finite length of time by a man using paper and pencil. Example:- Write an algorithm to find the largest number in a list (Natural Language.) Step 1. Assume the first item is largest. Step 2. Compare the largest item with remaining items in the list and if it is larger than the largest item so far. Step 3 The largest item in the list is display when the process is complete. Example:- Write an algorithm to find the largest number in a list (Pseudo code.) Largest Number Input: A non. Empty list of numbers L.