Day 1: Data
Structures &
Algorithms
Data Structures and Algorithms & Design
Patterns
Introduction
• Data Structure 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 Structures is about rendering data elements in terms of some relationship, for better
organization and storage.
• It represents 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 Data S8s
• Correctness – Data structure implementation should implement its interface correctly
• Time Complexity - Running time or the execution time of operations of data structure
must be as small as possible.
• Space Complexity - Memory usage of a data structure operation should be as little as
possible.
Need for Data Structures
As applications scale and data volumes grow, traditional search and retrieval methods become
increasingly inefficient. This leads to three common challenges:
• Slow Search Times: As the number of data items increases, linear search becomes impractical,
leading to significant performance degradation.
• Processor Limitations: Even with powerful processors, large datasets can overwhelm processing
capabilities, resulting in slow response times.
• Scalability Issues: Handling a high volume of concurrent requests can strain server resources,
leading to degraded performance and potential system failures.
To address these challenges, efficient data structures are crucial. By organizing data in specific
ways, we can optimize search and retrieval operations, minimize processing time, and improve
overall system performance.
Algorithms
• A step-by-step procedure, which defines a set of instructions to be executed in a certain
order to get the desired output. Algorithms are generally language agnostisc.
• Input ----------> Algorithm -----------------> Output
• Example:
o Algorithm to add two numbers would typically;
▪ Take two number inputs
▪ Add numbers using the + operator
▪ Display results
Algorithms continued
From the data structure point of view, following are some important categories of algorithms
• Search
• Sort
• Insert
• Update
• Delete
Algorithm 1: Add 2 numbers
•
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 of 3
numbers
Types of Data Structures
Data structures are categorized into two;
- Linear Data Structures
- Non-linear Data Structures
Types of Data Structures
Linear data structures
• In linear data structures, the elements are arranged in sequence one after the other. Since
elements are arranged 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
Types of Data Structures
Popular linear data structures are:
• Array Data Structure
In an array, elements in memory are arranged in continuous memory. All the elements of an array are of the same type. And the type of
elements that can be stored in the form of arrays is determined by the programming language.
Types of Data Structures
Popular linear data structures are:
• Stack Data Structure
In stack data structure, elements are stored in the LIFO principle. That is, the last element stored in a stack will be removed first. It works
just like a pile of plates where the last plate kept on the pile will be removed first.
Types of Data Structures
Popular linear data structures are:
• Linked List Data Structure
In 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.
Types of Data Structures
Non-linear data structures
Unlike linear data structures, elements in non-linear data structures are not 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.
Graph Data Structure: Each node is called vertex and each vertex is connected to other vertices through
edges.
Trees Data Structures: A tree is also a collection of vertices and edges. However, in tree data structure,
here can only be one edge between two vertices.
Thank you
Questions??