[go: up one dir, main page]

0% found this document useful (0 votes)
29 views41 pages

Lesson 1: Introduction To Data Structures and Algorithms

The document provides an introduction to data structures and algorithms. It discusses key topics like common data structures, how data structures differ from data types, classification of data structures, and the importance of algorithms. It also covers algorithm analysis and different types of algorithms like sorting, searching, hashing, and divide and conquer algorithms. Understanding algorithm analysis is important to predict an algorithm's behavior and compare different solutions to determine the most efficient one.

Uploaded by

sititop130
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views41 pages

Lesson 1: Introduction To Data Structures and Algorithms

The document provides an introduction to data structures and algorithms. It discusses key topics like common data structures, how data structures differ from data types, classification of data structures, and the importance of algorithms. It also covers algorithm analysis and different types of algorithms like sorting, searching, hashing, and divide and conquer algorithms. Understanding algorithm analysis is important to predict an algorithm's behavior and compare different solutions to determine the most efficient one.

Uploaded by

sititop130
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

Data Structure and

Algorithms
Lesson 1: Introduction to Data Structures and Algorithms
Lesson 1: Introduction to Data
Structures and Algorithms

• Overview of data structures and their


importance
• Basics of algorithm analysis
Data Structures

• A storage that is used to store and organize data.


• Essential components that help organize and store
data efficiently in computer memory.
• Provide a way to manage and manipulate data
effectively, enabling faster access, insertion,
and deletion operations
Common Data Structures

1. Arrays
2. Linked lists
3. Stacks
4. Queues
5. Trees “Each serving specific purposes
6. Graphs based on the requirements of
the problem at hand.”
How Data Structure varies from Data
Type?
How Data Structure varies from Data Type?

Data Type Data Structure


The data type is the form of a Data structure is a collection of
variable to which a value can be different kinds of data. That entire
assigned. It defines that the data can be represented using an
particular variable will assign the object and can be used throughout
values of the given data type only. the program.
It can hold value but not data. It can hold multiple types of data
Therefore, it is dataless. within a single object.
The implementation of a data type Data structure implementation is
is known as abstract known as concrete
implementation. implementation.
How Data Structure varies from Data Type?

Data Type Data Structure


There is no time complexity in the In data structure objects, time
case of data types. complexity plays an important role.
While in the case of data
structures, the data and its value
In the case of data types, the value
acquire the space in the
of data is not stored because it
computer’s main memory. Also, a
only represents the type of data
data structure can hold different
that can be stored.
kinds and types of data within one
single object.
Data type examples are int, float, Data structure examples are stack,
double, etc. queue, tree, etc.
Classification of Data Structure
Classification of Data Structure
Linear Data Structure

• Data structure in which data elements are


arranged sequentially or linearly
• Each element is attached to its previous and
next adjacent elements, is called a linear
data structure.
Linear Data Structure

1. Static data structure


• Has a fixed memory size.
• It is easier to access the elements in a static data
structure. (e.g. array)
2. Dynamic data structure
• Memory size is not fixed; Can be randomly updated
during the runtime which may be considered efficient
concerning the memory (space) complexity of the code.
(e.g. data structure are queue, stack, etc.)
Non-linear Data Structure

•Data structures where data elements are


not placed sequentially or linearly.
•We can’t traverse all the elements in a
single run only.
•E.g. trees and graphs.
Importance Of Data Structure?

• Data presentation must be easy to understand so


the developer, as well as the user, can make an
efficient implementation of the operation.
• Data structures provide an easy way of organizing,
retrieving, managing, and storing data.
Basics of Algorithm Analysis
Algorithm

• A set of rules to be followed in calculations or


other problem-solving operations
• A procedure for solving a mathematical
problem in a finite number of steps that
frequently involves recursive operations
Use of the Algorithms

1. Computer Science: Algorithms form the basis of


computer programming and are used to solve
problems ranging from simple sorting and
searching to complex tasks such as artificial
intelligence and machine learning.
2. Mathematics: Algorithms are used to solve
mathematical problems, such as finding the
optimal solution to a system of linear equations or
finding the shortest path in a graph.
Use of the Algorithms

3. Operations Research: Algorithms are used to


optimize and make decisions in fields such as
transportation, logistics, and resource allocation.
4. Artificial Intelligence: Algorithms are the
foundation of artificial intelligence and machine
learning and are used to develop intelligent
systems that can perform tasks such as image
recognition, natural language processing, and
decision-making.
Use of the Algorithms

5. Data Science: Algorithms are used to analyze,


process, and extract insights from large amounts
of data in fields such as marketing, finance, and
healthcare.
What is the need for algorithms?
Importance of Algorithms

1. Necessary for solving complex problems efficiently and


effectively.
2. Help to automate processes and make them more reliable,
faster, and easier to perform.
3. Enable computers to perform tasks that would be difficult or
impossible for humans to do manually.
4. Used in various fields such as mathematics, computer
science, engineering, finance, and many others to optimize
processes, analyze data, make predictions, and provide
solutions to problems.
Characteristics of an Algorithm

1. Clear and 6. Input


Unambiguous 7. Output
2. Well-Defined Inputs 8. Definiteness
3. Well-Defined Outputs 9. Effectiveness
4. Finiteness
5. Language Independent
Properties of Algorithm

• It should terminate after a finite time.


• It should produce at least one output.
• It should take zero or more input.
• It should be deterministic means giving the same
output for the same input case.
• Every step in the algorithm must be effective i.e.
every step should do some work.
Types of Algorithms
1. Brute Force Algorithm

It is the simplest approach to a problem. A


brute force algorithm is the first approach that
comes to finding when we see a problem.
2. Recursive Algorithm

A recursive algorithm is based on recursion. In


this case, a problem is broken into several
sub-parts and called the same function again
and again.
3. Backtracking Algorithm

Builds the solution by searching among all


possible solutions.
We keep on building the solution following
criteria. Whenever a solution fails, we trace
back to the failure point build on the next
solution and continue this process till we find
the solution, or all possible solutions are
looked after.
4. Searching Algorithm

Searching algorithms are the ones that are


used for searching elements or groups of
elements from a particular data structure.
They can be of different types based on their
approach or the data structure in which the
element should be found.
5. Sorting Algorithm

Sorting is arranging a group of data in a


particular manner according to the
requirement. The algorithms which help in
performing this function are called sorting
algorithms.
Generally sorting algorithms are used to sort
groups of data in an increasing or decreasing
manner.
6. Hashing Algorithm

Hashing algorithms work similarly to the


searching algorithm. But they contain an index
with a key ID.
In hashing, a key is assigned to specific data.
7. Divide and Conquer Algorithm

This algorithm breaks a problem into sub-problems,


solves a single sub-problem, and merges the
solutions to get the final solution. It consists of the
following three steps:

• Divide
• Solve
• Combine
8. Greedy Algorithm

In this type of algorithm, the solution is built


part by part.
The solution for the next part is built based on
the immediate benefit of the next part.
The one solution that gives the most benefit
will be chosen as the solution for the next part.
9. Dynamic Programming Algorithm

This algorithm uses the concept of using the


already found solution to avoid repetitive
calculation of the same part of the problem.
It divides the problem into smaller overlapping
subproblems and solves them.
10. Randomized Algorithm

In the randomized algorithm, we use a random


number, so it gives immediate benefit.
The random number helps in deciding the
expected outcome.
Algorithm Analysis
Algorithm Analysis

An important part of computational complexity


theory, which provides theoretical estimation
for the required resources of an algorithm to
solve a specific computational problem.
The determination of the amount of time and
space resources required to execute it.
Why Analysis of Algorithms is
important?
Why Analysis of Algorithms is
important?

1. To predict the behavior of an algorithm


without implementing it on a specific
computer.
2. It is much more convenient to have simple
measures for the efficiency of an algorithm
than to implement the algorithm and test the
efficiency every time a certain parameter in
the underlying computer system changes.
Why Analysis of Algorithms is
important?

3. It is impossible to predict the exact


behavior of an algorithm. There are too
many influencing factors.
4. The analysis is thus only an
approximation; it is not perfect.
5. More importantly, by analyzing different
algorithms, we can compare them to
determine the best one for our purpose.
Types of Algorithm Analysis
Types of Algorithm Analysis

1. Best case: Define the input for which algorithm takes less time or minimum
time. In the best case, calculate the lower bound of an algorithm. Example: In
the linear search when search data is present at the first location of large data
then the best case occurs.
2. Worst Case: Define the input for which algorithm takes a long time or
maximum time. In the worst case, calculate the upper bound of an algorithm.
Example: In the linear search when search data is not present at all then the
worst case occurs.
3. Average case: In the average case take all random inputs and calculate the
computation time for all inputs. And then we divide it by the total number of
inputs. (Average case = all random case time / total no of case)
Sources

https://www.geeksforgeeks.org/data-structures/
https://www.geeksforgeeks.org/introduction-to-algorithms/
https://www.geeksforgeeks.org/what-is-algorithm-and-why-analysis-
of-it-is-important/
https://www.linkedin.com/pulse/algorithm-complexity-understanding-
time-space-devender-
singh#:~:text=The%20average%2Dcase%20time%20complexity,size
%20of%20the%20input%20data.

You might also like