DSA_Unit-1_-_Keypoints[1]
DSA_Unit-1_-_Keypoints[1]
Data-Structures
Data can be stored in different ways. Data structure is the logical or mathematical model of a
particular organization of data.
1. Should be suitable enough to mimic the actual relationships of data in the real world. e.g.
Graphs : Friend requests in Social media, Trees : hierarchical data like storing roles
2. Should be simple enough that one can effectively process the data however necessary.
3. Each data-structure has it's pros and cons, time complexity and space complexity. So
everything should be considered before using it.
Primitive Data Structures: Fundamental data types which is defined within the
programming language itself. These data types cannot be further divided down, hence the
name Simple data type. E.g. int, float, char, boolean etc.
Non-Primitive Data Structures: User-defined data types which are created using primitive
data structures. E.g. Linked-List, Stack, Queue, Trees and Graphs.
On the basis of structure and arrangement of data, Non-Primitive Data structure further
classified into :-
Analysis of Algorithms
Algorithm analysis is an important part of development, which provides theoretical estimation
for the required resources both time and space. It helps us compare between 2-3 different
choices of algorithms to choose whichever one is suitable for our use-case.
We usually talk about Best case, Worst case and Average case while discussing about an
algorithm.
Disadvantages:
Let function be f(n), for any value of n, the minimum time required by the
algorithm is given as :-
Let the function be f(n) belongs to the set O(g(n)), for any value of n running
time of an algorithm doesn't cross the time provided by O(g(n)) as per:-
3. Theta(θ) Notation(Average Case) : Provides both an upper and lower bound on the growth
rate of an algorithm's running time. Represents average-case scenario.
2. Binary Search: Divide and Conquer algorithm used in a sorted array by repeatedly
dividing the search interval in half.
Data structure must be sorted.
Divide the search space into two halves by finding the middle index mid.
Compare the element at mid with key value if equal then return otherwise delete the
half where value cannot be (like greater or smaller than key value).
If no match is found, return -1, again signifying absence of target value in structure.
Big-O Complexity : O(log n)