Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

DBMS notes B.tech students, Schemes and Mind Maps of Database Management Systems (DBMS)

DBMS NOtes for b.tech students. They can refer for the exam.

Typology: Schemes and Mind Maps

2022/2023

Uploaded on 01/04/2023

AshwaniKumarcse
AshwaniKumarcse 🇮🇳

5

(1)

3 documents

1 / 153

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
DATA STRUCTURES
[R18A0503]
LECTURE NOTES
B.TECH II YEAR – I SEM (R18)
(2019-2020)
MALLA REDDY COLLEGE OF ENGINEERING &
TECHNOLOGY
(Autonomous Institution – UGC, Govt. of India)
Recognized under 2(f) and 12 (B) of UGC ACT 1956
(Affiliated to JNTUH, Hyderabad, Approved by AICTE - Accredited by NBA & NAAC – ‘A’ Grade - ISO 9001:2015 Certified)
Maisammaguda, Dhulapally (Post Via. Hakimpet), Secunderabad – 500100, Telangana State, India
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download DBMS notes B.tech students and more Schemes and Mind Maps Database Management Systems (DBMS) in PDF only on Docsity!

DATA STRUCTURES

[R18A0503]

LECTURE NOTES

B.TECH II YEAR – I SEM (R18)

MALLA REDDY COLLEGE OF ENGINEERING &

TECHNOLOGY

(Autonomous Institution – UGC, Govt. of India)

Recognized under 2(f) and 12 (B) of UGC ACT 1956

(Affiliated to JNTUH, Hyderabad, Approved by AICTE - Accredited by NBA & NAAC – ‘A’ Grade - ISO 9001:2015 Certified)

Maisammaguda, Dhulapally (Post Via. Hakimpet), Secunderabad – 500100, Telangana State, India

MALLA REDDY COLLEGE OF ENGINEERING AND TECHNOLOGY

L T/P/D C

II Year B.Tech CSE - I Sem 3-/-/-

(R18A0503) DATA STRUCTURES

Prerequisites: A course on ―Programming for Problem Solving‖.

Course Objectives:

 To impart the basic concepts of data structures

 Exploring basic data structures such as stacks queues and lists.

 Introduces a variety of data structures such as hash tables, search trees, heaps, graphs.

 To understand concepts about searching and sorting techniques

UNIT-I

Introduction : Abstract data types, Singly linked list: Definition, operations: Traversing,

Searching, Insertion and deletion, Doubly linked list: Definition, operations: Traversing,

Searching, Insertion and deletion ,Circular Linked List: Definition, operations: Traversing,

Searching, Insertion and deletion.

UNIT-II

Stack: Stack ADT, array and linked list implementation, Applications- expression conversion

and evaluation. Queue : Types of Queue: Simple Queue, Circular Queue, Queue ADT- array

and linked list implementation. Priority Queue, heaps.

UNIT-III

Searching: Linear and binary search methods. Sorting: Selection Sort, Bubble Sort, Insertion

Sort, Quick Sort, Merge Sort, Heap Sort. Time Complexities .Graphs: Basic terminology,

representation of graphs, graph traversal methods DFS,BFS

UNIT IV

Dictionaries: linear list representation, skip list representation, operations - insertion, deletion

and searching. Hash Table Representation: hash functions, collision resolution- separate

chaining, open addressing-linear probing, quadratic probing, double hashing, rehashing,

extendible hashing.

UNIT-V

Binary Search Trees: Various Binary tree representation, definition, BST ADT,

Implementation, Operations- Searching, Insertion and Deletion, Binary tree traversals,

threaded binary trees,

AVL Trees :Definition, Height of an AVL Tree, Operations – Insertion, Deletion and

Searching, B-Trees: B-Tree of order m, height of a B-Tree, insertion, deletion and searching,

B+ Tree.

INDEX

S.No Topic Page

  • 1.1 Introduction UNIT-I
  • 1.2 Singly linked list
  • 1.3 Doubly linked list
  • 1.4 Circular Linked List
  • 2.1 Stack ADT UNIT-II
  • 2.2 Array implementation
  • 2.3 linked list implementation
  • 2.4 Queue ADT
  • 2.5 Array implementation
  • 2.6 linked list implementation
  • 2.7 Circular Queue
  • 2.8 Priority Queue
  • 2.9 Heaps
  • 3.1 Searching: Linear Search UNIT-III
  • 3.2 Binary search
  • 3.3 Sorting: Bubble Sort
  • 3.4 Selection Sort
  • 3.5 Insertion Sort
  • 3.6 Quick Sort
  • 3.7 Merge Sort
  • 3.8 Heap Sort
  • 3.9 Time Complexities
  • 3.10 Graphs: Basic terminology
  • 3.11 Representation of graphs
  • 3.12 Graph traversal methods
  • 4.1 Dictionaries: linear list representation UNIT-IV
  • 4.2 Skip list representation
  • 4.3 Hash Table Representation
  • 4.4 Rehashing,
  • 4.5 Extendible hashing
  • 5.1 Binary Search Trees: Basics UNIT-V
  • 5.2 Binary tree traversals
  • 5.3 Binary Search Tree
  • 5.4 AVL Trees
  • 5.5 B-Trees
  • 5.6 B+ Tree

Data structure A data structure is a specialized format for organizing and storing data.

General data structure types include the array, the file, the record, the table, the tree, and so on.

Any data structure is designed to organize data to suit a specific purpose so that it can be accessed

and worked with in appropriate ways

Abstract Data Type

In computer science, an abstract data type (ADT) is a mathematical model for data types

where a data type is defined by its behavior (semantics) from the point of view of a user

of the data, specifically in terms of possible values, possible operations on data of this type,

and the behavior of these operations. When a class is used as a type, it is an abstract type that

refers to a hidden representation. In this model an ADT is typically implemented as a class, and

each instance of the ADT is usually a n object of that class.

In ADT all the implementation details are hidden

 Linear data structures are the data structures in which data is arranged in a list or in a

sequence.

 Non linear data structures are the data structures in which data may be arranged in a

hierarchic al manner

LIST ADT

List is basically the collection of elements arrange d in a sequential manner. In memory

we can store the list in two ways: one way is we can store the elements in sequential

memory locations. That means we can store the list in arrays.

The other way is we can use pointers or links to associate elements sequentially.

This is known as linked list.

LINKED LISTS

The linked list is very different type of collection from an array. Using such lists, we can

store collections of information limited only by the total amount of memory that the OS will allow

us to use.Further more, there is no need to specify our needs in advance. The linked list is very

flexible dynamic data structure : items may be added to it or deleted from it at will. A programmer

need not worry about how many items a program will have to accommodate in advance. This

allows us to write robust programs which require much less maintenance.

Introduction: Abstract data types, Singly linked list: Definition, operations: Traversing, Searching,

Insertion and deletion, Doubly linked list: Definition, operations: Traversing, Searching, Insertion and

deletion, Circular Linked List: Definition, operations: Traversing, Searching, Insertion and deletion

temp->link=head;

head=temp;

Insertions: To place an elements in the list there are 3 cases :

  1. At the beginning
  2. End of the list
  3. At a given position

case 1:Insert at the beginning

temp

head is the pointer variable which contains address of the first node and temp contains address of

new node to be inserted then sample code is

After insertion:

Code for insert front:-

template

void list::insert_front()

struct node t,temp;

cout<<"Enter data into node:";

cin>>item;

temp=create_node(item);

if(head==NULL)

head=temp;

else

{ temp->link=head;

head=temp;

t=head;

while(t->link!=NULL)

t=t->link;

t->link=temp;

case 2:Inserting end of the list

temp

head is the pointer variable which contains address of the first node and temp contains address of new

node to be inserted then sample code is

After insertion the linked list is

Code for insert End:-

template

void list::insert_end()

struct node t,temp;

int n;

cout<<"Enter data into node:";

cin>>n;

temp=create_node(n);

if(head==NULL)

head=temp;

else

{ t=head;

while(t->link!=NULL)

t=t->link;

t->link=temp;

t=head;

head=head->link;

cout<<"node "<<t->data<<" Deletion is sucess";

delete(t);

head=temp;

else

while(c<pos)

{ c++;

prev=cur;

cur=cur->link;

prev->link=temp;

temp->link=cur;

Deletions: Removing an element from the list, without destroying the integrity of the list itself.

To place an element from the list there are 3 cases :

  1. Delete a node at beginning of the list
  2. Delete a node at end of the list
  3. Delete a node at a given position

Case 1: Delete a node at beginning of the list

head

head is the pointer variable which contains address of the first node

sample code is

head

code for deleting a node at front

template

void list::delete_front()

struct node*t;

if(head==NULL)

cout<<"List is Empty\n";

else

{ t=head;

struct nodecur,prev;

cur=prev=head;

while(cur->link!=NULL)

{ prev=cur;

cur=cur->link;

prev->link=NULL;

cout<<"node "<<cur->data<<" Deletion is sucess";

free(cur);

head=head->link;

cout<<"node "<<t->data<<" Deletion is sucess";

delete(t);

Case 2. Delete a node at end of the list

head

To delete last node , find the node using following code

head

code for deleting a node at end of the list

template

void list::delete_end()

struct nodecur,prev;

cur=prev=head;

if(head==NULL)

cout<<"List is Empty\n";

else

{ cur=prev=head;

if(head->link==NULL)

cout<<"node "<<cur->data<<" Deletion is sucess";

free(cur);

head=NULL;

Dynamic Implementation of list ADT

Traversing the list: Assuming we are given the pointer to the head of the list, how do we get the end

of the list.

template

void list:: display()

struct node*t;

if(head==NULL)

cout<<"List is Empty\n";

else

{ t=head;

while(t!=NULL)

{ cout<<t->data<<"->";

t=t->link;

#include<iostream.h>

#include<stdlib.h>

template

struct node

T data;

struct node *link;

template

class list

int item;

struct node*head;

public:

list();

void display();

struct node*create_node(int n);

void insert_end();

void insert_front();

void Insert_at_pos(int pos);

void delete_end();

void delete_front();

void Delete_at_pos(int pos);

void Node_count();

template

list::list()

head=NULL;

template

void list:: display()

struct node*t;

if(head==NULL)

cout<<"List is Empty\n";

else

{ t=head;

while(t!=NULL)

{ cout<<t->data<<"->";

t=t->link;

template

struct node* list::create_node(int n)

{struct node *t;

t=new struct node;

t->data=n;

t->link=NULL;

return t;

template

void list::insert_end()

{struct node t,temp;

int n;

cout<<"Enter data into node:";

cin>>n;

temp=create_node(n);

if(head==NULL)

head=temp;

else

{ t=head;

while(t->link!=NULL)

t=t->link;

t->link=temp;

cout<<"node "<<t->data<<" Deletion is sucess";

delete(t);

template

void list::Node_count()

struct node*t;

int c=0;

t=head;

if(head==NULL)

cout<<"List is Empty\n";

else

{ while(t!=NULL)

{ c++;

t=t->link;

cout<<"Node Count="<<c<<endl;

template

void list::Insert_at_pos(int pos)

{struct nodecur,prev,*temp;

int c=1;

cout<<"Enter data into node:";

cin>>item

temp=create_node(item);

if(head==NULL)

head=temp;

else

{ prev=cur=head;

if(pos==1)

else

temp->link=head;

head=temp;

while(c<pos)

{ c++;

prev=cur;

cur=cur->link;

prev->link=temp;

temp->link=cur;

template

void list::Delete_at_pos(int pos)

struct nodecur,prev,*temp;

int c=1;

if(head==NULL)

cout<<"List is Empty\n";

else

{ prev=cur=head;

if(pos==1)

head=head->link;

cout<<cur->data <<"is deleted sucesfully";

delete cur;

else

while(c<pos)

{ c++;

prev=cur;

cur=cur->link;

prev->link=cur->link;

cout<<cur->data <<"is deleted sucesfully";

delete cur;

int main()

int ncount,ch,pos;

list L;

while(1)

cout<<"\n Operations on Linked List"<<endl;

cout<<"\n1.Insert node at End"<<endl;

cout<<"2.Insert node at Front"<<endl;

cout<<"3.Delete node at END"<<endl;

cout<<"4.Delete node at Front"<<endl;

cout<<"5.Insert at a position "<<endl;

cout<<"6.Delete at a position "<<endl;

cout<<"7.Node Count"<<endl;

cout<<"8.Display nodes "<<endl;

cout<<"9.Clear Screen "<<endl;

NULL 20 30 NULL 10

Implementation of node using structure

Method -1:

struct node

int data;

struct node *prev;

struct node * next;

Implementation of node using class

Method -2:

class node

public:

int data;

node *prev;

node * next;

Operations on Doubly linked list:

 Insertion of a node

 Deletions of a node

 Traversing the list

Doubly linked list ADT:

template

class dlist

public:

int data;

struct dnode*head;

dlist()

head=NULL;

void display();

struct dnode*create_dnode(int n);

void insert_end();

void insert_front();

void delete_end();

void delete_front();

void dnode_count();

NULL 40 NULL

NULL 10

20 30 NULL

head

temp

20 30 NULL

head

void Insert_at_pos(int pos);

void Delete_at_pos(int pos);

Insertions: To place an elements in the list there are 3 cases

 1. At the beginning

 2. End of the list

 3. At a given position

case 1:Insert at the beginning

head is the pointer variable which contains address of the first node and temp contains address of new

node to be inserted then sample code is

Code for insert front:-

template

void DLL::insert_front()

struct dnode t,temp;

cout<<"Enter data into node:";

cin>>data;

temp=create_dnode(data);

if(head==NULL)

head=temp;

else

{ temp->next=head; head-

prev=temp;

head=temp;

temp->next=head;

head->prev=temp;

head=temp;