Intro to DSA
Intro to DSA
Intro to DSA
Sandeep G
Who Am I?
● What is an Algorithm?
● Data Structures and Types
● Why Learn Data Structures and Algorithms?
● Asymptotic Analysis
What is an Algorithm?
What is an Algorithm?
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.
In graph data structure, each node is called vertex and each vertex is
connected to other vertices through edges.
Edges
Tree Data structures
Similar to a 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 vs Non-linear Data Structures
Data items represented in single layer Data items represented in different layer
Can be traversed in single run. I.e. if we It may require multiple runs. I.e. if we start
start from start, we can go to end in a from one end, we might not reach till end in
sequential manner. one go.
E.g. you need to store students library card, you may store it in various ways -
1. Alphabetical order - sequential order
2. Based on department - hierarchical order
3. Based on type of book - hierarchical order
Now, if you know these different orders by which you can store, you will be
able to choose the best way to store these library cards. Such, that you are
able to access these cards fastest.
Find the factorial of ‘n’
Important resources in coding
Time complexity is the time taken by the algorithm to execute each set of instructions
Time to run code = no. of instructions * time to execute each instruction (constant for
every computer).
* Instruction is defined as the operation or calculation, computer does in each step.
E.g. You wrote a program, that works well for smaller input. But, as the input increases
your performance of the program decreases.
Why considering memory is important
The study of change in performance of the algorithm with the change in order of the input
size is defined as asymptotic analysis.
Our aim is to write the most efficient algorithm. Efficiency depends on the amount of time
and memory a program takes.
Asymptotic Notations - These are the mathematical notations used to describe the
running time of an algorithm when the input tends towards particular value.
It is defined as the upper bound of running time of an algorithm. Also known as the
performance of the algorithm in the worst case.
Search 52 (worst case time)
It is defined as the lower bound of running time of an algorithm. Also known as the
performance of the algorithm in the best case.
It is defined as the lower bound of running time of an algorithm. Also known as the
performance of the algorithm in the average case.