DSA – Data Structures & Algorithms

DSA = Data Structures + Algorithms

Data Structure is a way of organizing and storing data so that we can perform operations efficiently on it. How you store data decides how fast you can work with it.

Algorithm is a sequence of steps. An algorithm determines the steps used to solve a problem.

We judge a solution based on two parameters:
i. Time complexity: Time taken to run
ii. Space complexity: Memory used while running

Which solution you prefer:
i. Less time, more space
ii. More time, less space
Answer is i. Less time, more space as the cost of space is minimizing every day by various data storage methods.

Time complexity and space complexity are notations of time and space. Suppose we run the Java program in two different laptops, one with high end processor, 32 GB RAM, 8 core COPU and other with 4 GB RAM, 1 TB HDD. The absolute completion time may not be a right measurement of the solution as it depends on system configuration. Instead of looking at absolute values, we look at Notations.

Notations: Count operations against the input size. Suppose my input size is 10, how many operations are needed, input size is 1000, how many operations are needed.

You have an input array and have to find number 7 in array. It totally depends on the size of array. More the number of elements in array, more search operation has to be performed.

The three notations are:

Big OOmegaTheta
Worst caseBest caseAverage case
In case we do not find 7In case we find 7 in first elementIn case we find 7 somewhere in between

Complexity is written as a function of n
f(n) where n = input size

Leave a Reply

Your email address will not be published. Required fields are marked *