Introduction to Data
Structures and
Algorithms
D. Mpini
Learning Outcomes
• Why Study Data Structures and Algorithms? • Algorithm Efficiency
• The Role of Data Structures and Algorithms in ○ Space Complexity
Computing
○ Time Complexity
• Importance Across Disciplines
• Data Taxonomy Overview
• Data Type vs. Data Structure
• Introduction to Algorithms
• Algorithm Design Example
• Categories of Algorithms
• Algorithm Characteristics
Why Study Data Structures and Algorithms?
Enhance code Improve memory Enhance job prospects by Develop critical thinking
optimization for better utilization for efficient mastering skills for complex
performance operations problem-solving problem-solving
techniques
https://www.springboard.com/blog/software-engineeri
ng/data-structures-and-algorithms-interview-questions
/
Importance Across Disciplines
Data structures and algorithms are fundamental for software engineers to
Software
write optimized and scalable code, enhancing software performance and
Engineering efficiency.
In data science, understanding data structures and algorithms is essential for
Data Science processing and analyzing large datasets efficiently, enabling the extraction of
valuable insights and patterns.
AI researchers leverage data structures and algorithms to develop intelligent
AI Research algorithms and models that can learn and make decisions autonomously,
driving advancements in artificial intelligence technologies.
Data Structures
Way of Organizing
Examples Which is best? Importance of Data
Data
Structures
Data structures organize Linked lists, queues, heaps, The choice of data Data structures enhance
and store data effectively and graphs are common structure depends on the data management,
in memory locations for data structures each with specific task at hand, retrieval, and manipulation,
easy access and unique strengths and ensuring optimal leading to improved
manipulation. implementation strategies. performance and efficiency program functionality and
in data handling. resource utilization.
Data Taxonomy Overview
Linear Data Structures Non-Linear Data Structures
These structures store data in a These structures store data in a hierarchical
sequential order allowing for easy or interconnected manner allowing for
insertion and deletion operations. more complex relationships between data
Examples include arrays, linked lists,
and queues.
elements. Examples include trees, graphs,
and hash tables.
Visualgo.net
Linear DS Dynamic Nonlinear DS Trees
Static: Array Trees, Heaps, Graphs
Dynamic: Linked lists, Stacks, Queues
Discussion Questions
Which algorithm is best for this scenario
Data Type vs. Data Structure
Data Type Data Structure
Basic classification of data used in code Collection of different forms of data with specific operations
Informs compiler about data type and memory space Organizes items in memory and provides logical access
required
Includes linked lists, queues, heaps, stacks, graphs
Examples include int, string, etc.
Algorithms
Definition Expression Methods
Algorithms are finite sequences of Algorithms are not programs; they are Algorithms can be represented in
steps to achieve a specific computing abstract solutions to problems that can
task efficiently. 1. pseudocode for clarity and in
be expressed in pseudocode and
2. flowcharts for visual
flowcharts.
understanding.
Algorithm Design Example
Design an algorithm that takes 2 arrays and return true if the arrays have no common elements in them given that initially each array did not have a
recurring element. Express your algorithm in the form of
a. Pseudocode
b. Flowchart
Categories of Algorithms
1 2 3
Searching algorithms are used to find Sorting algorithms arrange data structures Greedy algorithms aim to find the locally
specific items within a collection of based on a comparison operator. optimal solution in the hopes of achieving
items. the global optimal solution.
4 5 6
Recursive algorithms solve problems by Backtracking algorithms incrementally Dynamic programming algorithms divide
calling themselves with smaller values. find solutions to a problem. problems into subproblems and store
results for future use.
Categories of Algorithms
7 8 8
● This common algorithm is Dynamic programming algorithms. This Hashing algorithms. This algorithm
algorithm solves problems by dividing takes data and converts it into a
divided into two parts. One
them into subproblems. The results uniform message with a hashing.
part divides a problem into are then stored to be applied to future
smaller subproblems. The corresponding problems.
second part solves these
problems and then combines
them to produce a solution.
Algorithm Characteristics
Algorithms must have clear steps and inputs to avoid ambiguity in their execution and
Unambiguous results.
Algorithms must have well-defined inputs and produce specific outputs to achieve their
Input and Output intended purpose.
Algorithms must terminate after a finite number of steps to ensure completion within a
Finiteness reasonable time frame.
Algorithms should be independent of programming languages, allowing them to be
Independence implemented in various environments without language constraints.
Algorithm Characteristics
Feasibility Algorithms must be feasible
Algorithm Efficiency
Time Complexity Space Complexity
• Way to represent the amount of time required by the program • Amount of memory space required by the algorithm during its
to run until its completion execution
• Depends on the size of the input data and the steps involved • Includes instruction space, data space, and environment space
in the algorithm
• Critical for understanding the memory usage of algorithms
• Used to analyze the efficiency of algorithms
Time Complexity
Importance of Time Complexity in Algorithms
● Time complexity is a crucial metric to evaluate how efficiently an
algorithm performs in terms of execution time.
● It helps in understanding how the algorithm's running time increases
with respect to the input size.
● By analyzing time complexity, developers can choose the most
efficient algorithm for a given problem.
● Optimizing time complexity leads to faster and more scalable Plus tip:
algorithms.
Space Complexity
Instruction space is needed to Data space stores constants and Environment space holds
store the executable program variables in the program information required to resume
code suspended functions
Big O Notation
• Tool for describing the time and space complexity of algorithms.
Type Notation Example Algorithms
Logarithmic O(log n) Binary Search
Linear O(n) Linear Search
Superlinear O(n log n) Heap Sort, Merge Sort
Polynomial O(n^c) Strassen’s Matrix Multiplication,
Bubble Sort, Selection Sort, Insertion
Sort, Bucket Sort
Exponential O(c^n) Tower of Hanoi
Factorial O(n!) Determinant Expansion by Minors,
Brute force Search algorithm for
Traveling Salesman Problem