Data Structure Tutorial

Data is organized in a particular fashion for the computer to be able to use it efficiently & this structure is called as Data Structure. We are going to see the importance, utility and various concepts of Data Structure in this tutorial.

Data Structure Tutorial

Learn Data Structure with our complete and easy to understand Data Structure Tutorial. Beginning with the basics of Data Structure, this tutorial goes on to explain you advance concepts like Graphs, Hashing and File Organization with the help of practical examples and programs.

Who is this Data Structure Tutorial designed for?

This tutorial will be very useful for both beginners and professionals. All the freshers, BCA, BE, BTech, MCA and college students, will find this tutorial extremely useful for their notes, exam preparation, lab exercises, assignments and viva questions.

What do I need to know to begin with?

A basic knowledge of C will be very helpful to get understand the concepts of Data Structure quickly.

Data Structure syllabus covered in this tutorial

This Data Structure tutorial covers:

Data Structure Introduction, Linked List, Types of Linked List, Stack, Queue, Types of Queue, Searching, Sorting, Trees, Graphs, Hashing, File Organization.

That covers almost everything about Data Structure, so let's begin learning!

What is Data Structure?

  • Data structure is an arrangement of data in computer's memory. It makes the data quickly available to the processor for required operations.
  • It is a software artifact which allows data to be stored, organized and accessed.
  • It is a structure program used to store ordered data, so that various operations can be performed on it easily.
    For example, if we have an employee's data like name 'ABC' and salary 10000. Here, 'ABC' is of String data type and 10000 is of Float data type.
    We can organize this data as a record like Employee record and collect & store employee's records in a file or database as a data structure like 'ABC' 10000, 'PQR' 15000, 'STU' 5000.
  • Data structure is about providing data elements in terms of some relationship for better organization and storage.
  • It is a specialized format for organizing and storing data that can be accessed within appropriate ways.

Why is Data Structure important?

  • Data structure is important because it is used in almost every program or software system.
  • It helps to write efficient code, structures the code and solve problems.
  • Data can be maintained more easily by encouraging a better design or implementation.
  • Data structure is just a container for the data that is used to store, manipulate and arrange. It can be processed by algorithms.
    For example, while using a shopping website like Flipkart or Amazon, the users know their last orders and can track them. The orders are stored in a database as records.
    However, when the program needs them so that it can pass the data somewhere else  (such as to a warehouse) or display it to the user, it loads the data in some form of data structure.

Types of Data Structure

types of data structure

A. Primitive Data Type

  • Primitive data types are the data types available in most of the programming languages.
  • These data types are used to represent single value.
  • It is a basic data type available in most of the programming language.
Data typeDescription
IntegerUsed to represent a number without decimal point.
FloatUsed to represent a number with decimal point.
CharacterUsed to represent single character.
BooleanUsed to represent logical values either true or false.

B. Non-Primitive Data Type

  • Data type derived from primary data types are known as Non-Primitive data types.
  • Non-Primitive data types are used to store group of values.
It can be divided into two types:

1. Linear Data Structure
2. Non-Linear Data Structure

1. Linear Data Structure

  • Linear data structure traverses the data elements sequentially.
  • In linear data structure, only one data element can directly be reached.
  • It includes array, linked list, stack and queues.
TypesDescription
ArraysArray is a collection of elements. It is used in mathematical problems like matrix, algebra etc. each element of an array is referenced by a subscripted variable or value, called subscript or index enclosed in parenthesis.
Linked listLinked list is a collection of data elements. It consists of two parts: Info and Link. Info gives information and Link is an address of next node. Linked list can be implemented by using pointers.
StackStack is a list of elements. In stack, an element may be inserted or deleted at one end which is known as Top of the stack. It performs two operations: Push and Pop. Push means adding an element in stack and Pop means removing an element in stack. It is also called Last-in-First-out (LIFO).
QueueQueue is a linear list of element. In queue, elements are added at one end called rear and the existing elements are deleted from other end called front. It is also called as First-in-First-out (FIFO).

2. Non-Linear Data Structure

  • Non-Linear data structure is opposite to linear data structure.
  • In non-linear data structure, the data values are not arranged in order and a data item is connected to several other data items.
  • It uses memory efficiently. Free contiguous memory is not required for allocating data items.
  • It includes trees and graphs.
TypeDescription
TreeTree is a flexible, versatile and powerful non-linear data structure. It is used to represent data items processing  hierarchical relationship between the grandfather and his children & grandchildren. It is an ideal data structure for representing hierarchical data.
GraphGraph is a non-linear data structure which consists of a finite set of ordered pairs called edges. Graph is a set of elements connected by edges. Each elements are called a vertex and node.

Abstract Data type (ADT)

What is ADT?

  • ADT stands for Abstract Data Type.
  • It is an abstraction of a data structure.
  • Abstract data type is a mathematical model of a data structure.
  • It describes a container which holds a finite number of objects where the objects may be associated through a given binary relationship.
  • It is a logical description of how we view the data and the operations allowed without regard to how they will be implemented.
  • ADT concerns only with what the data is representing and not with how it will eventually be constructed.
  • It is a set of objects and operations. For example, List, Insert, Delete, Search, Sort.
It consists of following three parts:

1. Data
2. Operation
3. Error

1. Data describes the structure of the data used in the ADT.

2. Operation describes valid operations for the ADT. It describes its interface.

3. Error describes how to deal with the errors that can occur.

Advantages of ADT

  • ADT is reusable and ensures robust data structure.
  • It reduces coding efforts.
  • Encapsulation ensures that data cannot be corrupted.
  • ADT is based on principles of Object Oriented Programming (OOP) and Software Engineering (SE).
  • It specifies error conditions associated with operations.