DS Unit-1
DS Unit-1
INTRODUCTION TO DATA
STRUCTURES
• Data structures act as the fundamental foundations of all computer software
processes.
• Data Structure is a way of organizing all data items that considers not only the
elements stored but also their relationship to each other.
• The study of Data Structures in C deals with the study of how the data is
organized in the memory, how efficiently the data can be retrieved from the
memory, how the data is manipulated in the memory and the possible ways in
which different data items are logically related.
DATA STRUCTURE MAINLY SPECIFIES THE
FOLLOWING FOUR THINGS
• Organization of Data
• Accessing methods
• Degree of associability
• Processing alternatives for information
ELEMENTARY DATA ORGANIZATION
• Data type is a classification identifying one of various types of data, such as floating-
point, integer, or Boolean, that determines the possible values for that type; the
operations that can be done on values of that type; and the way values of that type can be
stored. It is of two types: Primitive and non-primitive data type. Primitive data type is
the basic data type that is provided by the programming language with built-in support.
This data type is native to the language and is supported by machine directly while non-
primitive data type is derived from primitive data type. For example- array, structure etc.
3.Variable
• It is a symbolic name given to some known or unknown quantity or information, for the
purpose of allowing the name to be used independently of the information it represents.
A variable name in computer source code is usually associated with a data storage
location and thus also its contents and these may change during the course of program
execution.
4. Record
• Collection of related data items is known as record. The elements of records are
usually called fields or members. Records are distinguished from arrays by the fact
that their number of fields is typically fixed, each field has a name, and that each
field may have a different type.
5. Program
• A sequence of instructions that a computer can interpret and execute is termed as
program.
6. Entity
• An entity is something that has certain attributes or properties which may be
assigned some values. The values themselves may be either numeric or non-
numeric.
7. Entity Set
• An entity set is a group of or set of similar entities. For example, employees of an organization, students
of a class etc. Each attribute of an entity set has a range of values, the set of all possible values that could
be assigned to the particular attribute. The term “information” is sometimes used for data with given
attributes, of, in other words meaningful or processed data.
8. Field
• A field is a single elementary unit of information representing an attribute of an entity, a record is the
collection of field values of a given entity and a file is the collection of records of the entities in a given
entity set.
9. File
• File is a collection of records of the entities in a given entity set. For example, file containing records of
students of a particular class.
10. Key
• A key is one or more field(s) in a record that take(s) unique values and can be used to distinguish one
record from the others.
Eg:-
Entity : Employee
Attribute : Name , Age phone
Values : "ABC", 42, 9847092568
Entity set : All employees in an organization.
ABSTRACT DATA TYPE (ADT)
• Abstract Data type (ADT) is a type (or class) for objects whose behaviour is
defined by a set of value and a set of operations.
• The definition of ADT only mentions what operations are to be performed but
not how these operations will be implemented. It does not specify how data will
be organized in memory and what algorithms will be used for implementing the
operations.
• It is called “abstract” because it gives an implementation independent view. The
process of providing only the essentials and hiding the details is known as
abstraction.
ALGORITHMS
In
4. FINITENESS: If we trace out the instruction of an algorithm, then for all cases, the
5. EFFECTIVENESS: Every instruction must be very basic so that it can be carried out,
in
principal, by a person using only pencil and paper. It is not enough that each operation
positive integer.
• Algorithm is independent of programming, so the user need not know the syntax of
• Easy and efficient coding as it acts as a blue print during a program development.
DISADVANTAGES:-
3) Iterational: In this a task (one or more steps) is repeated more than once.
Read radius
Area=3.142*radius*radius
Stop
ASYMPTOTIC NOTATIONS
• Ω Notation
• θ Notation
BIG OH NOTATION, Ο
OMEGA NOTATION, Ω
THETA NOTATION, Θ
CLASSIFICATION OF DATA
STRUCTURES
PRIMITIVE DATA STRUCTURE
• Data at their most primitive level with in a computer is primitive data structure.
• Primitive data structure are the most basic & simple which are directly operated upon by
machine level instructions.
• The storage structure of these data structures vary from one machine to another.
• These data types consists of characters that cannot be divided and hence they also called
simple data types.
• Basic data types such as integer, real, character and Boolean are known as Primitive data
structures
integer values. When an integer type is used we can store only one numeric value at a
• REAL: it is also a simple type data like integer, but here we can store fractional values
or real values.
• CHARACTER: it is of type non-numeric simple type data which can store only one
character at a time.
• BOOLEAN: This is a logical simple type data which can take 2 possible values, true
or false.
which stores the address of the other data items or the address of the memory location.
• Ex: ‘P’ is a pointer to an integer which means P contains the address of memory
objects. Here we can derive linear relationships between the elements because elements are
2. LINKED LIST: A linked list or one way list is a linear collection of data elements, called
3. The second part contains the address of the next node (link /next pointer field) in the list.
There is a special pointer Start/List contains the address of first node in the list. If this
special pointer contains null, means that List is empty. Example:
3. QUEUES: A queue, also called FIFO system, is a linear list in which
deletions can take place only at one end of the list, the Front of the list
and insertion can take place only at the other end Rear.
4. STACKS: It is an ordered group of homogeneous items of elements.
Elements are added to and removed from the top of the stack (the most
recently added items are at the top of the stack). The last element to be
flights only between the cities connected by lines. This data structure is
called Graph.
6. TREES: Tree Data frequently contain a hierarchical
relationship between various elements. The data structure
which reflects this relationship is called a rooted tree graph
or, simply, a tree.
OPERATIONS ON NON-PRIMITIVE
DS
• TRAVERSAL: Accessing / processing each element of linear list exactly once.
• SEARCHING :Find the location of Item / element with given key value.
• Here we can derive linear relationships between the elements because elements are arranged
one after the other.
• The number of elements that can be stored in an array, that is the size of array or its length is
given by the following equation: (Upperbound-lowerbound)+1
• For the above array it would be (9-0)+1=10,where 0 is the lower bound of array and 9 is the
upper bound of array.
• for(i=0;i<=9;i++) {
scanf(“%d”,&arr[i]);
printf(“%d”,arr[i]);
}
TYPES OF ARRAY
• Single Dimension Array (Array with one subscript)
• Two Dimension Array (Array with two subscripts (Rows
and Column))
• Multi Dimension Array (Array with Multiple subscripts)
1. ONE-DIMENSIONAL ARRAY: An array with only one row or column is called
one-dimensional array.
Where,
Data type : Type of value it can store (Example: int, char, float)
Size : The maximum number of elements that the array can hold.
REPRESENT LINEAR ARRAY IN
MEMORY
• Value: The value of the non-zero element is located at the index (row,
column).
Why to use Sparse Matrix instead of
simple matrix ?
• Storage: There are lesser non-zero elements than
zeros and thus lesser memory can be used to store
only those elements.
• Computing time: Computing time can be saved by
logically designing a data structure traversing only
non-zero elements..
ADVANTAGES OF ARRAYS
array.