DS-Unit 1-Introduction To DS
DS-Unit 1-Introduction To DS
DS
DR. DEEPTI REDDY
A S S O C I AT E P R O F E S S O R
D E P T. O F C O M P U T E R E N G I N E E R I N G ,
MPSTME, NMIMS, MUMBAI
Unit 1- Introduction
oIntroduction to data structure and its importance,
oClassification of data structures,
oBasic operations.,
oAbstract data type,
oPerformance analysis- time and space complexity,
oAsymptotic Notations.
Data Structures
Data structures represents the organization of data in computer
memory on which operations like insert, delete, update can be
performed.
Data structure is basically a group of data elements included under one
name, e.g. the students data, employees data, etc.
The data structures defines a particular way of storing and organizing
data so it can be used efficiently (Thareja, 2014).
A data structure is a way to store and organize data in order to facilitate
access and modifications. No single data structure works well for all
purposes, and so it is important to know the strengths and limitations of
several of them (Corman, 2022)
Fox and crane story
Types Of Data Structures
Applications of DS
◦ Operating Systems
◦ Compiler Construction
◦ DBMS
◦ Some real world problems: lookup a contact on your phone, web search,
login to social network..
Efficiency of Programs
The programs are written to solve problems, like searching a data item,
sorting data items, updating data, etc.
The programs efficiency is based on the execution time and memory
space utilization.
The efficiency of the program depends on the data structure used to
represent data on which operations like search, sort, insert, etc are
performed.
Types of Data Structures and
its operations
Data structures
and operations
12 56 89 29
Linear DS- Stack
A stack is an ordered collection of data elements into which elements
can be inserted or deleted only from one end, called the top of the
stack as shown in figure.
58 Top of stack
98
16
Linear DS-Queue
In contrast to stack, queue is opened at both end. One end is always
used to insert data (enqueue) and the other is used to remove data
(dequeue).
Queue follows First-In-First-Out methodology, i.e., the data item stored
first will be accessed first as shown in figure.
Nonlinear DS- Trees
A binary tree is another commonly
used data structure. It is organized
like an upside down tree.
A node, holds an item of data along
with a left pointer and a right pointer.
Useful for efficient search, e.g
telephone directory
Nonlinear DS- Use of Trees
A binary search tree is a good data structure to use for
searching sorted data.
The middle item from the list is stored in the root node,
with lesser items to the left and greater items to the
right.
A search begins at the root. The computer either find
the data, or moves left or right, depending on the value
for which you are searching.
Each move down the tree cuts the remaining data in half.
Items can be located very quickly in a tree.
Telephone directory assistance information is stored in a
tree, so that a name and phone number can be found
quickly.
Nonlinear DS- Graphs
Graph is a collection of vertices(nodes) and edges that connect these
vertices.
Unlike trees, in graph the nodes may not be connected in hierarchy.
Used to represent a complex relationships between components.
City map can be represented using graph, where nodes represent cities
and edges represent road connectivity.
Linear and Nonlinear DS
Linear DS
◦ Data elements are stored sequentially
◦ Traverse forward and backward from the node
◦ E.g. Arrays, stack, queues and linked list.
Nonlinear DS
◦ No linear relation between data elements
◦ Cannot be traversed in a single run.
Reflection
Match the following
A. Stack i. Dynamic memory allocation
B. Queue ii. Last in first out
C. Linked list iii. Static memory allocation
D. Array iv. First in first out
int main()
{
int array[100], position, c, n, value;
printf("Enter number of elements in array\n");
scanf("%d", &n);
array[position-1] = value;
return 0;
}
Abstract Data Type
Solving a problem involves processing data, this requires that we
identify-
1. the collection of data items and
2. basic operations that must be performed on them.
Such a collection of data items together with the operations on the data
is called an abstract data type (ADT).
The word abstract refers to the fact that data and operations are
defined independent of its implementation.
We just specify what can be done with the data, and not how it is done.
Example of ADT
Problem- Because of new government regulation, the university has to keep records
of all students currently receiving financial aid and submit regular reports to
government. Design the program for the same.
Data: Financial_aid_awards: text string source, real value amount
Operations:
Get_amount(): Access and return the amount stored
Display(): display on screen source and amount
Update_amount(): modify the amount
Data: Student_data: numeric id, text string name, list of financial aid awarded <
source, amount>
Operation:
Get_record(),Update_amount()
Example of ADT
ADT of List
List holds an ordered collection of items accessible by an integer index.
Operations
1. Insert(element, position) – inserts element at a given position
2. delete(element)- deletes the existing element
3. search(element)- returns the position of the element
Abstract Data Type
Advantage of ADT
Data abstraction: The idea of separating the definition of data
definition from implementation enables software designers to study
data types without being concerned about the details of its
implementation.
Reuse: Programmers may reuse these data types and its operation
without worrying about its implementation.
To manage complexity: To manage the complexity of problems and the
problem-solving process, computer scientists use abstractions to allow
them to focus on the “big picture” without getting lost in the details.
Reflection
1. Abstract data type represents –
◦ A. Set of data types and operations defined on that data type.
◦ B. The data types and operations implemented using programming language
◦ C. The data types and its values only