Introduction to Data Structure And Algorithm in C++ for Beginners: (Part 1)

Akash Salvi
GDSC DYPCOE
Published in
4 min readJun 12, 2020

What is Data structure?

Data Structure is a way of collecting and organising data in such a way that we can perform operations on these data in an effective way.

For example, we have some data which has, student’s name “Prakash” and age 26. Here “ Prakash” is of String data type and 26 is of the integer data type.

Data Structures are structures programmed to store ordered data so that various operations can be performed on it easily. It represents the knowledge of data to be organized in memory. It should be designed and implemented in such a way that it reduces the complexity and increases the efficiency.

Basic types of Data Structures:-

There are three types of data structure :

A. Primitive Data Types: These data types are built-in or predefined data types and can be used directly by the user to declare variables. example: int, char, float, bool etc. Primitive data types available in C++ are

  1. Integer (int)
  2. Character (char)
  3. Boolean (bool)
  4. Floating Point (float)
  5. Double Floating Point (double)
  6. Valueless or Void (void)
  7. Wide Character (wchar_t)

B. Derived Data Types: The data-types that are derived from the primitive or built-in datatypes are referred to as Derived Data Types. These can be of four types namely:

  1. Function
  2. Array
  3. Pointer
  4. Reference

C. Abstract/User-defined Data Types: These data types are defined by the user itself. Like, defining a class in C++ or a structure. C++ provides the following user-defined datatypes:

  1. Class
  2. Structure
  3. Union
  4. Enumeration
  5. Typedef defined DataType.

The data structures can also be classified on the basis of the following characteristics:

  1. Linear :- In Linear data structures, the data items are arranged in a linear sequence. Example: Array.
  2. Non-Linear :- In Non-Linear data structures, the data items are not in sequence. Example: Tree, Graph.
  3. Homogeneous :-In homogeneous data structures, all the elements are of the same type. Example: Array.
  4. Non-Homogeneous :- In a Non-Homogeneous data structure, the elements may or may not be of the same type. Example: Structures.
  5. Static :- Static data structures are those whose sizes and structures associated memory locations are fixed, at compile time. Example: Array.
  6. Dynamic :-Dynamic structures are those which expands or shrinks depending upon the program need and its execution. Also, their associated memory locations changes. Example: Linked List created using pointers.

What is an Algorithm?

An algorithm is a finite set of instructions or logic, written in order, to accomplish a certain predefined task. The algorithm is not the complete code or program, it is just the core logic(solution) of a problem, which can be expressed either as an informal high-level description as pseudocode or using a flowchart.

Every Algorithm must satisfy the following properties:

  1. Input- There should be 0 or more inputs supplied externally to the algorithm.
  2. Output- There should be at least 1 output obtained.
  3. Definiteness- Every step of the algorithm should be clear and well defined.
  4. Finiteness- The algorithm should have a finite number of steps.
  5. Correctness- Every step of the algorithm must generate correct output.

An algorithm is said to be efficient and fast, if it takes less time to execute and consumes less memory space. The performance of an algorithm is measured on the basis of the following properties :

  1. Time Complexity : Time Complexity is a way to represent the amount of time required by the program to run until its completion. It’s generally a good practice to try to keep the time required minimum so that our algorithm completes its execution in the minimum time possible.
  2. Space Complexity : Its the amount of memory space required by the algorithm, during the course of its execution. Space complexity must be taken seriously for multi-user systems and in situations where limited memory is available.

So, till now you got a basic intro of data structure and algorithm,their are few important data structure through which you can master in DSA i.e

  • Arrays and Lists
  • 2D Arrays
  • Strings
  • Linked List
  • Stack
  • Queue
  • Hash Table & Hash Set
  • Heap
  • Graphs
  • Binary Tree
  • Binary Search Tree

If you practice and are able to solve problem-related to all the data structure listed above, you can master in DSA.

You can Check my new article based on Array:

“Introduction to Data Structure And Algorithm (Part 2):-(Arrays)”

next article coming soon…..

--

--