A Common Sense Guide To Data Structures And Algorithms

Rate this post

There are many ways to understand and learn about data structures and algorithms. Still, here I am going to share some common sense things that will help you acquire a deeper knowledge of DSA, i.e., data structure and algorithm, and also be able to apply these things in real-world scenarios.

Let’s understand the terms used in DSA i.e. Data, Structures, and Algorithms.

This image is showing data in a structured format in a peace of paper.
  1. DATA: A metric detailing anything is considered to be data, and everything around us can be represented as Data. For example, you are sitting at a table, interacting with a laptop, and reading codewithdc.com articles and it can be called data.
    • With the help of data we can perform better in our daily lives, For example: In a forensic report, if an officer wants to find the suspect or the victim then he or she needs to analyze and validate the data properly to confirm the suspect or victim and hence the data result’s in performing better.
  2. Structures: Analyzing limited data is fine, but when it comes to analyzing the collection of data which can be huge in terms of number or size then it becomes difficult to analyze the data in less amount of time.
    • So to analyze the collection of data in less amount then we need to define a proper structure after understanding the given data.
    • For Example: In a given collection of data, we were able to find the pattern which repeatedly giving details about the student like student name, student marks, student birth date, etc. Then for such data, we can give data a table structure.
    • By giving table structure, we will be able to analyze data faster.
  3. Algorithm: An algorithm is the set of steps that should be taken to perform a task and it is up to you, that you may design an algorithm that takes less Time and Space complexity or a greater one, always note that the world refers to an optimized algorithm and by the time you will be able to find the difference between the performance.

Till now, we have understood all the parameters of DSA i.e. Data Structure and Algorithms, and here you should note that Data Structure and Algorithms are two different subjects from which Data Structure represents the whole subject of structuring data, For Example, Stack, Queues, Linked Lists and there are many more.

The Algorithm uses Data Structures to create a durable and optimized version of steps that can be used to write programs in different languages. For Example: If you want to write a program to calculate PostFix Expression then the optimized algorithm uses Stack Data Structure. Likewise, you can think about which data structures can be used in your program, but always note that use data structures when there is a need to structure your data.

Checkout More Articles at codewithdc.com

Now, I hope you understood all the parameters properly, and if not, then you can mention your thoughts in the comment section and describe your confusion so that we can add those missing elements to this article.

Now, I am going to give you an example of how you can use data structures and algorithms together, or, in simple words, I am going to tell you how any programmer was thinking before writing an actual program and using DSA in their program, but before understanding that let’s understand the common sense guide for each term little bit deeper.

Common Sense Guide To Data Structure

As you may have heard, there are types of data structures, such as arrays, stacks, queues, linked lists, trees, graphs, etc. But have ever tried to know the reason behind the naming of these data structures and if you didn’t it’s fine but think off now and think why this data structure is called a Stack or an Array, If you were able to find the answer to this question then you are good to go with implementation and if not below examples will definitely help you to grab the overall concept.

Lets’s understand some of the data structures in the easiest manner:

  1. Stack: We call it a Stack data structure and the main reason behind calling it Stack is the way of inserting elements into this data structure i.e. Here we only insert elements from one side and deletion also happens on one side only.

    Therefore we can say that it’s kind of building a tower by inserting elements on the top of it. Let’s see the below examples one by one to build your confidence over this type of data structure.
    • Tower Of Hanoi: Tower Of Hanoi is a game in which three pillars are given on a base and from this pillar one pillar has a stack of plates with different sizes and here we need to shift the whole stack into another pillar and follow the rule like by moving plates we need to make sure that while inserting plate we need to check that the inserted element is greater than the current one or not if not then we cannot insert that plate.
      Tower Of Hanoi
    • Stack Of Books Or Plates:
      Here, Stack of Books or Plates means that the books or plates are placed in the bottom-up approach manner i.e one book placed on another book, likewise for plates also and here we can’t insert the books or plates in between, because there may be chances of the building of books can be fallen. See the below images for more clarity.

      StackOfBooks scaled Stack Of Plates

Common Sense Guide To Algorithm

In life or In a career, Whatever you have done or you want to do is always followed by certain steps, and the number of steps you follow to achieve that particular thing is sometimes referred to as an Algorithm in the digital world.

Now, that we have understood the definition of an Algorithm, but finding the difference between the given algorithms is the key to figuring out the optimized version of an algorithm that can give you the best results by consuming less time and space in the universe.

Let’s understand one of the algorithms here and the difference between the two algorithms.

The Algorithm we are going to talk about is to find the given element in the sorted array in less amount of time.

Know About Claude AI: One Of Best AI In The Market.

So there are many ways to solve this type of problem and we will be going to discuss about two of them (i.e. Linear Search and Binary Search) and don’t fear about the coding language, Here we will be just going to understand this algorithm in layman language. Please note that we are considering that the given array will be sorted in ascending order.

Linear Search algorithm banner (1)
  1. Linear Search:
    • In Linear Search, Searching is performed linearly, and if there are “N” number of elements present in the given array then to find the given element in the worst-case scenario, we have to trace the whole array i.e for N element we have to search N times.
    • Therefore, the worst-case time complexity is N.
    • To have more clarification, refer above image from GeeksForGeeks.
  2. Binary Search:
    • In Binary Search, Searching is performed by checking out the middle element and if the middle element is greater than the given element then we just need to update the index value to the right of the middle element otherwise to the left one.
    • Now, Here if you read the above statement carefully then you will come to know that every time we divide an array into two halves and due to that our searching got improves i.e In an array of N elements we need to search the given element, time taken by this algorithm is less than the Linear Search Algorithm.
    • The time complexity of this algorithm to search for a given element in an array of N elements is nothing logN in the worst case.
    • For more clarification, refer to the below image from GeeksForGeeks.org
binnary search

FAQ’s

Now I know you guys will be having lots of questions in your head but don’t worry, I have targeted a few of them below and if you didn’t find your answer then don’t forget to mention your question in the comment section.

Is still Data Structures & Algorithms used in IT Companies.

Yes due to its great features, Nearly every company implements Data Structures & Algorithms for producing a great version of any application or software. And if they are not using then it may be possible that they don’t know the power of DSA.

How to enhance our DSA Knowledge

Knowing the concept of DSA is great, but to understand you to practice it to enhance your DSA problem-solving knowledge. Therefore, the more problems you solve will help you unlock the great features of DSA. You can also refer to Cracking the Coding Interview Book.

What is data in programming?

In programming, data can be Numbers, an Array of numbers, Strings, A set of strings, Information about any field, Excel data, Images, Links, etc. In simple meaning, data in programming can be anything that can help you write an efficient program to produce the required output.

For Example:
I have a list of 100 numbers, and my client says you need to write a program to find whether the entered number is present in the given list or not, if the number is present then print “Number is present in the list” otherwise “Number is not present in the list”.

So, In this example, 100 numbers were the precious data in the programming, which helps us to write a program accordingly.

What is an algorithm in a computer with an example?

In Computers, an Algorithm is a set of instructions used to process the given input and produce the output according to that input.

How time complexity is calculated in the algorithm with an example?

In Algorithms, there are two ways to calculate the time complexity of an algorithm: the priori analysis and the posterior analysis. We normally go with the prior analysis because here, we calculate time complexity according to program statements without taking care of system details like the i5 7th Gen Processor or something similar, which is taken care of in posterior analysis.

Leave a Comment

Scroll to Top