You are on page 1of 20

INTRODUCTION TO

DATA
STRUCTURES AND
ALGORITHM
INTRODUCTION
DATA STRUCTURES

• Data structures is a way of collecting and organizing data in such a way that we can perform
operations on these data in an effective way. Data structure is about rendering data elements in terms
of some relationship, for better organization and storage.
•A data structure is a particular way of organising data in a computer so that it can be used effectively.
The idea is to reduce the space and time complexities of different tasks.

•Data structures are structures programmed to store ordered data, so that various operations can be
performed on it easily. It presents the knowledge of data to be organized in memory.

•It should be designed and implemented in such a way that it reduces the complexity and increases the
efficiency.
CHARACTERISTICS OF A DATA STRUCTURE

• Correctness - This property is related to the algorithm of data structures. It's important that the
algorithm is correct. Correctness here means that the algorithm always produces the expected output or
follows the ground truth for the range of valid inputs, and eventually, it terminates. It is important
because you're relying on it for the desired output.
• Time Complexity – The time your algorithm use to execute should be as small as possible because
the more time your data structure takes, it will decrease its efficiency.
• Space Complexity – This is the total memory space your data structure needs for its execution. It
should be as small as possible for data structures because it's one of the important factors in efficiency.
NEED OF A DATA STRUCTURE

As applications are getting complex and data rich, there are three common problems that applications face now-a-
days.
• Data Search – Consider an inventory of 2 million items of a store. If the application is to search an item, it has to
search an item in 2 million items ever time slowing down the search. As data grows, search will become slower.

• Processor Speed – Processor speed although being very high, falls limited if the data grows to billion records.

• Multiple Request – as thousands of users can search data simultaneously on a web server, even the fast server
fails while searching the data.

To solve the above-mentioned problems, data structures come to rescue. Data can be organized in a data structure in
such a way that all items may not be required to be searched, and the required data can be searched almost instantly.
WHAT IS AN ALGORITHM?

• An algorithm is a steps-by-step procedures in performing a specific task or solving a problem.

• Algorithm is a step-by-step procedure, which defines a set f instructions to be executed in a certain order to get the desired output.
Algorithms are generally created independent of underlying languages, i.e. An algorithm can be implemented in more than one
programming language.
• In computer programming terms, an algorithm is a set of well-defined instructions to solve a particular problem. It takes a set of input(s)
and produces the desired output.

For example;

An algorithm to add two numbers:

- Take two number inputs

- Add numbers using the + operator

- Display the results


QUALITIES OF A GOOD ALGORITHM

• Input and output should be defined precisely.

• Steps in the algorithm should be clear and unambiguous.

• it should be most effective among ways to solve a problem.

• An algorithm shouldn’t include computer code. Instead,


the algorithm should be written in such a way that it can
be used in different programming languages.

Basic Flow Chart


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 an 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 .


CHARACTERISTICS OF AN ALGORITHM

Not all procedures can be called an algorithm. An algorithm should have the following characteristics.
• Unambiguous - Algorithm should be clear. Each of its steps (or phases), and their inputs/outputs should be
clear and must lead to only one meaning.
• Input – an algorithm should have 0 or more well-defined inputs

• Output – an algorithm should have 1 or more well defined outputs, and should match the desired output.

• Finiteness – algorithms must terminate after a finite number of steps.

• Feasibility – should be feasible with available resources.

• Independent – an algorithm should have step-by-step directions, which should be independent of any
programming code.
Algorithm 1: Add two numbers entered by a user

Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
sum num1+num2
Step 5: Display sum.
Step 6: Stop.
Algorithm 2: Find the largest number among three numbers.

Step 1: Start
Step 2: Declare variables a, b and c
Step 3: Read variables a, b and c.
Step 4: if a > b
if a > c
Display a is the largest number.
Else
Display c is the largest number.
Else
if b > c
Display b is the largest number
Else
Display c is the largest number
Step 5: Stop.
TYPES OF DATA STRUCTURES

Basically, data structures are divided into two categories.


• Linear Data Structure

• Non-Linear Data Structure

Linear Data Structures.


• In linear data structures, the elements are arranged in sequence one after the other. Since elements
are arranged in order, they are easy to implement.
• However, when the complexity of the program increases, the linear data structures might not be
the best choice because of operational complexities.
POPULAR LINEAR DATA STRUCTURES ARE:

1. Array Data Structure: In an array, elements in memory are arranged in continuous memory. All
the elements are of the same type. And the type of elements that can be stored in the form of arrays is
determined by the programing language.

2. Stack Data Structure: Elements are stored in the LIFO principle. This is, the last element stored in
a stack will be removed first.

3. Queue Data Structure: Unlike stack, the queue data structure works in the FIFO principle where
first element stored in the queue will be removed first.

4. Linked List Data Structure: Data elements are connected through a series of nodes. And each
node contains the data items and address to the next node.
NON-LINEAR DATA STRUCTURES

Unlike linear data structures, elements in non-linear data structures are in any sequence. Instead they
are arranged in a hierarchical manner where one element will be connected to one or more elements.

Non linear data structures are further divided into graph and tree-based data structures.

1. Graph Data Structure: In graph data structure, each node is called vertex an each vertex is
connected to other vertices through edges.

2. Trees Data Structures: like graph, a tree is also a collection of vertices and edges. However, in tree
data structure, there can only be one edge between two vertices .
LINEAR VRS NON-LINEAR DATA STRUCTURES
Linear Data Structures Non-Linear Data Structures
The items are arranged in sequential order, one after The data items are arranged in non-sequential order
the other. (hierarchical manner)
All the items are presented on a single layer The data items are presented at different layers
It can be traversed on a single run. That is, if we It require multiple runs. That is, if we start from the
start from first element, we can traverse all the first element it might not be possible to traverse all
elements sequentially in a single pass. the elements in a single pas.
The memory utilization is not efficient Different structures utilize memory in different
efficient ways depending on the need.
The time complexity increases with the data size Time complexity remains the same
Example: Arrays, Stack, Queue Example: Tree, Graph, Map
REAL WORLD APPLICATIONS OF DATA
STRUCTURES
Network Security Cryptographic Algorithms: For encrypting and decrypting data, ensuring secure
data transmission.
Hash Functions: In maintaining integrity and authenticity of data.

Operating Systems Process Scheduling: Using queues to manage processes and tasks.

Memory Management: Algorithms for efficient allocation and deallocation of memory.

 Web Development Search Engine Optimization: Algorithms to rank pages based on relevance.

Data Structures for Storing Web Data: Trees for DOM manipulation, caches.
REAL WORLD APPLICATIONS OF DATA
STRUCTURES

Software Development Use of Arrays, Linked Lists: For managing collections of elements, such as user data, files, etc.

Stacks and Queues: In undo-redo functionalities, task scheduling.

Graphs: In social networks for representing and processing connections.

Database Systems B-Trees, Hash Tables: For indexing, which allows faster retrieval of data.

SQL Query Optimization: Algorithms determine the most efficient way to execute a query.

Artificial Intelligence and Machine Learning Search Algorithms: In decision-making processes, like pathfinding
algorithms in robotics.
Data Structures for ML Models: Trees and graphs for decision trees, and neural networks.
REAL-WORLD EXAMPLES
Google's Search Algorithm: Uses complex algorithms for indexing and ranking web pages.

Facebook's Social Graph: Utilizes graph data structures to represent and manage user connections.

Cryptocurrencies: Leverage cryptographic algorithms for secure transactions.


CHALLENGES AND CONSIDERATIONS
Scalability: How data structures and algorithms perform as the size of the dataset increases.

Efficiency vs. Complexity: Balancing speed with resource consumption.

Security Implications: Ensuring algorithms protect data and privacy.


THANK YOU.

You might also like