What is Data Structure and algorithm ?

Data Structure


Data Structure:-

 When we organize the data in a logical way that is called a data structure. In the programming world, the data structure plays the most significant role. In programming the two things are most important that is time and space. On computers, these two things are very important talking about time to execute any program the time is very important the execution should be done in less time as much as possible. Similarly, space any programs that not happen takes a lot of unwanted space. To avoid these things the concept comes in the mind is Data structure.

I hope you understand the concept of  Data structure.

Algorithm:-

It is a step by step procedure to solve the problem in a limited amount of time that is called Algorithm. To solve any problem in programming we need to know the algorithm for that let me give you an example so that you can understood properly.

Example:-

Let's say I want to add two numbers so what will be the algorithm for that I know it is quite simple we can make a big algorithm here but that will create confusion so for this moment let's stick on the simple algorithm. So our approach will be like this 

Algorithm:- Write an algorithm to add two numbers entered by the user?

Step 1: Start
Step 2: Declare variables num1, num2 and sum. 
Step 3: Read values num1 and num2. 
Step 4: Add num1 and num2 and assign the result to sum.
        sum←num1+num2 
Step 5: Display sum 
Step 6: Stop
so this will be the approach to solve this problem.

Explanation:-

In step 1  just starting the program from the main function.
Step 2 in this step we are declaring three variables num1, num2, and sum 
 Step 3 in this step we are taking the two inputs from the user num1 will hold the fist input and num2 will hold the second input in the program.
Step 4 in this step we are adding both numbers that we have taken from the user and after adding the number we will get our result so the result will store in the sum variable that we have previously declared.
Step 5 here just we are printing the result after adding both numbers and the result will display at the console window.



This is the algorithm to add the two numbers entered by the user and the approach to solve this problem is called an algorithm. 
I hope you guy's enjoyed this article in the next article we will start the stack. So let's jump right into it.









No comments:

Post a Comment