DATA STRUCTURE
Lesson 1:
Data Structure - are fundamental constructs used to organize, store, and manage
data efficiently within a computer's memory or storage systems
Key Characteristic:
● Organization - Data structures define how data elements are organized
andconnected, determining the relationships between different pieces of
information
● Storage Efficiency - Effective data structures aim to minimize memory usage
while maintaining accessibility and performance.
● Access and Retrieval - Data structures enable fast and efficient access to
specific elements within the stored data, enhancing the speed of search and
retrieval operations.
● Modification - They allow for the insertion, deletion, and modification of data
elements while maintaining the structure's integrity.
● Abstraction - Data structures often provide a higher-level abstraction,
shielding the user from the low-level details of memory management and
manipulation.
● Flexibility - Data structures can be adapted and designed to suit the
requirements of specific applications and algorithms.
● Complexity Analysis - Different data structures exhibit varying time and
space complexities for different operations, which influence the performance
of algorithms that use them.
Common Data Types:
● Arrays - A collection of elements with a fixed size, where each element is
identified by its index or position.
● Linked Lists - A linear collection of elements (nodes) where each element
points to the next element, forming a chain.
● Stacks - A collection of elements with Last-In-First-Out (LIFO) behavior, allowing
elements to be added and removed from the top.
● Queues - A collection of elements with First-In-First-Out (FIFO) behavior, used
for managing elements in the order they were added.
● Trees - Hierarchical structures with nodes that have parent-child relationships,
used for tasks like hierarchical representation and searching.
● Graphs - Networks of nodes (vertices) connected by edges, suitable for
representing relationships between entities.
● Hash Tables - Structures that store key-value pairs, offering fast retrieval and
insertion using a hash function.
● Heaps - Specialized trees with specific ordering rules, often used for priority
queue operations.
● Tries - Trees used for storing sequences like strings, offering efficient prefix
search and retrieval.
CLASSIFICATION OF DATA STRUCTURES
● Primitive Data Structures - These are the basic building blocks provided by
programming languages. They include integers, floating-point numbers,
characters, and booleans.
● Linear Data Structures - Elements are organized in a sequential manner, with
each element having a predecessor and a successor. Examples include arrays,
linked lists, stacks, and queues.
● Non-Linear Data Structures - Elements are organized in a hierarchical or
network-like manner, where each element can have multiple successors.
Examples include trees and graphs.
● Static Data Structures - These have a fixed size that needs to be specified at
the time of declaration. Examples include static arrays.
● Dynamic Data Structures - These can grow or shrink in size during execution.
Examples include linked lists and dynamic arrays.
● Homogeneous Data Structures - All elements are of the same data type.
Arrays are an example of homogeneous data structures.
● Heterogeneous Data Structures - Elements can be of different data types.
Structures and records are examples of heterogeneous data structures.
● Contiguous Data Structures - Elements are stored in consecutive memory
locations. Examples include arrays and matrices.
● Linked Data Structures - Elements are connected through pointers or
references. Examples include linked lists and trees.
● Primitive Linear Data Structures - These include basic linear structures like
arrays and linked lists.
● Composite Linear Data Structures - These are combinations of primitive linear
structures. Examples include stacks (built on arrays or linked lists) and queues
(built on arrays or linked lists).
● Linear Data Structures with Special Behavior - Examples include
double-ended queues (deque) and priority queues.
● Tree Data Structures - Hierarchical structures where elements (nodes) have
parent-child relationships. Examples include binary trees, AVL trees, and B-trees.
● Graph Data Structures - Networks of nodes (vertices) connected by edges.
Examples include directed graphs, undirected graphs, and weighted graphs.
● Hash-Based Data Structures - These use hash functions to store and retrieve
data efficiently. Examples include hash tables and hash maps.
● File-Based Data Structures - Data structures designed for storage on external
storage devices like disks. Examples include file systems and databases.
● Spatial Data Structures - Designed for efficient storage and retrieval of spatial
or geographical data. Examples include quadtrees and R-trees.
● Composite or Hybrid Data Structures - Combinations of multiple data
structures to achieve specific functionality or optimizations. Examples include
combination of arrays and linked lists.
Lesson 2:
Algorithm - well-defined, step-by-step procedure or set of rules
History of Algorithm:
● Ancient and Medieval Periods - the Euclidean algorithm for finding the greatest
common divisor (GCD) was known to the ancient Greeks.
● Islamic Golden Age (8th-13th centuries) - Mathematicians like Al-Khwarizmi
developed algorithms for solving linear and quadratic equations, leading to the
term "algorithm" derived from Al-Khwarizmi's name.
● Renaissance and Enlightenment Periods (16th-18th centuries) - Mathematical
developments continued with the work of mathematicians like Isaac Newton and
Gottfried Wilhelm Leibniz, who contributed to the development of calculus and
mathematical methods for solving various scientific problems
● 19th Century - saw the formalization of algorithms and the emergence of
systematic methods for solving specific problems. George Boole's work on
Boolean algebra laid the foundation for logic and computer science. Ada
Lovelace is often credited with writing the first algorithm intended to be processed
by a machine, even though her design was not implemented due to technological
limitations of the time.
● 20th Century - the emergence of computers in the mid-20th century brought
algorithms to the forefront of computation. Algorithms became essential for
programming these machines to perform calculations and execute tasks.
● Late 20th Century and Beyond - witnessed the rise of algorithms in various
domains, including cryptography, data analysis, and optimization.
● Modern Era - With the advent of the internet and the exponential growth of data,
algorithms have become crucial for tasks like web search, recommendation
systems, natural language processing, and machine learning
Characteristic of Algorithm
● Well-Defined Steps : Algorithms provide clear and precise instructions for performing
each step of the process. Each step should be unambiguous and understandable.
● Input and Output : Algorithms take some input (data or information) and produce an
output (result or solution) based on the provided input.
● Finite and Deterministic : Algorithms must have a finite number of steps, meaning they
eventually terminate. Additionally, each step in an algorithm must be well-defined and
deterministic, meaning that given the same input, the algorithm will always produce the
same output.
● Effective: Algorithms should be effective, meaning they produce the correct and desired
result for the given problem.
● Feasible: Algorithms should be feasible to implement, meaning that thesteps can be
carried out using available resources within a reasonable amount of time.
● General Applicability : Algorithms are designed to solve a class of problems rather than
a single instance. They provide a general method that can beadapted to different
scenarios within the problem domain.
● Independence of Implementation: Algorithms are not tied to a specific programming
language or platform. They are conceptual solutions that can be translated into code for
execution.
● Optimization : In some cases, algorithms strive to achieve optimal solutions, minimizing
or maximizing certain criteria, such as minimizing the time or space required for
execution.
Classification and types of Algorithm
A. Purpose
● Searching Algorithms - These algorithms are designed to find the presence or
location of a specific element within a dataset or data structure. Examples include
linear search and binary search.
● Sorting Algorithms - Sorting algorithms arrange elements in a particular order,
such as ascending or descending. Examples include bubble sort, merge sort, and
quicksort.
● Graph Algorithms - These algorithms analyze and manipulate graphs to solve
problems like finding shortest paths, detecting cycles, and network analysis.
Examples include Dijkstra's algorithm and breadth-first search.
● Numerical Algorithms - Numerical algorithms deal with mathematical
computations, such as solving equations, integrating functions, and finding roots.
● String Algorithms - String algorithms address problems related to string
manipulation and pattern matching, like finding substrings or searching for
patterns within strings.
● Greedy Algorithms - Greedy algorithms make locally optimal choices at each
step to achieve a global optimal solution. Examples include the greedy algorithm
for the knapsack problem.
● Dynamic Programming Algorithms - Dynamic programming algorithms break
down complex problems into smaller subproblems and solve each subproblem
only once, storing the solutions for later use. Examples include the Fibonacci
sequence and the edit distance problem
B. Design and Paradigms
● Divide and Conquer - Algorithms following this paradigm divide a problem into
smaller subproblems, solve them independently, and then combine the solutions
to solve the original problem. Examples include merge sort and quicksort.
● Dynamic Programming - As mentioned earlier, dynamic programming
algorithms break down problems into overlapping subproblems and store their
solutions to avoid redundant computations.
● Greedy Algorithms - Greedy algorithms make locally optimal choices at each
step, hoping to reach a global optimal solution.
● Backtracking Algorithms - Backtracking involves exploring all possible
solutions by trying out different choices and undoing them if they don't lead to a
valid solution. Examples include the eight queens problem and the traveling
salesman problem.
C. Computational Complexity
● P (Polynomial Time) - These algorithms can be solved in polynomial time,
ndicating efficient computation. Problems in the P class are generally considered
tractable.
● NP (Nondeterministic Polynomial Time) - These problems can be verified in
polynomial time, but finding a solution is not necessarily efficient. NP problems
include many optimization problems.
● NP-Hard and NP-Complete - These are problem classes that are at least as
hard as the hardest problems in NP. NP-complete problems are both in NP and
also have the property that if one NP-complete problem can be solved in
polynomial time, then all NP problems can.
● Exponential Time - Algorithms with exponential time complexity are not
considered efficient, as their running time grows very rapidly with the input size.
Lesson 3:
Algorithm Approaches - systematic strategies used to design and analyze algorithms
for solving specific types of problems
Lesson 4:
Subsets of AI:
● Machine learning - Machine learning is a type of AI that allows computers to
learn without being explicitly programmed. Machine learning algorithms are
trained on data to identify patterns and make predictions.
● Deep learning - Deep learning is a type of machine learning that uses artificial
neural networks to learn from data. Neural networks are inspired by the structure
and function of the human brain, and they are able to learn complex patterns
from large amounts of data.
● Natural language processing (NLP) - NLP is a field of AI that deals with the
interaction between computers and human language. NLP algorithms can be
used to understand and generate human language, and they are used in a wide
variety of pplications, such as machine translation, chatbots, and text
summarization.
● Computer vision - Computer vision is a field of AI that deals with the ability of
computers to understand and interpret images and videos. Computer vision
algorithms can be used to identify objects, faces, and scenes in mages and
videos, and they are used in a wide variety of applications, such as self-driving
cars, facial recognition software, and medical imaging.
● Robotics - Robotics is a field of AI that deals with the design, construction,
operation, and application of robots. Robots are machines that can be
programmed to perform tasks automatically, and they are used in a wide variety
of industries, such as manufacturing, healthcare, and logistics.
Lesson 5:
Time profiling - is a technique used to measure the amount of time that a program or
function spends executing different parts of its code
Space profiling - is a technique used to measure the amount of memory that a
program or function uses. This information can be used to identify memory leaks and to
optimize the code for better memory usage
Code Coverage
● Statement coverage - This technique measures the percentage of statements in the
code that are executed when the program is run.
● Branch coverage - This technique measures the percentage of branches in the code
(such as if-else statements and loops) that are executed when the program is run.
● Function coverage - This technique measures the percentage of functions in the code
that are called when the program is run.
● Condition coverage - This technique measures the percentage of conditions in the
code (such as Boolean expressions) that are evaluated as true when the program is run.
● Path coverage - This technique measures the percentage of paths through the code
that are executed when the program is run.