Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 31

SANJIVANI K. B. P.

POLYTECHNIC, KOPARGAON
With NBA ACCREDIATED programs , Approved by AICTE, New Delhi,
Recognized by Govt. of Maharashtra, Affiliated to Maharashtra State Board of Technical Education, Mumbai,
ISO 9001:2015 Certified Institute

Department:- Computer Technology Class:- CM3I

Name of Subject:- Data Structures Using 'C‘ MSBTE Subject Code:- 22317

Name of Faculty: Prof. Yogesh Annasaheb Pawar


Introduction to Data
Structures
Unit Outcome
After going through this unit, the student will be able to:

1a. Classify the given type of Data Structures based on their characteristics.

1b. Explain complexity of the given algorithm in terms of time and space.

1c. Explain the given operations to be performed on the given type of data
Data Structure: Concept
In computer science, a data structure 
• is a particular way of storing and organizing data in a computer so that it
can be used efficiently.
• is a particular way of storing and organizing information in a computer so
that it can be retrieved and used most productively.
• is about collection of data values, the relationships among them, and the
functions or operations that can be applied to the data.
• is the structural representation of logical relationships between elements
of data.
Data Structure: Concept
A data structure is made of:
• A set of data values
• A set of functions specifying the operations permitted on the data values.

• A set of axioms describing how these operations work.


For example, consider the following statements:
• Akash is 17 years old.
• Akash is in the SYIF Class.
• Akash got 85 marks in Programming in 'C'.

Let ‘name’, ‘age’, ‘class’, ‘marks’ and ‘subject’ be some defined variables. Now, let us assign a value
to each of these variables from the above statements.

• 𝑵𝒂𝒎𝒆 = 𝑨𝒌𝒂𝒔𝒉
• 𝑪𝒍𝒂𝒔𝒔 = 𝑺𝒀𝑰𝑭
• 𝑨𝒈𝒆 = 𝟏𝟕
• 𝑴𝒂𝒓𝒌𝒔 = 𝟖𝟓
• 𝑺𝒖𝒃𝒋𝒆𝒄𝒕 = 𝑷𝒓𝒐𝒈𝒓𝒂𝒎𝒎𝒊𝒏𝒈 𝒊𝒏 ′𝑪′

Fig 1.1: Relation between data and information


Need of Data Structure
• Goal: To Organise data
• Criteria: To facilitate efficient
• Storage of data
• Retrieval of data
• Manipulation of data
• Design Issue:
• Select and design appropriate data types
Why Data Structure?
1. Data Search:
If data is not organized then it will be very difficult to search an element each time, which
will create a complexity.
2. Process Speed:
Large data processing takes time, so if we know what to find and where to find make the
process fast.
3. Multiple Request:
As the database is used to store data and provide information as required by different users
at the same time. So to handle these requests organization of data and request prioritization
is required.
4. Efficiency:
Data structure increases the efficiency by providing the data in the correct format and in a
quicker way.
Abstract Data Type
• Abstract data types (often written ADT for short) are data types whose
implementation details are hidden from user view for the data
structure.
• The abstract datatype is special kind of datatype, whose
behaviour is defined by a set of values and set of operations.
• The ADT is made of with primitive datatypes, but operation
logics are hidden.
• Some examples of ADT are Stack, Queue, List etc.
Types of Data Structure
• Data structures are divided into two types the Primitive and Non-
primitive data structures.
• Data Structure further classified into two categories :
• Linear Data Structure
• Non Linear Data Structure
Types of Data Structures
Linear Data Structures:
• The data structure where data items are organized sequentially or
linearly where data elements attached one after another is called linear
data structure.
• Data elements in a liner data structure are traversed one after the other
and only one element can be directly reached while traversing.
• All the data items in linear data structure can be traversed in single run.
• These kind of data structures are very easy to implement because
memory of computer is also organized in linear fashion.
• Examples of linear data structures are Arrays, Stack, Queue and Linked
List.
Non Linear Data Structures:
• The data structure where data items are not organized sequentially is
called non linear data structure.
• In other words, A data elements of the non linear data structure could
be connected to more than one elements to reflect a special
relationship among them.
• All the data elements in non linear data structure can not be traversed
in single run.
• Examples of non linear data structures are Trees and Graphs.
Types of Data Structures
Array

Linked List

Queue Stack
Tree
Difference Between Linear and Non Linear Data Structure

Linear Data Structure Non-Linear Data Structure

Every item is related to its previous and next item. Every item is attached with many other items.

Data is arranged in linear sequence. Data is not arranged in sequence.

Data items can be traversed in a single run. Data can not be traversed in a single run.

Examples: Array, Stack, Queue, Linked List. Examples: Tree, Graph.

Implementation is Easy. Implementation is Difficult.


Algorithms
• An algorithm is a well defined list of steps for solving a particular
problem.
• There may be more than one algorithm to solve a particular problem.
Algorithm Complexity
• The complexity of an algorithm is the function which gives the
running time and/ or space in term of input size.
• In simple words, the complexity of an algorithm refers to how fast
or slow a particular algorithm performs.
• We define complexity as a numerical function T(n) - time versus the
input size n.
Algorithm Complexity
The efficiency of an algorithm depends on the following factors:
• Accuracy of the output
• Robustness of the algorithm
• User-friendliness of the algorithm
• The time required to run the algorithm
• Space required to run the algorithm
• Reliability of the algorithm
• Extensibility of the algorithm
Algorithm Complexity
• Algorithm complexity is a measure which evaluates the order of
the count of operations, performed by a given or algorithm as a
function of the size of the input data.
• Algorithm complexity is a rough approximation of the number of
steps necessary to execute an algorithm.
Algorithm Complexity
Complexity analysis broadly categorized in two classes
• Time complexity of an algorithm computes the amount of time taken
by an algorithm to run as a function of the length of the input.
• Space complexity of an algorithm computes the amount of space or
memory taken by an algorithm to run as a function of the length of
the input.
Time Complexity:
• Time complexity of an algorithm is the amount of computer time it
needs to run the program until completion.
• To measure the time complexity in absolute time unit has the
following problems
1. The time required for an algorithm depends on the number of instructions
executed by the algorithm.
2. The execution time of an instruction depends on the computer's power.
Since different computers take a different amount of time for the same
instruction.
3. Different types of instructions take a different amount of time on the same
computer.
Time Complexity:
Ex: Consider the following algorithm to add two numbers
 

Here, algorithm has only two simple statements so the complexity of this algorithm is 2
Time Complexity:
Ex: Consider another algorithm to add n even numbers
 
Time Complexity:
Here,
Step 1, Step 2 and Step 7 are the simple statements and they will
execute only once.
Step 3 is a loop statement and it will execute as many times the loop
condition is true and once more time for check the condition is false.
Step 5 and Step 6 are inside the loop so it will run as much as the loop
condition is true
Step 6 just indicates the end of a while statement and no cost
associated with it.
Time Complexity:
Statement Cost Frequency Total cost
1 1 1
1 1 1
1
1 n n
1 n n
0 1 0
1 1 1
Total Cost    
Space Complexity:
• Space complexity of an algorithm is the amount of main memory needed
to run the program until completion.
• To measure the space complexity in absolute memory unit has the
following problems
1. The space required for an algorithm depends on the space required by the
machine during execution, they are:
i. Program space
ii. Data space.
2. The program space is fixed and it is used to store the temporary data, object
code, etc.
3. The data space is used to store the different variables, data structures defined
in the program.
Space Complexity:
Ex: Consider the following algorithms for exchange two numbers:
 
 The first algorithm uses three variables and
and the second one take only two variables, so
if we look from the space complexity
perspective the second algorithm is better than
  the first one.
Asymptotic Notation
• Asymptotic Notations are the expressions that are used to represent
the complexity of an algorithm.
Asymptotic Notation
There are three types of analysis that we perform on a particular algorithm.
• Best Case: Minimum time required for program execution. Best Case is the
performance of an algorithm for the input, for which the algorithm takes less time or
space.
• Worst Case: Maximum time required for program execution. Worst case is the
performance of an algorithm for the input, for which the algorithm takes a long time
or space.
• Average Case: Average time required for program execution. Average Case is the
performance of an algorithm for the input, for which the algorithm takes time or
space that lies between best and worst case.
Asymptotic Notation
Types of Data Structure Asymptotic Notation
• Big-O Notation (Ο): Big O notation specifically describes the worst-case
scenario.
• Omega Notation (Ω): Omega (Ω) notation specifically describes the best-
case scenario.
• Theta Notation (θ): This notation represents the average complexity of an
algorithm.
Operations on Data Structure
The data in data structures are processed by certain operations:
• Traversing: print all the array elements one by one.
• Searching: Searches an element using the given index or by the value.
• Insertion: Adds an element at the given index.
• Deletion: Deletes an element at the given index.
• Sorting: process of ordering or placing a list of elements from a
collection in some kind of order.

You might also like