3. Unit Outcomes
• Classify different types of data structures based on their characteristics
• Explain complexity of an algorithm in terms of time & space.
• Explain the given operations to be performed on the given type of data
structure.
4. What will we Learn
• Concept & Need of DS, Abstract Data Types
• Types of Data Structure
• Algorithm Complexity
• Operations on Data Structure
5. Concept of Data Structure
• Data : Collection of raw facts.
• Data structure is a special way of organizing and storing data in a computer
so that it can be used efficiently.
• Data Structures is about interpretation data elements in terms of some
relationship, for better organization and storage. For example, we have
some data which has, player's name “Sachin" and age 26. Here “Sachin" is
of String data type and 26 is of integer data type.
• We can organize this data as a record like Player record, which will have
both player's name and age. Now we can store player's records in a file or
database as a data structure. For example: "Dhoni" 30, "Gambhir" 31,
"Sachin" 33
6. Concept of Data Structure
• We can define Data Structure as a set of triplet i.e. D = (D,F,A)
Where
D - Set of Domain (set of data objects)
F - Set of Functions(set of operations performed on data objects)
A - Set of Axioms (set of rules to implement the functions)
• Example :- consider an example of integer data type
D = (0, +/- 1 , +/- 2, …….. )
F = (+,-,*,/)
A = a set of binary arithmetic rules to perform addition, subtraction,
division, multiplication and module operations.
7. Need of Data Structure
• As applications are getting completed and amount of data is increasing day by day, there
may arise the following problems:
1. Processor speed: To handle very large amout of data, high speed processing is required,
but as the data is growing day by day to the billions of files per entity, processor may fail
to deal with that much amount of data.
2. Data Search: Consider an inventory size of 106 items in a store, If our application needs
to search for a particular item, it needs to traverse 106 items every time, results in
slowing down the search process.
3. Multiple requests: If thousands of users are searching the data simultaneously on a web
server, then there are the chances that a very large server can be failed during that
process
in order to solve the above problems, data structures are used.
8. Need of Data Structure
1. Data structures are important way of organizing data in a
computer
2. It has a different way of storing and organizing data so that it can
be used efficiently.
3. It helps us to understand relationship of one data element with
other
4. It helps to store a data in logical order.
5. It stores a data that may grow and shrink dynamically over a time
and allows efficient access.
9. Abstract Data Type
• Abstract Data Type is defined as a mathematical model of data objects that
make up a data type as well as the functions that operate on these objects.
• ADT is the way we look at data structure focusing on what it does and
ignoring how it does it job.
• In ADT only behavior is defined and not implementation.
• Example :- Array,List,Map,set,Stack,Queue,table,Tree,graph etc.
• Real life example:
Book is Abstract (Telephone Book is an implementation)
11. Primitive Data Structure
The primitive data structures are the basic data types that are available in most
of the programming languages.
The primitive data structures are used to represent single values.
Example: Integer, character, string, Boolean
12. Non-Primitive Data Structure
The data structure that are derived from primary data
structure is known as non-Primitive data structure.
These data types are used to store group of values.
Example: Arrays, Structure, Union, linked list, Stacks, Queue
etc.
13. Linear Data Structure
In linear data structure the elements are stored in sequential order. The linear data structures
are
Array: Array is a collection of data of same data type stored in consecutive memory
location and is referred by common name
Linked list: Linked list is a collection of data of same data type but the data items
need not be stored in consecutive memory locations.
Stack: A stack is a Last-In-First-Out linear data structure in which insertion and
deletion takes place at only one end called the top of the stack.
Queue: A Queue is a First in First-Out Linear data structure in which insertions takes
place one end called the rear and the deletions takes place at one end called the
Front.
14. Non-Linear Data Structure
Elements are stored based on the hierarchical relationship among the data. The
following are some of the Non-Linear data structure
Trees:
• Trees are used to represent data that has some hierarchical
relationship among the data elements.
Graph:
• Graph is used to represent data that has relationship between
pair of elements not necessarily hierarchical in nature. For
example electrical and communication networks, airline routes,
flow chart, graphs for planning projects
15. Algorithm Complexity
• Algorithm is a step-by-step procedure, which defines a set of instructions to be
executed in a certain order to get the desired output.
• Suppose,
X is an algorithm
n is the size of input data
• Then the time and space used by the algorithm X are the two main factors,
which decide the efficiency of X.
1. Time Factor − Time is measured by counting the number of key
operations such as comparisons in the sorting algorithm.
2. Space Factor − Space is measured by counting the maximum memory
space required by the algorithm.
• The complexity of an algorithm f(n) gives the running time and/or the storage
space required by the algorithm in terms of n as the size of input data
16. Space Complexity
• Space complexity of an algorithm represents the amount of memory space
required by the algorithm in its life cycle.
• The space required by an algorithm is equal to the sum of the following two
components −
1. A fixed part that is a space required to store certain data and
variables, that are independent of the size of the problem.
Example: simple variables and constants used, program size, etc.
2. A variable part is a space required by variables, whose size
depends on the size of the problem.
Example, dynamic memory allocation, recursion stack space, etc.
17. Space Complexity
• Space complexity S(P) of any algorithm P is written as
S(P) = C + SP(I)
where
C- the fixed part
SP(I) - the variable part of the algorithm, which depends on instance characteristic I.
• Example
Algorithm: Sum(A,B)
Step 1 : start
Step 2 : c= A + B + 10
Step 3 : stop
• Here we have three variables A, B, and C and one constant. Hence S(P) = 1 + 3. Now, space
depends on data types of given variables and constant types and it will be multiplied
accordingly.
.
18. Time Complexity
• Time complexity of an algorithm represents the amount of time required by
the algorithm to run to completion.
• Time requirements can be defined as a numerical function T(n), where T(n) can
be measured as the number of steps, provided each step consumes constant
time.
• Example
• addition of two n-bit integers takes n steps. Consequently, the total
computational time is T(n) = c ∗ n, where c is the time taken for the addition of
two bits. Here, we observe that T(n) grows linearly as the input size increases.
19. Operations on Data Structure
• Traversing - Visiting each element of the data structure in order to perform
some specific operation like searching or sorting.
• Insertion - Adding the elements to the data structure at any location.
• Deletion - removing an element from the data structure.
• Searching - finding the location of an element within the data structure.
• Sorting - arranging the data structure in a specific order.
• Merging – Merging of two list to get single list.