This document introduces data structures and their implementation. It discusses data objects and data structures, classification of data structures, implementation of data structures using arrays and linked lists, abstract data types, algorithms, pseudocode, and complexity analysis. Primitive data structures like integers can be directly manipulated by machine instructions while non-primitive structures like arrays and linked lists require indirect representation. Common linear structures are stacks, queues, and linked lists, while trees and graphs are non-linear. Implementation involves mapping conceptual structures to programming language constructs.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
18 views
Intro To Data STR
This document introduces data structures and their implementation. It discusses data objects and data structures, classification of data structures, implementation of data structures using arrays and linked lists, abstract data types, algorithms, pseudocode, and complexity analysis. Primitive data structures like integers can be directly manipulated by machine instructions while non-primitive structures like arrays and linked lists require indirect representation. Common linear structures are stacks, queues, and linked lists, while trees and graphs are non-linear. Implementation involves mapping conceptual structures to programming language constructs.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5
Session 2
Introduction to Data structures
During this session you will learn about:
Data objects and Data structures.
Classification of data structures. Implementation of data structures. Abstract data type. Algorithm and pseudo codes. Complexity of algorithm.
2.1. Introduction
Data structures, is one of the most important subject,
which is required by all the software programmers. As a programmer, we would be handling the data in huge quantity. The data we are given, requires to be stored in the memory. The memory should be used efficiently.
The data will be handled on the basis of its type. It
could be an integer, real, character etc. There could be even the combination of the data, result in some new type, like structures, unions etc which were covered in the previous session.
2.2. Data Objects & Data Structures
DATA OBJECT is a set of elements, say D. This D may or
may not be finite, for example, when data object is set of real numbers is infinite and when it is a set of numeric digits it is finite.
DATA STRUCTURE contains the data object along with the
set of operations, which will be performed on them, or data structure contains the information about the manner in which these data objects are related. The data structures deal with the study of how data is organized in the memory, how efficiently it can be retrieved and manipulated.
They can be classified into
- Primitive Data structures. - Non Primitive Data structures.
Data Structures with ‘c’ 23
2.3. Primitive Data structures
These are the data structures that can be manipulated
directly by machine instructions. The integer, real, character etc., are some of primitive data structures. In C, the different primitive data structures are int, float, char and double.
2.4. Non Primitive Data structures
These data structures cannot be manipulated directly by
machine instructions. Arrays, linked lists, trees etc., are some non-primitive data structures. These data structures can be further classified into ‘linear’ and ‘non-linear’ data structures.
The data structures that show the relationship of logical
adjacency between the elements are called linear data structures. Otherwise they are called non-linear data structures.
Different linear data structures are stack, queue, linear
linked lists such as singly linked list, doubly linked list etc. Trees, graphs etc are non-linear data structures.
2.5. Implementation of the Data Structures
When we define the data structure, we also give the
functions or the rules used for handling of the data and its logical and/or physical relation. This can be considered as conceptual handling of data for effective working. But very often we face limitations of a particular language or by the available data i.e. its type and size. When these come into picture along with the defined data structure, we may chose some other available form for handling the data along with all the restrictions imposed on it.
Consider the common example of the QUEUE. It will be
every day experience that whenever we are in queue – we follow all the rules of the queue. We are aware that the first person in the queue will be the first one to leave it. We will not allow anyone to enter the queue in between the first and the
Data Structures with ‘c’ 24
last person. You cannot leave the queue and cannot search for someone.
When we think of processing the data the very first thing
that comes to our mind is that, we should process the data in same sequence in which it arrives and hence for storing the data we define the data structure called QUEUE.
The rules to be followed by the queue are :
1. The data can be removed from one end, called as the
front. 2. The new data should be always added at the other end called rear. 3. It is possible that there is no data in the queue, which indicates queue empty condition. 4. It is possible that there is no space in the queue for data to be stored which indicates queue full condition.
Now if we think of actually using the concept in our
program then it is necessary to store these data items. We should remember which is the first and which is the last data item. If we use different variable names for each item they will not look as if they are related.
The only method to store related items, which we all know
by this time, is using an Array. The array can be used to implement queue.
In case of arrays, deletion and addition can be made at
any position. For queues, we have to impose some restrictions. We will have to remember two positions indicating the first and the last positions of the queue. Whenever an item is removed the first position will change to its next.
If our first position is beyond the last, the queue will
not contain any data items. The deletion of an element from the queue will be logical deletion. If we observe the array, then all the elements are physically available all the time.
The same data structure can also be implemented by
another data structure known as LINKED LIST. In short we say that implementing data structure d1 using another data structure d2, is mapping from d1 to d2.
Data Structures with ‘c’ 25
2.6. Abstract Data type
A data structure is a set of domains , a designated
domain P, a set of functions and set of axioms . A triplet (,,) denotes the data structure d.
The triplet is referred to as abstract data type (ADT).
It is abstract because the axioms in the triple do not give any idea about the representation. Defining the data structure is a continuous process because at the initial stage we can design a data structure, and also we indicate as what it should do. In the later stages of the refinement we try to find the ways in which it can be done or how it can be achieved. Thus it is the total process of specification and implementation.
The idea for representing of data, relation in the data
objects and the tasks to be performed will be the specification of the data structure. When we actually try to use all the concepts then we decide as how to achieve each goal, which set by each function. This will be the implementation phase.
2.7. Algorithm and pseudo code
Whenever we need to solve a problem it is a better
approach to first write down the solution in algorithm or pseudo codes. Once the logic and data structures to be used are decided we can write algorithm or a pseudo code. Later we can implement them into a program of a particular language.
Algorithm is a set by step solution to a problem written
in English alone or with some programming language constructs.
Pseudo code is algorithm written in a particular
programming language that will be used to implement the algorithm.
2.8. Complexity of Algorithms
When a program is written, it is evaluated on many
criteria, like satisfactory results, minimum code, optimum logic etc. The complexity of the algorithm, which is used, will depend on the number of statements executed. Though the execution for each statement is different, we can roughly check as how many times each statement is executed. Whenever we execute a conditional statement, we will be skipping some
Data Structures with ‘c’ 26
statements or we might repeat some statements. Hence the total number of statements executed will depend on conditional statements.
At this stage we can roughly estimate that the complexity
is the number of times the condition is executed.
e.g.
for(i=0; i<n; i++)
{ printf(“%d”,i);}
The output is from 0 to n-1. We can easily say that it
has been executed n times. The condition which is checked here is i<n. It is executed n+1 times - n times when it is true and once when it is false. Hence the total number of statements executes is 2n+1. Also the statement i=0 is executed once and i++ is executed n times.
The total = 1+(n+!)+(n)+(n) = 3n + 2
If we ignore the constants, we say that the complexity is
of the order of n. The notation used is big-O. i.e. O(n).
Exercises :
Find the number of times for which each statement is executed.
1. i=2;
while( i < n) { for( i = 0; i < n; i++) { k=k+j; } i=i+2; }
2. for( i =0; i<n; i++)
{ for(j=0; j<i; j++) { printf(“ Enter the num “); scanf(“%f”,&p[i][j];)’ } }