Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Data Structures Introduction by Dr.

Fatima Bahjat

Introduction to Data Structures


Data Structure is a way of collecting and organizing data in such a way that we can perform
operations on these data in an effective way. Data Structures is about rendering data elements
in terms of some relationship, for better organization and storage.

Following terms are the foundation terms of a data structure.

- Interface − Each data structure has an interface. Interface represents the set of
operations that a data structure supports. An interface only provides the list of
supported operations, type of parameters they can accept and return type of these
operations.
- Implementation − Implementation provides the internal representation of a data
structure. Implementation also provides the definition of the algorithms used in the
operations of the data structure.

Characteristics of a Data Structure

• Correctness − Data structure implementation should implement its interface correctly.


• Time Complexity − Running time or the execution time of operations of data structure
must be as small as possible.
• Space Complexity − Memory usage of a data structure operation should be as little as
possible.

Data Structure Usage

Data structures are used in almost every program or software system. Data structures provide
a means to manage huge amounts of data efficiently, such as large databases and internet
indexing services. Usually, efficient data structures are a key to designing efficient algorithms.
Some formal design methods and programming languages emphasize data structures, rather
than algorithms, as the key organizing factor in software design.

DS-3rd class-1st semester (2021-2022) Page 1 of 5


Data Structures Introduction by Dr. Fatima Bahjat

Basic types of Data Structures

Anything that can store data can be called as a data structure, hence Integer, Float, Boolean,
Char etc, all are data structures. They are known as Primitive Data Structures.

Non-primitive data structures are more complicated data structures and are derived
from primitive data structures. They emphasize on grouping same or different data items
with relationship between each data item. Arrays, Lists and Files come under this category.

Then we also have some complex Data Structures (Derived Data Type), which are
used to store large and connected data. Some examples of Abstract Data Structure
are: Linked List, Tree, Graph, Stack, Queue etc.

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

Characteristic Description

In Linear data structures, the data items are arranged in a linear


Linear
sequence. Example: Array

DS-3rd class-1st semester (2021-2022) Page 2 of 5


Data Structures Introduction by Dr. Fatima Bahjat

In Non-Linear data structures, the data items are not in sequence.


Non-Linear
Example: Tree, Graph

In homogeneous data structures, all the elements are of same type.


Homogeneous
Example: Array

Non- In Non-Homogeneous data structure, the elements may or may not be


Homogeneous of the same type. Example: Structures

Static data structures are those whose sizes and structures associated
Static
memory locations are fixed, at compile time. Example: Array

Dynamic structures are those which expands or shrinks depending


upon the program need and its execution. Also, their associated
Dynamic
memory locations changes. Example: Linked List created using
pointers

An abstract data type (ADT) is the realization of a data type as a software component. The
interface of the ADT is defined in terms of a type and a set of operations on that type. The
behavior of each operation is determined by its inputs and outputs. An ADT does not specify
how the data type is implemented. These implementation details are hidden from the user of
the ADT and protected from outside access, a concept referred to as encapsulation. While a
data structure is the implementation for an ADT.

Data types have both a logical and a physical form. The definition of the data type in terms of
an ADT is its logical form. The implementation of the data type as a data structure is its physical
form.

DS-3rd class-1st semester (2021-2022) Page 3 of 5


Data Structures Introduction by Dr. Fatima Bahjat

What is an Algorithm?

An algorithm is a finite set of instructions or logic, written in order, to accomplish a certain


predefined task. 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.

Pseudocode is a mixture of C++ (or some other programming language) and English (or
some other natural language). Pseudocode is used to express algorithms so that you are not
distracted by details of C++ syntax.

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 finite number of steps.
5. Correctness- Every step of the algorithm must generate a 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 following
properties:

1. Time Complexity

2. Space Complexity

Space Complexity

It’s 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.

DS-3rd class-1st semester (2021-2022) Page 4 of 5


Data Structures Introduction by Dr. Fatima Bahjat

Time Complexity

Time Complexity is a way to represent the amount of time needed by the program to run till its
completion. The time complexity of algorithms is most commonly expressed using the big O
notation. Time Complexity is most commonly estimated by counting the number of
elementary functions performed by the algorithm. And since the algorithm's performance may
vary with different types of input data, hence for an algorithm we usually use the worst-case
Time complexity of an algorithm because that is the maximum time taken for any input size.

Preconditions and Postconditions

When you write a complete function definition, you specify how the function performs its
computation. However, when you are using a function, you only need to think about what the
function does. You need not think about how the function does its work. For example, suppose
you are writing the temperature conversion program and you are told that a function is
available for you to use, as described here:

// Convert a Celsius temperature c to Fahrenheit degrees


double celsius_to_fahrenheit(double c);

A precondition is a statement giving the condition that is required to be true when a function
is called. The function is not guaranteed to perform as it should unless the precondition is true.

A postcondition is a statement describing what will be true when a function call is completed.
If the function is correct and the precondition was true when the function was called, then the
function will complete, and the postcondition will be true when the function call is completed.

For example, a precondition/postcondition for the celsius_to_fahrenheit function is shown


here:

double celsius_to_fahrenheit(double c);


// c is a Celsius temperature no less than
// absolute zero (–273.15).
// The return value is the temperature c
// converted to Fahrenheit degrees.

DS-3rd class-1st semester (2021-2022) Page 5 of 5

You might also like