0% found this document useful (0 votes)
5 views

Unit I

Uploaded by

bobateaditya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Unit I

Uploaded by

bobateaditya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Unit - I Introduction to Data Structures

1.1Introduction: Concept and Need of Data Structure, Definition, Abstract


Data Type
Data Structure is a particular way of storing and organizing data in the memory of
the computer so that these data can easily be retrieved and efficiently utilized in the future
when required. The data structure name indicates itself that organizing the data in memory.
There are many ways of organizing the data in the memory as we have already seen one of
the data structures, i.e., array in C language. Array is a collection of memory elements in
which data is stored sequentially, i.e., one after another. In other words, we can say that array
stores the elements in a continuous manner. This organization of data is done with the help of
an array of data structures. There are also other ways to organize the data in memory.
The data structure is not any programming language like C, C++, java, etc. It is a
set of algorithms that we can use in any programming language to structure the data in the
memory. To structure the data in memory, 'n' number of algorithms were proposed, and all
these algorithms are known as Abstract data types. These abstract data types are the set of
rules.

A data structure is a way of organizing the data so that it can be used efficiently.
Here, we have used the word efficiently, which in terms of both the space and time. For
example, a stack is an ADT (Abstract data type) which uses either arrays or linked list data
structure for the implementation. Therefore, we conclude that we require some data structure
to implement a particular ADT.

An ADT tells what is to be done and data structure tells how it is to be done. In
other words, we can say that ADT gives us the blueprint while data structure provides the
implementation part. Now the question arises: how can one get to know which data structure
to be used for a particular ADT?

As the different data structures can be implemented in a particular ADT, but the
different implementations are compared for time and space. For example, the Stack ADT can
be implemented by both Arrays and linked list. Suppose the array is providing time efficiency
while the linked list is providing space efficiency, so the one which is the best suited for the
current user's requirements will be selected.

Understanding the Need for Data Structures

As applications are becoming more complex and the amount of data is


increasing every day, which may lead to problems with data searching, processing speed,
multiple requests handling, and many more. Data Structures support different methods to
organize, manage, and store data efficiently. With the help of Data Structures, we can easily
traverse the data items. Data Structures provide Efficiency, Reusability, and Abstraction.
Why should we learn Data Structures?

1. It gives different level of organization of data.


2. It provide fast searching and sorting of data.
3. It tells how data can be stored and accessed in its elementary level.
4. We will be able to write code that is more effective and reliable.
5. We will also be able to solve problems more quickly and efficiently.

1.2Types of Data Structures: (i) Linear Data Structures (ii) Non-Linear


Data Structures

We can classify Data Structures into two categories:

1. Primitive Data Structure : Primitive Data Structures are the data structures
consisting of the numbers and the characters that come in-built into programs.

2.Non-Primitive Data Structure: Non-Primitive Data Structures are those data


structures derived from Primitive Data Structures.

Linear Data Structures

A data structure that preserves a linear connection among its data elements is known
as a Linear Data Structure. The arrangement of the data is done linearly, where each
element consists of the successors and predecessors except the first and the last data
element. However, it is not necessarily true in the case of memory, as the arrangement
may not be sequential.
Non-Linear Data Structures

Non-Linear Data Structures are data structures where the data elements are not arranged in
sequential order. Here, the insertion and removal of data are not feasible in a linear manner.
There exists a hierarchical relationship between the individual data items.

1.3Operations on Data Structures: (i) Traversing (ii) Insertion (iii) Deletion

Basic Operations of Data Structures

In the following section, we will discuss the different types of operations that we can perform
to manipulate data in every data structure:

1. Traversal: Traversing a data structure means accessing each data element exactly
once so it can be administered. For example, traversing is required while printing the
names of all the employees in a department.
2. Search: Search is another data structure operation which means to find the location of
one or more data elements that meet certain constraints. Such a data element may or
may not be present in the given set of data elements. For example, we can use the
search operation to find the names of all the employees who have the experience of
more than 5 years.
3. Insertion: Insertion means inserting or adding new data elements to the collection.
For example, we can use the insertion operation to add the details of a new employee
the company has recently hired.
4. Deletion: Deletion means to remove or delete a specific data element from the given
list of data elements. For example, we can use the deleting operation to delete the
name of an employee who has left the job.
5. Sorting: Sorting means to arrange the data elements in either Ascending or
Descending order depending on the type of application. For example, we can use the
sorting operation to arrange the names of employees in a department in alphabetical
order or estimate the top three performers of the month by arranging the performance
of the employees in descending order and extracting the details of the top three.
6. Merge: Merge means to combine data elements of two sorted lists in order to form a
single list of sorted data elements.
7. Create: Create is an operation used to reserve memory for the data elements of the
program. We can perform this operation using a declaration statement. The creation of
data structure can take place either during the following:
a. Compile-time
b. Run Time
For example, the malloc() function is used in C Language to create data structure.

8. Selection: Selection means selecting a particular data from the available data. We can
select any particular data by specifying conditions inside the loop.
9. Update: The Update operation allows us to update or modify the data in the data
structure. We can also update any particular data by specifying some conditions inside
the loop, like the Selection operation.
10. Splitting: The Splitting operation allows us to divide data into various subparts
decreasing the overall process completion time.

Applications of Data Structures & Algorithms (DSA)

From the data structure point of view, following are some important categories of algorithms

 Search − Algorithm to search an item in a data structure.


 Sort − Algorithm to sort items in a certain order.
 Insert − Algorithm to insert item in a data structure.
 Update − Algorithm to update an existing item in a data structure.
 Delete − Algorithm to delete an existing item from a data structure.
Algorithm Complexity

The performance of the algorithm can be measured in two factors:

o Time complexity: The time complexity of an algorithm is the amount of time


required to complete the execution. The time complexity of an algorithm is denoted
by the big O notation. Here, big O notation is the asymptotic notation to represent the
time complexity. The time complexity is mainly calculated by counting the number of
steps to finish the execution. Let's understand the time complexity through an
example.

1. sum=0;
2. // Suppose we have to calculate the sum of n numbers.
3. for i=1 to n
4. sum=sum+i;
5. // when the loop ends then sum holds the sum of the n numbers
6. return sum;

In the above code, the time complexity of the loop statement will be atleast n, and if the value
of n increases, then the time complexity also increases. While the complexity of the code, i.e.,
return sum will be constant as its value is not dependent on the value of n and will provide
the result in one step only. We generally consider the worst-time complexity as it is the
maximum time taken for any given input size.

o Space complexity: An algorithm's space complexity is the amount of space required


to solve a problem and produce an output. Similar to the time complexity, space
complexity is also expressed in big O notation.

For an algorithm, the space is required for the following purposes:

1. To store program instructions


2. To store constant values
3. To store variable values
4. To track the function calls, jumping statements, etc.

Auxiliary space: The extra space required by the algorithm, excluding the input size, is
known as an auxiliary space. The space complexity considers both the spaces, i.e., auxiliary
space, and space used by the input.

So,

Space complexity = Auxiliary space + Input size.

You might also like