SlideShare a Scribd company logo
Data Structures
and Algorithms
Lec-1
CSC 391
2
Data Structures and Algorithms
Data Structure
©SMT, Faculty, CSE, IUBAT
In computer science, a data structure is a particular way of storing and
organizing data in a computer’s memory so that it can be used
efficiently. Data may be organized in many different ways.
The logical or mathematical model of a particular organization
of data is called a data structure.
3
Data Structures and Algorithms
Types
Categories of Data Structure:
The data structure can be classified in to major types:
• Linear Data Structure
• Non-linear Data Structure
1. Linear Data Structure:
A data structure is said to be linear if its elements form any sequence. There
are basically two ways of representing such linear structure in memory.
a) One way is to have the linear relationships between the elements
represented by means of sequential memory location. These linear
structures are called arrays.
b) The other way is to have the linear relationship between the
elements represented by means of pointers or links. These linear structures
are called linked lists.
©SMT, Faculty, CSE, IUBAT
4
Data Structures and Algorithms
The common examples of linear data structure are- Arrays, Queues, Stacks,
Linked lists
2. Non-linear Data Structure:
This structure is mainly used to represent data containing a hierarchical
relationship between elements.
e.g. graphs, family trees and table of contents.
Types
©SMT, Faculty, CSE, IUBAT
5
Data Structures and Algorithms
Memory Allocation
©SMT, Faculty, CSE, IUBAT
Memory allocation can be classified as either
 Contiguous
 Linked
 Indexed
Prototypical examples:
 Contiguous allocation: arrays
 Linked allocation: linked lists
6
Data Structures and Algorithms
Contiguous Allocation
©SMT, Faculty, CSE, IUBAT
An array stores n objects in a single contiguous space of memory
Unfortunately, if more memory is required, a request for new
memory usually requires copying all information into the new
memory
 In general, you cannot request for the operating
system to allocate to you the next n memory
locations
7
Data Structures and Algorithms
Linked Allocation
©SMT, Faculty, CSE, IUBAT
Linked storage such as a linked list associates two pieces of data
with each item being stored:
 The object itself, and
 A reference to the next item
 In C++ that reference is the address of the next node
8
Data Structures and Algorithms
Linked Allocation
©SMT, Faculty, CSE, IUBAT
This is a class describing such a node
template <typename Type>
class Node {
private:
Type element;
Node *next_node;
public:
// ...
};
9
Data Structures and Algorithms
Linked Allocation
©SMT, Faculty, CSE, IUBAT
The operations on this node must include:
 Constructing a new node
 Accessing (retrieving) the value
 Accessing the next pointer
Node( const Type& = Type(), Node* = nullptr );
Type retrieve() const;
Node *next() const; Pointing to nothing has been represented
as:
C NULL
Java/C# null
C++ (old) 0
C++ (new) nullptr
Symbolically Ø
10
Data Structures and Algorithms
Linked Allocation
©SMT, Faculty, CSE, IUBAT
For a linked list, however, we also require an object which links to
the first object
The actual linked list class must store two pointers
 A head and tail:
Node *head;
Node *tail;
Optionally, we can also keep a count
int count;
The next_node of the last node is assigned nullptr
11
Data Structures and Algorithms
Linked Allocation
©SMT, Faculty, CSE, IUBAT
The class structure would be:
template <typename Type>
class List {
private:
Node<Type> *head;
Node<Type> *tail;
int count;
public:
// constructor(s)...
// accessor(s)...
// mutator(s)...
};
12
Data Structures and Algorithms
Indexed Allocation
©SMT, Faculty, CSE, IUBAT
With indexed allocation, an array of pointers
(possibly NULL) link to a sequence of
allocated
memory locations
Used in the C++ standard template library
Computer engineering students will see
indexed
allocation in their operating systems course
13
Data Structures and Algorithms
Indexed Allocation
©SMT, Faculty, CSE, IUBAT
Matrices can be implemented using indexed
allocation:
1 2 3
4 5 6
 
 
 
14
Data Structures and Algorithms
Indexed Allocation
©SMT, Faculty, CSE, IUBAT
Matrices can be implemented using indexed allocation
 Most implementations of matrices (or higher-dimensional arrays)
use indices pointing into a single contiguous block of memory
Row-major order Column-major order
C, Python Matlab, Fortran
1 2 3
4 5 6
 
 
 
15
Data Structures and Algorithms
Data Structure Formats
©SMT, Faculty, CSE, IUBAT
We will look at some variations or hybrids of these memory
allocations including:
 Trees
 Graphs
 Array
 Linked List
 Stack
 Queue
16
Data Structures and Algorithms
Trees
©SMT, Faculty, CSE, IUBAT
The linked list can be used to store linearly ordered data
 What if we have multiple next pointers?
A rooted tree (weeks 4-6) is similar
to a linked list but with multiple next
pointers
17
Data Structures and Algorithms
Trees
©SMT, Faculty, CSE, IUBAT
Data frequently contain a hierarchical relationship between various elements.
The data structure which reflects this relationship is called a rooted tree graph
or, simply, a tree.
A tree is a variation on a linked list:
 Each node points to an arbitrary number of subsequent nodes
 Useful for storing hierarchical data
2.2.2.2
18
Data Structures and Algorithms
Graphs
©SMT, Faculty, CSE, IUBAT
Suppose we allow arbitrary relations between any two objects in a
container
 Given n objects, there are n2 – n possible relations
 If we allow symmetry, this reduces to
 For example, consider the network
2
2
n n
2.2.2.2
Data sometimes contains a relationship between pairs of
elements which is not necessarily hierarchical in nature, e.g. an
airline flights only between the cities
connected by lines. This data structure is called Graph.
19
Data Structures and Algorithms
Arrays
©SMT, Faculty, CSE, IUBAT
2.2.2.2
The simplest type of data structure is a linear (or one dimensional)
array. A list of a finite number n of similar data referenced respectively
by a set of n consecutive numbers, usually 1, 2, 3 . . . . . . . n. if we choose
the name A for the array, then the elements of A are denoted by subscript
notation A 1 , A 2 , A 3 . . . . A n
or by the parenthesis notation A (1), A (2), A (3) . . . . . . A (n)
or by the bracket notation A [1], A [2], A [3] . . . . . . A [n]
Example:
A linear array A[8] consisting of numbers is pictured in following figure
20
Data Structures and Algorithms
Linked List
©SMT, Faculty, CSE, IUBAT
A linked list, or one way list is a linear collection of data elements,
called nodes, where the linear order is given by means of pointers. Each
node is divided into two parts:
The first part contains the information of the element/node
The second part contains the address of the next node (link /next
pointer field) in the list.
There is a special pointer Start/List contains the address of first node in the
list. If this special pointer contains null, means that List is empty.
21
Data Structures and Algorithms
Array of Linked Lists
©SMT, Faculty, CSE, IUBAT
Suppose we allow arbitrary
relations between any two
objects in a container
 Alternatively, we could use
a hybrid: an array of
linked lists
A
B
C
D
E
F
G
H
I
J
K
L
2.2.2.2
22
Data Structures and Algorithms
Queue and Stack
©SMT, Faculty, CSE, IUBAT
Queue:
A queue, also called FIFO system, is a linear list in which deletions can take
place only at one end of the list, the Font of the list and insertion can take
place only at the other end Rear.
Stack:
It is an ordered group of homogeneous items of elements. Elements are added
to and removed from the top of the stack (the most recently added items are
at the top of the stack). The last element to be added is the first to be
removed (LIFO: Last In, First Out).
23
Data Structures and Algorithms
Data Structures Operations
©SMT, Faculty, CSE, IUBAT
The data appearing in our data structures are processed by means of certain
operations. In fact, the particular data structure that one chooses for a
given situation depends largely in the frequency with which specific
operations are performed.
The following four operations play a major role in this text:
 Traversing: accessing each record/node exactly once so that certain items
in the record may be processed. (This accessing and processing is
sometimes called “visiting” the record.)
24
Data Structures and Algorithms
Data Structures Operations
©SMT, Faculty, CSE, IUBAT
 Searching: Finding the location of the desired node with a given key
value,
or finding the locations of all such nodes which satisfy one or more conditions.
 Inserting: Adding a new node/record to the structure.
 Deleting: Removing a node/record from the structure.

More Related Content

What's hot

Linklist
LinklistLinklist
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)
Elavarasi K
 
Data structures using c
Data structures using cData structures using c
Data structures using c
Prof. Dr. K. Adisesha
 
Introduction to Data Abstraction
Introduction to Data AbstractionIntroduction to Data Abstraction
Introduction to Data Abstraction
Dennis Gajo
 
6. Linked list - Data Structures using C++ by Varsha Patil
6. Linked list - Data Structures using C++ by Varsha Patil6. Linked list - Data Structures using C++ by Varsha Patil
6. Linked list - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
RJ Mehul Gadhiya
 
Application of Data structure
Application of Data structureApplication of Data structure
Application of Data structure
Deepika051991
 
Database : Relational Data Model
Database : Relational Data ModelDatabase : Relational Data Model
Database : Relational Data Model
Smriti Jain
 
NOSQL- Presentation on NoSQL
NOSQL- Presentation on NoSQLNOSQL- Presentation on NoSQL
NOSQL- Presentation on NoSQL
Ramakant Soni
 
Data structures in Python
Data structures in PythonData structures in Python
Data structures in Python
MITULJAMANG
 
Page replacement algorithms
Page replacement algorithmsPage replacement algorithms
Page replacement algorithms
sangrampatil81
 
Abstract Data Types
Abstract Data TypesAbstract Data Types
Abstract Data Types
karthikeyanC40
 
Cookies in servlet
Cookies in servletCookies in servlet
Cookies in servlet
chauhankapil
 
Sql
SqlSql
SQL Tutorial for BCA-2
SQL Tutorial for BCA-2SQL Tutorial for BCA-2
SQL Tutorial for BCA-2
Raj vardhan
 
Indexing and hashing
Indexing and hashingIndexing and hashing
Indexing and hashingJeet Poria
 
file system in operating system
file system in operating systemfile system in operating system
file system in operating systemtittuajay
 
11. Storage and File Structure in DBMS
11. Storage and File Structure in DBMS11. Storage and File Structure in DBMS
11. Storage and File Structure in DBMSkoolkampus
 
Segmentation in Operating Systems.
Segmentation in Operating Systems.Segmentation in Operating Systems.
Segmentation in Operating Systems.
Muhammad SiRaj Munir
 
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)
Tasif Tanzim
 

What's hot (20)

Linklist
LinklistLinklist
Linklist
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)
 
Data structures using c
Data structures using cData structures using c
Data structures using c
 
Introduction to Data Abstraction
Introduction to Data AbstractionIntroduction to Data Abstraction
Introduction to Data Abstraction
 
6. Linked list - Data Structures using C++ by Varsha Patil
6. Linked list - Data Structures using C++ by Varsha Patil6. Linked list - Data Structures using C++ by Varsha Patil
6. Linked list - Data Structures using C++ by Varsha Patil
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
 
Application of Data structure
Application of Data structureApplication of Data structure
Application of Data structure
 
Database : Relational Data Model
Database : Relational Data ModelDatabase : Relational Data Model
Database : Relational Data Model
 
NOSQL- Presentation on NoSQL
NOSQL- Presentation on NoSQLNOSQL- Presentation on NoSQL
NOSQL- Presentation on NoSQL
 
Data structures in Python
Data structures in PythonData structures in Python
Data structures in Python
 
Page replacement algorithms
Page replacement algorithmsPage replacement algorithms
Page replacement algorithms
 
Abstract Data Types
Abstract Data TypesAbstract Data Types
Abstract Data Types
 
Cookies in servlet
Cookies in servletCookies in servlet
Cookies in servlet
 
Sql
SqlSql
Sql
 
SQL Tutorial for BCA-2
SQL Tutorial for BCA-2SQL Tutorial for BCA-2
SQL Tutorial for BCA-2
 
Indexing and hashing
Indexing and hashingIndexing and hashing
Indexing and hashing
 
file system in operating system
file system in operating systemfile system in operating system
file system in operating system
 
11. Storage and File Structure in DBMS
11. Storage and File Structure in DBMS11. Storage and File Structure in DBMS
11. Storage and File Structure in DBMS
 
Segmentation in Operating Systems.
Segmentation in Operating Systems.Segmentation in Operating Systems.
Segmentation in Operating Systems.
 
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)
 

Viewers also liked

Webpage Visual Design and Online Prototype
Webpage Visual Design and Online PrototypeWebpage Visual Design and Online Prototype
Webpage Visual Design and Online Prototype
amoore155
 
Chapter 3.1
Chapter 3.1Chapter 3.1
Chapter 3.1sotlsoc
 
Basics in algorithms and data structure
Basics in algorithms and data structure Basics in algorithms and data structure
Basics in algorithms and data structure Eman magdy
 
Chapter 7.4
Chapter 7.4Chapter 7.4
Chapter 7.4sotlsoc
 
Logic Formulation 2
Logic Formulation 2Logic Formulation 2
Logic Formulation 2
deathful
 
Digital Logic
Digital LogicDigital Logic
Digital Logic
Dilum Bandara
 
Problem Solving with Algorithms and Data Structure - Lists
Problem Solving with Algorithms and Data Structure - ListsProblem Solving with Algorithms and Data Structure - Lists
Problem Solving with Algorithms and Data Structure - Lists
Yi-Lung Tsai
 
Problem Solving with Algorithms and Data Structure - Graphs
Problem Solving with Algorithms and Data Structure - GraphsProblem Solving with Algorithms and Data Structure - Graphs
Problem Solving with Algorithms and Data Structure - Graphs
Yi-Lung Tsai
 
Komunikasyon
KomunikasyonKomunikasyon
Komunikasyon
deathful
 
Data Structure & Algorithms | Computer Science
Data Structure & Algorithms | Computer ScienceData Structure & Algorithms | Computer Science
Data Structure & Algorithms | Computer Science
Transweb Global Inc
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
Julie Iskander
 
មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++
Ngeam Soly
 
Program logic formulation
Program logic formulationProgram logic formulation
Program logic formulationSara Corpuz
 

Viewers also liked (15)

Webpage Visual Design and Online Prototype
Webpage Visual Design and Online PrototypeWebpage Visual Design and Online Prototype
Webpage Visual Design and Online Prototype
 
Chapter 3.1
Chapter 3.1Chapter 3.1
Chapter 3.1
 
Basics in algorithms and data structure
Basics in algorithms and data structure Basics in algorithms and data structure
Basics in algorithms and data structure
 
Chapter 7.4
Chapter 7.4Chapter 7.4
Chapter 7.4
 
Logic Formulation 2
Logic Formulation 2Logic Formulation 2
Logic Formulation 2
 
Chap 2(const var-datatype)
Chap 2(const var-datatype)Chap 2(const var-datatype)
Chap 2(const var-datatype)
 
2. electric field calculation
2. electric field calculation2. electric field calculation
2. electric field calculation
 
Digital Logic
Digital LogicDigital Logic
Digital Logic
 
Problem Solving with Algorithms and Data Structure - Lists
Problem Solving with Algorithms and Data Structure - ListsProblem Solving with Algorithms and Data Structure - Lists
Problem Solving with Algorithms and Data Structure - Lists
 
Problem Solving with Algorithms and Data Structure - Graphs
Problem Solving with Algorithms and Data Structure - GraphsProblem Solving with Algorithms and Data Structure - Graphs
Problem Solving with Algorithms and Data Structure - Graphs
 
Komunikasyon
KomunikasyonKomunikasyon
Komunikasyon
 
Data Structure & Algorithms | Computer Science
Data Structure & Algorithms | Computer ScienceData Structure & Algorithms | Computer Science
Data Structure & Algorithms | Computer Science
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++
 
Program logic formulation
Program logic formulationProgram logic formulation
Program logic formulation
 

Similar to Data Structure Basics

2.02.Data_structures_and_algorithms (1).pptx
2.02.Data_structures_and_algorithms (1).pptx2.02.Data_structures_and_algorithms (1).pptx
2.02.Data_structures_and_algorithms (1).pptx
DrBashirMSaad
 
DS_PPT.ppt
DS_PPT.pptDS_PPT.ppt
DS_PPT.ppt
MeghaKulkarni27
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pd
Nimmi Weeraddana
 
DATA STRUCTURES - SHORT NOTES
DATA STRUCTURES - SHORT NOTESDATA STRUCTURES - SHORT NOTES
DATA STRUCTURES - SHORT NOTES
suthi
 
Introduction to Data Structure.pptx
Introduction to Data Structure.pptxIntroduction to Data Structure.pptx
Introduction to Data Structure.pptx
GlenardDSarmiento
 
UNITIII LDS.pdf
UNITIII LDS.pdfUNITIII LDS.pdf
UNITIII LDS.pdf
meenamadhuvandhi2
 
Introduction to data structure ppt
Introduction to data structure pptIntroduction to data structure ppt
Introduction to data structure ppt
NalinNishant3
 
Chapter 1 Introduction to Data Structures and Algorithms.pdf
Chapter 1 Introduction to Data Structures and Algorithms.pdfChapter 1 Introduction to Data Structures and Algorithms.pdf
Chapter 1 Introduction to Data Structures and Algorithms.pdf
Axmedcarb
 
Datastructures using c++
Datastructures using c++Datastructures using c++
Datastructures using c++
Gopi Nath
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
SaralaT3
 
Introduction to Data Structures .
Introduction to Data Structures        .Introduction to Data Structures        .
Introduction to Data Structures .
Ashutosh Satapathy
 
DATA STRUCTURE IN C LANGUAGE
DATA STRUCTURE IN C LANGUAGEDATA STRUCTURE IN C LANGUAGE
DATA STRUCTURE IN C LANGUAGE
shubhamrohiwal6
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
sarala9
 
Data structure (basics)
Data structure (basics)Data structure (basics)
Data structure (basics)
ShrushtiGole
 
Data Structures & Recursion-Introduction.pdf
Data Structures & Recursion-Introduction.pdfData Structures & Recursion-Introduction.pdf
Data Structures & Recursion-Introduction.pdf
MaryJacob24
 
Data structure
Data structureData structure
Data structure
Gaurav Handge
 
Data Structures and algoithms Unit - 1.pptx
Data Structures and algoithms Unit - 1.pptxData Structures and algoithms Unit - 1.pptx
Data Structures and algoithms Unit - 1.pptx
mexiuro901
 
DATA STRUCTURE AND ALGORITHMS
DATA STRUCTURE AND ALGORITHMS DATA STRUCTURE AND ALGORITHMS
DATA STRUCTURE AND ALGORITHMS
Adams Sidibe
 
Introduction to Data Structure
Introduction to Data StructureIntroduction to Data Structure
Introduction to Data StructureJazz Jinia Bhowmik
 
2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdf2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdf
SulabhPawaia
 

Similar to Data Structure Basics (20)

2.02.Data_structures_and_algorithms (1).pptx
2.02.Data_structures_and_algorithms (1).pptx2.02.Data_structures_and_algorithms (1).pptx
2.02.Data_structures_and_algorithms (1).pptx
 
DS_PPT.ppt
DS_PPT.pptDS_PPT.ppt
DS_PPT.ppt
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pd
 
DATA STRUCTURES - SHORT NOTES
DATA STRUCTURES - SHORT NOTESDATA STRUCTURES - SHORT NOTES
DATA STRUCTURES - SHORT NOTES
 
Introduction to Data Structure.pptx
Introduction to Data Structure.pptxIntroduction to Data Structure.pptx
Introduction to Data Structure.pptx
 
UNITIII LDS.pdf
UNITIII LDS.pdfUNITIII LDS.pdf
UNITIII LDS.pdf
 
Introduction to data structure ppt
Introduction to data structure pptIntroduction to data structure ppt
Introduction to data structure ppt
 
Chapter 1 Introduction to Data Structures and Algorithms.pdf
Chapter 1 Introduction to Data Structures and Algorithms.pdfChapter 1 Introduction to Data Structures and Algorithms.pdf
Chapter 1 Introduction to Data Structures and Algorithms.pdf
 
Datastructures using c++
Datastructures using c++Datastructures using c++
Datastructures using c++
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
 
Introduction to Data Structures .
Introduction to Data Structures        .Introduction to Data Structures        .
Introduction to Data Structures .
 
DATA STRUCTURE IN C LANGUAGE
DATA STRUCTURE IN C LANGUAGEDATA STRUCTURE IN C LANGUAGE
DATA STRUCTURE IN C LANGUAGE
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
 
Data structure (basics)
Data structure (basics)Data structure (basics)
Data structure (basics)
 
Data Structures & Recursion-Introduction.pdf
Data Structures & Recursion-Introduction.pdfData Structures & Recursion-Introduction.pdf
Data Structures & Recursion-Introduction.pdf
 
Data structure
Data structureData structure
Data structure
 
Data Structures and algoithms Unit - 1.pptx
Data Structures and algoithms Unit - 1.pptxData Structures and algoithms Unit - 1.pptx
Data Structures and algoithms Unit - 1.pptx
 
DATA STRUCTURE AND ALGORITHMS
DATA STRUCTURE AND ALGORITHMS DATA STRUCTURE AND ALGORITHMS
DATA STRUCTURE AND ALGORITHMS
 
Introduction to Data Structure
Introduction to Data StructureIntroduction to Data Structure
Introduction to Data Structure
 
2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdf2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdf
 

More from Shakila Mahjabin

Computer processing
Computer processingComputer processing
Computer processing
Shakila Mahjabin
 
Arrays in CPP
Arrays in CPPArrays in CPP
Arrays in CPP
Shakila Mahjabin
 
CSC 433 Sample normalization SQL Question
CSC 433 Sample normalization SQL QuestionCSC 433 Sample normalization SQL Question
CSC 433 Sample normalization SQL Question
Shakila Mahjabin
 
SQL : introduction
SQL : introductionSQL : introduction
SQL : introduction
Shakila Mahjabin
 
Normalization
NormalizationNormalization
Normalization
Shakila Mahjabin
 
Solution of Erds
Solution of ErdsSolution of Erds
Solution of Erds
Shakila Mahjabin
 
Entity Relationship Diagram
Entity Relationship DiagramEntity Relationship Diagram
Entity Relationship Diagram
Shakila Mahjabin
 
Ch1- Introduction to dbms
Ch1- Introduction to dbmsCh1- Introduction to dbms
Ch1- Introduction to dbms
Shakila Mahjabin
 
Stack and queue
Stack and queueStack and queue
Stack and queue
Shakila Mahjabin
 
Algo analysis
Algo analysisAlgo analysis
Algo analysis
Shakila Mahjabin
 
Merge sort and quick sort
Merge sort and quick sortMerge sort and quick sort
Merge sort and quick sort
Shakila Mahjabin
 
Codes on structures
Codes on structuresCodes on structures
Codes on structures
Shakila Mahjabin
 
Arrays
ArraysArrays
array, function, pointer, pattern matching
array, function, pointer, pattern matchingarray, function, pointer, pattern matching
array, function, pointer, pattern matching
Shakila Mahjabin
 
String operation
String operationString operation
String operation
Shakila Mahjabin
 

More from Shakila Mahjabin (15)

Computer processing
Computer processingComputer processing
Computer processing
 
Arrays in CPP
Arrays in CPPArrays in CPP
Arrays in CPP
 
CSC 433 Sample normalization SQL Question
CSC 433 Sample normalization SQL QuestionCSC 433 Sample normalization SQL Question
CSC 433 Sample normalization SQL Question
 
SQL : introduction
SQL : introductionSQL : introduction
SQL : introduction
 
Normalization
NormalizationNormalization
Normalization
 
Solution of Erds
Solution of ErdsSolution of Erds
Solution of Erds
 
Entity Relationship Diagram
Entity Relationship DiagramEntity Relationship Diagram
Entity Relationship Diagram
 
Ch1- Introduction to dbms
Ch1- Introduction to dbmsCh1- Introduction to dbms
Ch1- Introduction to dbms
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Algo analysis
Algo analysisAlgo analysis
Algo analysis
 
Merge sort and quick sort
Merge sort and quick sortMerge sort and quick sort
Merge sort and quick sort
 
Codes on structures
Codes on structuresCodes on structures
Codes on structures
 
Arrays
ArraysArrays
Arrays
 
array, function, pointer, pattern matching
array, function, pointer, pattern matchingarray, function, pointer, pattern matching
array, function, pointer, pattern matching
 
String operation
String operationString operation
String operation
 

Recently uploaded

The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 

Recently uploaded (20)

The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 

Data Structure Basics

  • 2. 2 Data Structures and Algorithms Data Structure ©SMT, Faculty, CSE, IUBAT In computer science, a data structure is a particular way of storing and organizing data in a computer’s memory so that it can be used efficiently. Data may be organized in many different ways. The logical or mathematical model of a particular organization of data is called a data structure.
  • 3. 3 Data Structures and Algorithms Types Categories of Data Structure: The data structure can be classified in to major types: • Linear Data Structure • Non-linear Data Structure 1. Linear Data Structure: A data structure is said to be linear if its elements form any sequence. There are basically two ways of representing such linear structure in memory. a) One way is to have the linear relationships between the elements represented by means of sequential memory location. These linear structures are called arrays. b) The other way is to have the linear relationship between the elements represented by means of pointers or links. These linear structures are called linked lists. ©SMT, Faculty, CSE, IUBAT
  • 4. 4 Data Structures and Algorithms The common examples of linear data structure are- Arrays, Queues, Stacks, Linked lists 2. Non-linear Data Structure: This structure is mainly used to represent data containing a hierarchical relationship between elements. e.g. graphs, family trees and table of contents. Types ©SMT, Faculty, CSE, IUBAT
  • 5. 5 Data Structures and Algorithms Memory Allocation ©SMT, Faculty, CSE, IUBAT Memory allocation can be classified as either  Contiguous  Linked  Indexed Prototypical examples:  Contiguous allocation: arrays  Linked allocation: linked lists
  • 6. 6 Data Structures and Algorithms Contiguous Allocation ©SMT, Faculty, CSE, IUBAT An array stores n objects in a single contiguous space of memory Unfortunately, if more memory is required, a request for new memory usually requires copying all information into the new memory  In general, you cannot request for the operating system to allocate to you the next n memory locations
  • 7. 7 Data Structures and Algorithms Linked Allocation ©SMT, Faculty, CSE, IUBAT Linked storage such as a linked list associates two pieces of data with each item being stored:  The object itself, and  A reference to the next item  In C++ that reference is the address of the next node
  • 8. 8 Data Structures and Algorithms Linked Allocation ©SMT, Faculty, CSE, IUBAT This is a class describing such a node template <typename Type> class Node { private: Type element; Node *next_node; public: // ... };
  • 9. 9 Data Structures and Algorithms Linked Allocation ©SMT, Faculty, CSE, IUBAT The operations on this node must include:  Constructing a new node  Accessing (retrieving) the value  Accessing the next pointer Node( const Type& = Type(), Node* = nullptr ); Type retrieve() const; Node *next() const; Pointing to nothing has been represented as: C NULL Java/C# null C++ (old) 0 C++ (new) nullptr Symbolically Ø
  • 10. 10 Data Structures and Algorithms Linked Allocation ©SMT, Faculty, CSE, IUBAT For a linked list, however, we also require an object which links to the first object The actual linked list class must store two pointers  A head and tail: Node *head; Node *tail; Optionally, we can also keep a count int count; The next_node of the last node is assigned nullptr
  • 11. 11 Data Structures and Algorithms Linked Allocation ©SMT, Faculty, CSE, IUBAT The class structure would be: template <typename Type> class List { private: Node<Type> *head; Node<Type> *tail; int count; public: // constructor(s)... // accessor(s)... // mutator(s)... };
  • 12. 12 Data Structures and Algorithms Indexed Allocation ©SMT, Faculty, CSE, IUBAT With indexed allocation, an array of pointers (possibly NULL) link to a sequence of allocated memory locations Used in the C++ standard template library Computer engineering students will see indexed allocation in their operating systems course
  • 13. 13 Data Structures and Algorithms Indexed Allocation ©SMT, Faculty, CSE, IUBAT Matrices can be implemented using indexed allocation: 1 2 3 4 5 6      
  • 14. 14 Data Structures and Algorithms Indexed Allocation ©SMT, Faculty, CSE, IUBAT Matrices can be implemented using indexed allocation  Most implementations of matrices (or higher-dimensional arrays) use indices pointing into a single contiguous block of memory Row-major order Column-major order C, Python Matlab, Fortran 1 2 3 4 5 6      
  • 15. 15 Data Structures and Algorithms Data Structure Formats ©SMT, Faculty, CSE, IUBAT We will look at some variations or hybrids of these memory allocations including:  Trees  Graphs  Array  Linked List  Stack  Queue
  • 16. 16 Data Structures and Algorithms Trees ©SMT, Faculty, CSE, IUBAT The linked list can be used to store linearly ordered data  What if we have multiple next pointers? A rooted tree (weeks 4-6) is similar to a linked list but with multiple next pointers
  • 17. 17 Data Structures and Algorithms Trees ©SMT, Faculty, CSE, IUBAT Data frequently contain a hierarchical relationship between various elements. The data structure which reflects this relationship is called a rooted tree graph or, simply, a tree. A tree is a variation on a linked list:  Each node points to an arbitrary number of subsequent nodes  Useful for storing hierarchical data 2.2.2.2
  • 18. 18 Data Structures and Algorithms Graphs ©SMT, Faculty, CSE, IUBAT Suppose we allow arbitrary relations between any two objects in a container  Given n objects, there are n2 – n possible relations  If we allow symmetry, this reduces to  For example, consider the network 2 2 n n 2.2.2.2 Data sometimes contains a relationship between pairs of elements which is not necessarily hierarchical in nature, e.g. an airline flights only between the cities connected by lines. This data structure is called Graph.
  • 19. 19 Data Structures and Algorithms Arrays ©SMT, Faculty, CSE, IUBAT 2.2.2.2 The simplest type of data structure is a linear (or one dimensional) array. A list of a finite number n of similar data referenced respectively by a set of n consecutive numbers, usually 1, 2, 3 . . . . . . . n. if we choose the name A for the array, then the elements of A are denoted by subscript notation A 1 , A 2 , A 3 . . . . A n or by the parenthesis notation A (1), A (2), A (3) . . . . . . A (n) or by the bracket notation A [1], A [2], A [3] . . . . . . A [n] Example: A linear array A[8] consisting of numbers is pictured in following figure
  • 20. 20 Data Structures and Algorithms Linked List ©SMT, Faculty, CSE, IUBAT A linked list, or one way list is a linear collection of data elements, called nodes, where the linear order is given by means of pointers. Each node is divided into two parts: The first part contains the information of the element/node The second part contains the address of the next node (link /next pointer field) in the list. There is a special pointer Start/List contains the address of first node in the list. If this special pointer contains null, means that List is empty.
  • 21. 21 Data Structures and Algorithms Array of Linked Lists ©SMT, Faculty, CSE, IUBAT Suppose we allow arbitrary relations between any two objects in a container  Alternatively, we could use a hybrid: an array of linked lists A B C D E F G H I J K L 2.2.2.2
  • 22. 22 Data Structures and Algorithms Queue and Stack ©SMT, Faculty, CSE, IUBAT Queue: A queue, also called FIFO system, is a linear list in which deletions can take place only at one end of the list, the Font of the list and insertion can take place only at the other end Rear. Stack: It is an ordered group of homogeneous items of elements. Elements are added to and removed from the top of the stack (the most recently added items are at the top of the stack). The last element to be added is the first to be removed (LIFO: Last In, First Out).
  • 23. 23 Data Structures and Algorithms Data Structures Operations ©SMT, Faculty, CSE, IUBAT The data appearing in our data structures are processed by means of certain operations. In fact, the particular data structure that one chooses for a given situation depends largely in the frequency with which specific operations are performed. The following four operations play a major role in this text:  Traversing: accessing each record/node exactly once so that certain items in the record may be processed. (This accessing and processing is sometimes called “visiting” the record.)
  • 24. 24 Data Structures and Algorithms Data Structures Operations ©SMT, Faculty, CSE, IUBAT  Searching: Finding the location of the desired node with a given key value, or finding the locations of all such nodes which satisfy one or more conditions.  Inserting: Adding a new node/record to the structure.  Deleting: Removing a node/record from the structure.