Unit 1 Introduction To Data Structures
Unit 1 Introduction To Data Structures
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
Name of Subject:- Data Structures Using 'C‘ MSBTE Subject Code:- 22317
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.
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.
• 𝑵𝒂𝒎𝒆 = 𝑨𝒌𝒂𝒔𝒉
• 𝑪𝒍𝒂𝒔𝒔 = 𝑺𝒀𝑰𝑭
• 𝑨𝒈𝒆 = 𝟏𝟕
• 𝑴𝒂𝒓𝒌𝒔 = 𝟖𝟓
• 𝑺𝒖𝒃𝒋𝒆𝒄𝒕 = 𝑷𝒓𝒐𝒈𝒓𝒂𝒎𝒎𝒊𝒏𝒈 𝒊𝒏 ′𝑪′
Linked List
Queue Stack
Tree
Difference Between Linear and Non Linear Data Structure
Every item is related to its previous and next item. Every item is attached with many other items.
Data items can be traversed in a single run. Data can not be traversed in a single run.
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.