techAVblog

DATA STRUCTURE AND ALGORITHAM

What are data structures & algorithms?

The term data structure is used to describe how the data is stored and the algorithm is used to describe how data is pressed, both data and algorithm are irrelated to each other, Where Data structure is nothing but a representation of the logical relationship between each element of the data. In other words, a data structure helps you organize all the data items that consider the way data elements are stored and their relationship to one another.

The algorithm is a finite set of instructions, which is used toaccomplish a particular task. Each of which has a clear meaning and can be performed with a finite number of efforts by a finite length of time. The best thing about the algorithm is that it doesn’t matter what input values may be, the algorithm terminates after executing a finite number of instructions.

The data structure can be represented as:

Algorithm + Data structure= program

What are ALGORITHM

An algorithm is a step-by-step process, which is to be followed when writing an algorithm to define a set of instructions in a certain order to get the output, algorithm can be written in more than one programming language. According to the data structure, some of the important categories of the algorithm are,

HOW TO WRITE AN ALGORITHM

Well, there is no well-defined structure for writing an algorithm. Algorithms are never written to be code for any particular programming language. We may know that all programming language(s) share some of the basic code constructures, like flow-control (if, else); loops (for, do, while), etc. these common constructure can help you in writing an algorithm.

We know that we write an algorithm in step-by-step order but, it is not in all cases. Writing an algorithm is the process of execution after the problem domain is well defined. Before you begin writing an algorithm you must know the main problem domain, for which you are about to design the solution.

Some of the examples are given to understand more about how to write an algorithm:

EXAMPLE 1

Write an algorithm to add 2 numbers,

STEP 1 - start
STEP 2 - read a, b
STEP 3 - sum a+b
STEP 4 - print
STEP 5 - stop

EXAMPLE 2

Check the eligibility of getting driving licence

STEP 1 - start
STEP 2 - read age
STEP 3 - if age >= 18 then go to step_4 else step_5
STEP 4 - writ “The person is eligible to get driving licences”
STEP 5 - writ “The person is not eligible to get driving licences”
STEP 6 - Stop

It is not necessarily that one must write an algorithm in the same way as mentioned above, the algorithm tells the programmer how to code to the given problem domain effectively. Moreover, we design algorithms to get the solution to a given problem. The problem can be solved in more than one way.


PERFORMANCE OF ALGORITHM

The efficiency of the algorithm is mostly dependent on

TIME COMPLEXITY:

The amount of time required for the algorithm to complete its execution is the time complexity. An algorithm is said to be efficient if it takes a minimum(reasonable) amount of time to complete the execution.

SPACE COMPLEXITY:

It’s the space occupied by the algorithm is known as space complexity. An algorithm is said to be efficient if it takes less space and required less amount of time to complete its execution.

ASYMPTOTIC NOTATIONS

Asymptotic analysis is the algorithm that refers to defining the mathematical bounding/framing of its run time. Asymptotic helps you to find the best, average, worst, case scenario of an algorithm. Asymptotic analysis refers to the computing time of any operation in a mathematical unit of computation.

For example, the running time of one operation is computed as f(n) and another operation took to compute g(n^2). This means that the first operation running time will increase linearly with the increase in n and the running time of the second operation will increase exponentially when n is increased.

The time required to compute by the algorithm fall under three (3) categories:

Why do we need to study DSA?

In this, we will learn why one should learn Data structure and algorithm (DSA), by learning Data structure and algorithm (DSA) you can understand the concept of the data and how to store the data in a way that can be found easily so that the user doesn’t face any problem finding out the data. As the applications are getting big and complex and increase in data, there are three (3) commonly problems that may occur in the application

  1. Data search
  2. Processor speed
  3. Multiple requests

To overcome this problem, we use data structures in this Data structure and algorithm (DSA) we will see the time and space complexity of the code and the best possible way to store the data. There are a few ways by which you can store the data,

ARRAY:

An array is a type of data structure that stores homogeneous elements in a memory location which are contiguous. The main concept of an array is to store multiple data in one location where each data is stored together to save memory and time to search the data. The data (or) objects which are of the same type are stored in the same order in the array. The size of the array needs to be defined before the data is stored in the array. Any data stored in the array can be accessed and modified easily. The data which are stored in the array are given a subject (or) index to identify the location of the data stored.

EXAMPLE:



let’s, store the marks of 20 students, then the size of an array has to be mentioned as 20. Then the student's marks can then be stored in the created array without creating separate variables for marks for every student. A Simple traversal of an array could be done to access the elements.

STACK

A stack is a linear data structure, where elements are inserted and deleted only from one end, that is the top of the stack. Stack follows the principle of LIFO (last in first out). The elements which are last in the stack will be deleted first as the elements can only be added from the top. So, the element which is added last will be the one that needs to be removed first.

The best example to understand the stack properties would be arranging the books according to their Roll number where the first roll number’s book goes at the bottom and the book of the last roll number is placed at the top. And if the books need to be distributed to students again the first book goes to the last roll number person. the items can only be added or removed only from the top that is the last item to be added to a stack will be removed first from the stack.

©coppy rights