0% found this document useful (0 votes)
4 views28 pages

Lec 01

The document provides an introduction to data structures, explaining the concepts of variables, data types, and the classification of data structures into linear and non-linear types. It discusses abstract data types (ADTs) and their operations, as well as specific data structures like arrays, lists, stacks, queues, trees, and graphs. Additionally, it emphasizes the importance of selecting the appropriate data structure based on efficiency and resource constraints.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views28 pages

Lec 01

The document provides an introduction to data structures, explaining the concepts of variables, data types, and the classification of data structures into linear and non-linear types. It discusses abstract data types (ADTs) and their operations, as well as specific data structures like arrays, lists, stacks, queues, trees, and graphs. Additionally, it emphasizes the importance of selecting the appropriate data structure based on efficiency and resource constraints.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 28

Introduction

to
Data Structures

1
Variables
• Before going to the definition of variables, let us
relate them to old mathematical equations.
• All of us have solved many mathematical
equations since childhood. As an example,
consider the below equation:

2
Variables

• We don’t have to worry about the use of this


equation.
• The important thing that we need to understand is
that the equation has names (x and y), which hold
values (data).
• That means the names (x and y) are placeholders
for representing data.
• Similarly, in computer science programming we
need something for holding data, and variables is
the way to do that.
3
Data Types

• To solve the equation, we need to relate them to


the kind of values they can take, and data type is
the name used in computer science programming
for this purpose.
• A data type in a programming language is a set of
data with predefined values.
• Examples of data types are: integer, floating point,
unit number, character, string, etc.

4
Data Types

• A data type reduces the coding effort. At the top


level, there are two types of data types:
– System-defined data types (also called Primitive data
types)
– User-defined data types

5
System-defined data types
(Primitive data types)
• Data types that are defined by system are called
primitive data types.
• The primitive data types provided by many
programming languages are: int, float, char,
double, bool, etc.
• The number of bits allocated for each primitive
data type depends on the programming
languages, the compiler and the operating system.

6
System-defined data types
(Primitive data types)
• For the same primitive data type, different
languages may use different sizes.
• Depending on the size of the data types, the total
available values (domain) will also change.

7
User defined data types

• If the system-defined data types are not enough,


then most programming languages allow the users
to define their own data types, called user –
defined data types.
• Good examples of user defined data types are:
structures in C/C ++ and classes in Java.
• For example, in the following slide, we are
combining many system-defined data types and
calling the user defined data type by the name
“newType”.
8
User defined data types

• This gives more flexibility and comfort in dealing


with computer memory.

struct newType{
int data1;
float data2;

char data;
};
9
Data Structures

• Based on the discussion above, once we have


data in variables, we need some mechanism for
manipulating that data to solve problems.
• Data structure is a particular way of storing and
organizing data in a computer so that it can be
used efficiently.

10
Data Structures

• A data structure is a special format for organizing


and storing data.
• General data structure types include arrays, files,
linked lists, stacks, queues, trees, graphs and so
on.

11
Data Structures

• Depending on the organization of the elements,


data structures are classified into two types:
– Linear data structures: Elements are accessed in a
sequential order but it is not compulsory to store all
elements sequentially. Examples: Linked Lists, Stacks
and Queues.
– Non – linear data structures: Elements of this data
structure are stored/accessed in a non-linear order.
Examples: Trees and graphs.

12
Abstract Data Types (ADTs)

• Before defining abstract data types, let us consider


the different view of system-defined data types.
• We all know that, by default, all primitive data
types (int, float, etc.) support basic operations
such as addition and subtraction.
• The system provides the implementations for the
primitive data types.

13
Abstract Data Types (ADTs)

• For user-defined data types we also need to


define operations.
• The implementation for these operations can be
done when we want to actually use them.
• That means, in general, user defined data types
are defined along with their operations.

14
Abstract Data Types (ADTs)

• To simplify the process of solving problems, we


combine the data structures with their operations
and we call this Abstract Data Types (ADTs).
• An ADT consists of two parts:
– Declaration of data
– Declaration of operations

15
Abstract Data Types (ADTs)

• Commonly used ADTs include: Linked Lists,


Stacks, Queues, Priority Queues, Binary Trees,
Dictionaries, Graphs, and many others.
• For example, stack uses LIFO (Last-In-First-Out)
mechanism while storing the data in data
structures.
• The last element inserted into the stack is the first
element that gets deleted.

16
Abstract Data Types (ADTs)

• Common operations of it are: creating the stack,


pushing an element onto the stack, popping an
element from stack, finding the current top of the
stack, finding number of elements in the stack, etc.
• Different kinds of ADTs are suited to different
kinds of applications, and some are highly
specialized to specific tasks.

17
Abstract Data Types (ADTs)
• The most commonly used operation on data
structure are broadly categorized into following
types:
– Create
– Selection
– Updating
– Searching
– Sorting
– Merging
– Destroy or Delete
18
Arrays

• An array is defined as a set of finite number of


homogeneous elements or same data items.
• It means an array can contain one type of data
only, either all integer, all float-point number or
all character.
• Simply, declaration of array is as follows:
int arr[10];

19
Lists

• A lists (Linear linked list) can be defined as a


collection of variable number of data items.
• Lists are the most commonly used non-primitive
data structures.
• An element of list must contain at least two fields,
one for storing data or information and other for
storing address of next element.
• As you know for storing address we have a
special data structure of list the address must be
pointer type.

20
Stack

• A stack is also an ordered collection of elements


like arrays, but it has a special feature that
deletion and insertion of elements can be done
only from one end called the top of the stack
(TOP)
• Due to this property it is also called as last in first
out type of data structure (LIFO).

21
Queue

• Queue are first in first out type of data structure


(FIFO)
• In a queue new elements are added to the queue
from one end called REAR end and the element
are always removed from other end called the
FRONT end.
• The people standing in a railway reservation row
are an example of queue.

22
Trees

• A tree can be defined as finite set of data items


(nodes).
• Tree is non-linear type of data structure in which
data items are arranged or stored in a sorted
sequence.
• Tree represent the hierarchical relationship
between various elements.

23
Graph

• Graph is a mathematical non-linear data structure


capable of representing many kind of physical
structures.
• It has found application in Geography, Chemistry
and Engineering sciences.
• Definition: A graph G(V,E) is a set of vertices V
and a set of edges E.

24
Graph

• An edge connects a pair of vertices and many


have weight such as length, cost and another
measuring instrument for according the graph.
• Vertices on the graph are shown as point or
circles and edges are drawn as arcs or line
segment.

25
Efficiency

• Choice of data structure or algorithm can make


the difference between a program running in a
few seconds or many days.
• A solution is said to be efficient if it solves the
problem within its resource constraints.
– Space
– Time
• The cost of a solution is the amount of resources
that the solution consumes.
26
Selecting a Data Structure

• Select a data structure as follows:


– Analyze the problem to determine the basic
operations that must be supported.
– Quantify the resource constraints for each
operation.
– Select the data structure that best meets
these requirements.

27
Summary
• Each data structure has costs and benefits.
• Rarely is one data structure better than another in all
situations.
• A data structure requires:
– space for each data item it stores,
– time to perform each basic operation,
– programming effort.
• Each problem has constraints on available space and
time.
• Only after a careful analysis of problem characteristics
can we know the best data structure for the task.
28

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy