2 - 1 Lab Manual Final
2 - 1 Lab Manual Final
&
ELECTRICAL AND ELECTRONICS
LABORATORY MANUAL
B.TECH
(II YEAR – I SEM)
(2017-18)
DEPARTMENT OF
INFORMATION TECHNOLOGY
LABORATORY MANUAL
B.TECH
(II YEAR – I SEM)
(2017-18)
DEPARTMENT OF
INFORMATION TECHNOLOGY
Vision
To acknowledge quality education and instill high patterns of
discipline making the students technologically superior and ethically
strong which involves the improvement in the quality of life in
human race.
Mission
To achieve and impart holistic technical education using the best of
infrastructure, outstanding technical and teaching expertise to
establish the students into competent and confident engineers.
Evolving the center of excellence through creative and innovative
teaching learning practices for promoting academic achievement to
produce internationally accepted competitive and world class
professionals.
PROGRAMME EDUCATIONAL OBJECTIVES (PEOs)
2. To facilitate the graduates with the technical skills that prepare them for
immediate employment and pursue certification providing a deeper
understanding of the technology in advanced areas of computer science and
related fields, thus encouraging to pursue higher education and research based
on their interest.
3. To facilitate the graduates with the soft skills that include fulfilling the mission,
setting goals, showing self-confidence by communicating effectively, having a
positive attitude, get involved in team-work, being a leader, managing their
career and their life.
After the completion of the course, B. Tech Computer Science and Engineering, the
graduates will have the following Program Specific Outcomes:
1. Students are advised to come to the laboratory at least 5 minutes before (to the
starting time), those who come after 5 minutes will not be allowed into the lab.
2. Plan your task properly much before to the commencement, come prepared to the lab
with the synopsis / program / experiment details.
3. Student should enter into the laboratory with:
a. Laboratory observation notes with all the details (Problem statement, Aim,
Algorithm, Procedure, Program, Expected Output, etc.,) filled in for the lab session.
b. Laboratory Record updated up to the last session experiments and other utensils (if
any) needed in the lab.
c. Proper Dress code and Identity card.
4. Sign in the laboratory login register, write the TIME-IN, and occupy the computer
system allotted to you by the faculty.
5. Execute your task in the laboratory, and record the results / output in the lab
observation note book, and get certified by the concerned faculty.
6. All the students should be polite and cooperative with the laboratory staff, must
maintain the discipline and decency in the laboratory.
7. Computer labs are established with sophisticated and high end branded systems,
which should be utilized properly.
8. Students / Faculty must keep their mobile phones in SWITCHED OFF mode during
the lab sessions. Misuse of the equipment, misbehaviors with the staff and systems
etc., will attract severe punishment.
9. Students must take the permission of the faculty in case of any urgency to go out ; if
anybody found loitering outside the lab / class without permission during working
hours will be treated seriously and punished appropriately.
10. Students should LOG OFF/ SHUT DOWN the computer system before he/she leaves
the lab after completing the task (experiment) in all aspects. He/she must ensure the
system / seat is kept properly.
Objectives:
Outcomes:
Ability to identify the appropriate data structure for given problem.
Graduate able to design and analyze the time and space complexity of
algorithm or program.
Vision:
To acknowledge quality education and instill high patterns of discipline making the
students technologically superior and ethically strong which involves the
improvement in the quality of life in human race.
Mission:
To achieve and impart holistic technical education using the best of infrastructure,
outstanding technical and teaching expertise to establish the students into
competent and confident engineers.
Evolving the center of excellence through creative and innovative teaching learning
practices for promoting academic achievement to produce internationally accepted
competitive and world class professionals.
RECOMMENDED SYSTEM / SOFTWARE REQUIREMENTS:
List of programs
Week 1: write a C++ programs to implement recursive and non recursive i) Linear search ii) Binary
search
Aim: To implement Linear search and binary search recursively and non recursively
Description:
i) LINEAR SEARCH (SEQUENTIAL SEARCH): Search begins by comparing the first
element of the list with the target element. If it matches, the search ends. Otherwise, move
to next element and compare. In this way, the target element is compared with all the
elements until a match occurs. If the match do not occur and there are no more elements to
be compared, conclude that target element is absent in the list.
For example consider the following list of elements.
5 9 7 8 11 2 6 4
To search for element 11(i.e Key element = 11). first compare the target element
with first element in list i.e. 5. Since both are not matching we move on the next elements in
the list and compare. Finally found the match after 5 comparisons.
Algorithm for Linear search
Department of IT Page 1
Date Structures using C++ LAB 2017-2018
Results
Department of IT Page 2
Date Structures using C++ LAB 2017-2018
if(list[n]==key)
return n;
else
return Rec_Lsearch(list,n-1,key);
}
Results
ii) Binary Searching: Before searching, the list of items should be sorted in ascending order.
First compare the key value with the item in the mid position of the array. If there is a match,
we can return immediately the position. if the value is less than the element in middle
location of the array, the required value is lie in the lower half of the array.if the value is
greater than the element in middle location of the array, the required value is lie in the upper
half of the array. We repeat the above procedure on the lower half or upper half of the array.
Algorithm:
Binary_Search (A [ ], U_bound, VAL)
Step 1 : set BEG = 0 , END = U_bound , POS = -1
Step 2 : Repeat while (BEG <= END )
Step 3 : set MID = ( BEG + END ) / 2
Step 4 : if A [ MID ] == VAL then
POS = MID
print VAL “ is available at “, POS
GoTo Step 6
End if
if A [ MID ] > VAL then
set END = MID – 1
Else
set BEG = MID + 1
End if
End while
Step 5 : if POS = -1 then
print VAL “ is not present “
End if
Step 6 : EXIT
Source code: Non recursive C++ program for binary search
#include<iostream>
using namespace std;
int binary_search(int list[],int key,int low,int high);
int main()
{
int n,i,key,list[25],pos;
cout<<"enter no of elements\n" ;
cin>>n;
Department of IT Page 3
Date Structures using C++ LAB 2017-2018
Results
Department of IT Page 4
Date Structures using C++ LAB 2017-2018
cin>>list[i];
cout<<"enter key to search" ;
cin>>key;
pos=rbinary_search(list,key,0,n-1);
if(pos==-1)
cout<<"element not found" ;
else
cout<<"element found at index "<<pos;
}
/*recursive function for binary search*/
int rbinary_search(int list[ ],int key,int low,int high)
{
int mid,pos=-1;
if(low<=high)
{
mid=(low+high)/2;
if(key==list[mid])
{
pos=mid;
return pos;
}
else if(key<list[mid])
return rbinary_search(list,key,low,mid-1);
else
return rbinary_search(list,key,mid+1,high);
}
return pos;
}
Results
Assignment :-
Department of IT Page 5
Date Structures using C++ LAB 2017-2018
Week 2: write a C++ programs to implement i) Bubble sort ii) Selection sort iii) quick sort iv) insertion
sort
Aim: To implement i) Bubble sort ii) Selection sort iii) Quick sort iv) Insertion sort
Description:
i)Bubble sort
The bubble sort is an example of exchange sort. In this method, repetitive comparison is
performed among elements and essential swapping of elements is done. Bubble sort is
commonly used in sorting algorithms. It is easy to understand but time consuming i.e.
takes more number of comparisons to sort a list . In this type, two successive elements are
compared and swapping is done. Thus, step-by-step entire array elements are checked. It
is different from the selection sort. Instead of searching the minimum element and then
applying swapping, two records are swapped instantly upon noticing that they
are not in order.
ALGORITHM:
Bubble_Sort ( A [ ] , N )
Step 1: Start
Step 2: Take an array of n elements
Step 3: for i=0,………….n-2
Step 4: for j=i+1,…….n-1
Step 5: if arr[j]>arr[j+1] then
Interchange arr[j] and arr[j+1]
End of if
Step 6: Print the sorted array arr
Step 7:Stop
Source code: Write a program to sort a list of numbers using bubble sort
#include<iostream>
using namespace std;
void bubble_sort(int list[30],int n);
int main()
{
int n,i;
int list[30];
cout<<"enter no of elements\n";
cin>>n;
cout<<"enter "<<n<<" numbers ";
for(i=0;i<n;i++)
cin>>list[i];
bubble_sort (list,n);
cout<<" after sorting\n";
for(i=0;i<n;i++)
cout<<list[i]<<endl;
return 0;
}
void bubble_sort (int list[30],int n)
{
int temp ;
int i,j;
for(i=0;i<n;i++)
Department of IT Page 6
Date Structures using C++ LAB 2017-2018
for(j=0;j<n-1;j++)
if(list[j]>list[j+1])
{
temp=list[j];
list[j]=list[j+1];
list[j+1]=temp;
}
}
Results
Department of IT Page 7
Date Structures using C++ LAB 2017-2018
cout<<"enter no of elements\n";
cin>>n;
cout<<"enter "<<n<<" numbers ";
for(i=0;i<n;i++)
cin>>list[i];
selection_sort (list,n);
cout<<" after sorting\n";
for(i=0;i<n;i++)
cout<<list[i]<<endl;
return 0;
}
void selection_sort (int list[],int n)
{
int min,temp,i,j;
for(i=0;i<n;i++)
{
min=i;
for(j=i+1;j<n;j++)
{
if(list[j]<list[min])
min=j;
}
temp=list[i];
list[i]=list[min];
list[min]=temp;
}
}
Results
iii) Quick sort: It is a divide and conquer algorithm. Quick sort first divides a large array into
two smaller sub-arrays: the low elements and the high elements. Quick sort can then
recursively sort the sub-arrays.
ALGORITHM:
Step 1: Pick an element, called a pivot, from the array.
Step 2: Partitioning: reorder the array so that all elements with values less than the pivot come
before the pivot, while all elements with values greater than the pivot come after it (equal
values can go either way). After this partitioning, the pivot is in its final position. This is called
the partition operation.
Department of IT Page 8
Date Structures using C++ LAB 2017-2018
Step 3: Recursively apply the above steps to the sub-array of elements with smaller values and
separately to the sub-array of elements with greater values.
Source code: program to implement Quick sort
#include<iostream>
using namespace std;
void quicksort(int x[],int Lb,int Ub)
{
int down,up,pivot,t;
if(Lb<Ub)
{
down=Lb;
up=Ub;
pivot=down;
while(down<up)
{
while((x[down]<=x[pivot])&&(down<Ub))down++;
while(x[up]>x[pivot])up--;
if(down<up)
{
t=x[down];
x[down]=x[up];
x[up]=t;
}/*endif*/
}
t=x[pivot];
x[pivot]=x[up];
x[up]=t;
quicksort( x,Lb,up-1);
quicksort( x,up+1,Ub);
}
}
int main()
{
int n,i;
int list[30];
cout<<"enter no of elements\n";
cin>>n;
cout<<"enter "<<n<<" numbers ";
for(i=0;i<n;i++)
cin>>list[i];
quicksort(list,0,n-1);
cout<<" after sorting\n";
for(i=0;i<n;i++)
cout<<list[i]<<endl;
return 0;
}
Department of IT Page 9
Date Structures using C++ LAB 2017-2018
Results
iv) Insertion sort: It iterates, consuming one input element each repetition, and growing a
sorted output list. Each iteration, insertion sort removes one element from the input data,
finds the location it belongs within the sorted list, and inserts it there. It repeats until no
input elements remain
ALGORITHM:
Step 1: start
Step 2: for i ← 1 to length(A)
Step 3: j ← i
Step 4: while j > 0 and A[j-1] > A[j]
Step 5: swap A[j] and A[j-1]
Step 6: j←j-1
Step 7: end while
Step 8: end for
Step9: stop
Department of IT Page 10
Date Structures using C++ LAB 2017-2018
int n,i;
int list[30];
cout<<"enter no of elements\n";
cin>>n;
cout<<"enter "<<n<<" numbers ";
for(i=0;i<n;i++)
cin>>list[i];
insertion_sort(list,n);
cout<<" after sorting\n";
for(i=0;i<n;i++)
cout<<list[i]<<endl;
return 0;
}
Results
Assignment:-
Department of IT Page 11
Date Structures using C++ LAB 2017-2018
Week 3: Write C++ programs to implement the following using an array. Stack ADT b) Queue ADT
sort
Aim: To implement Stack ADT and Queue ADT using an array
Description:
Stack:It is an ordered collection of data elements into which new elements may be inserted and
from which elements may be deleted at one end called the “TOP” of stack.
A stack is a last-in-first-out ( LIFO ) structure.
Insertion operation is referred as “PUSH” and deletion operation is referred as “POP”.
The most accessible element in the stack is the element at the position “TOP”.
Stack must be created as empty.
Whenever an element is pushed into stack, it must be checked whether the stack is
full or not.
Whenever an element is popped form stack, it must be checked whether the stack is
empty or not.
We can implement the stack ADT either with array or linked list.
ALGORITHM: push()
ALGORITHM pop()
#include<iostream>
using namespace std;
#include<stdlib.h>
#define max 50
template <class T>
Department of IT Page 12
Date Structures using C++ LAB 2017-2018
class stack
{
private:
T top,stk[50],item;
public:
stack();
void push();
void pop();
void display();
};
template <class T>
stack<T>::stack()
{
top=-1;
}
//code to push an item into stack;
template <class T>
void stack<T>::push()
{
if(top==max-1)
cout<<"Stack Overflow...\n";
else
{
cout<<"Enter an item to be pushed:";
top++;
cin>>item;
stk[top]=item;
cout<<"Pushed Sucesfully....\n";
}
}
template <class T>
void stack<T>::pop()
{
if(top==-1)
cout<<"Stack is Underflow";
else
{
item=stk[top];
top--;
cout<<item<<" is poped Sucesfully....\n";
}
}
template <class T>
void stack<T>::display()
{
if(top==-1)
cout<<"Stack Under Flow";
else
{
for(int i=top;i>-1;i--)
Department of IT Page 13
Date Structures using C++ LAB 2017-2018
{
cout<<"|"<<stk[i]<<"|\n";
cout<<"----\n";
}
}
}
int main()
{
int choice;
stack<int>st;
while(1)
{
cout<<"\n\n*****Menu for Skack operations*****\n\n";
cout<<"1.PUSH\n2.POP\n3.DISPLAY\n4.EXIT\n";
cout<<"Enter Choice:";
cin>>choice;
switch(choice)
{
case 1:
st.push();
break;
case 2:
st.pop();
break;
case 3: cout<<"Elements in the Stack are....\n";
st.display();
break;
case 4:
exit(0);
default:cout<<"Invalid choice...Try again...\n";
}
}
}
Results
Department of IT Page 14
Date Structures using C++ LAB 2017-2018
QUEUE
DESCRIPTION:
Queue is a data structure in which the elements are added at one end, called the rear, and
deleted from the other end, called the front. A First In First Out data structure (FIFO).The
rear of the queue is accessed whenever a new element is added to the queue, and the front of
the queue is accessed whenever an element is deleted from the queue. As in a stack, the
middle elements in the queue are in accessible, even if the queue elements are sorted in an
array.
BASIC QUEUE OPERATIONS:
1. initializeQueue(): Initializes the queue to an empty state.
2. Determines whether the queue is empty. If the queue is empty, it returns the value
true; otherwise, it returns the value false.
3. Determines whether the queue is full. If the queue is empty, it returns the value
true; otherwise, it returns the value false.
4. rear: Returns the last element of the queue. Prior to this operation, the queue must
exit.
5. front: Returns the front, that is, the first element of the queue. Priority to this
operation, the queue must exit.
Queue can be stored either in an array or in linked list. We will consider both
implementations. Because elements are added at one end and remove from the other
end, we need two pointers to keep track of the front and rear of the queue, called
queueFront and queueRear. Queues are restricted versions of arrays and linked lists.
The middle terms of queue should not be accessed directly.
#include<stdlib.h>
#include<iostream>
using namespace std;
#define max 5
template <class T>
class queue
{
private:T q[max],item;
int front,rear;
public: queue();
void insert_q();
void delete_q();
void display_q();
};
Department of IT Page 15
Date Structures using C++ LAB 2017-2018
Department of IT Page 16
Date Structures using C++ LAB 2017-2018
else
{
for(int i=front;i<=rear;i++)
cout<<"|"<<q[i]<<"|<--";
}
}
int main()
{
int choice;
queue<int> q;
while(1)
{
cout<<"\n\n*****Menu for QUEUE operations*****\n\n";
cout<<"1.INSERT\n2.DELETE\n3.DISPLAY\n4.EXIT\n";
cout<<"Enter Choice:";
cin>>choice;
switch(choice)
{
case 1: q.insert_q();
break;
case 2: q.delete_q();
break;
case 3: cout<<"Elements in the queue are....\n";
q.display_q();
break;
case 4: exit(0);
default: cout<<"Invalid choice...Try again...\n";
}
}
return 0;
}
Results
Assignment :-
Department of IT Page 17
Date Structures using C++ LAB 2017-2018
sort
Aim: To implement list ADT to perform following operations
a) Insert an element into a list. b) Delete an element from list
c) Search for a key element in list d)count number of nodes in list
Description:
List ADT
A linked list is a data structure consisting of a group of nodes which together represent a
sequence. Each node is composed of a data part and a reference (in other words, a link) to the next
node in the sequence.
The Linked List is a collection of elements called nodes, each node of which stores two items of
information, i.e., data part and link field.
The data part of each node consists the data record of an entity.
The link field is a pointer and contains the address of next node.
The beginning of the linked list is stored in a pointer termed as head which points to the first
node.
The head pointer will be passed as a parameter to any method, to perform an operation.
First node contains a pointer to second node, second node contains a pointer to the third node
and so on.
The last node in the list has its next field set to NULL to mark the end of the list.
There are several variants of linked lists. These are as follows:
Singly linked list
Circular linked list
Doubly linked list
Doubly circular linked list
Single Linked List is a collection of nodes. Each node contains 2 fields: I) info where the
information is stored and ii) link which points to the next node in the list.
Department of IT Page 18
Date Structures using C++ LAB 2017-2018
The operations that can be performed on single linked lists includes: insertion, deletion and
traversing the list.
Various operations on a single linked list are
1.Insertion of a node into list
2.Deletion of a node from list
3.Traversal of the list
#include<stdlib.h>
#include<iostream.h>
#include<conio.h>
class node
{
public:
int data;
node *next;
};
class List
{
int item;
node *head;
public: List( );
void insert_front( );
void insert_end( );
void delete_front( );
void delete_end( );
void display( );
int node_count();
void delete_before_pos();
void delete_after_pos();
};
List::List( )
{
head=NULL;
}
//code to insert an item at front List;
void List::insert_front( )
{
node *p;
cout<<"Enter an element to be inserted:";
cin>>item;
p=new node;
p->data=item;
p->next=NULL;
if(head==NULL)
{
head=p;
}
else
Department of IT Page 19
Date Structures using C++ LAB 2017-2018
{ p->next=head;
head=p;
}
cout<<"\nInserted at front of Linked List Sucesfully....\n";
}
void List::delete_front( )
{
node*t;
if(head==NULL)
cout<<"\nList is Underflow";
else
{ item=head->data;
t=head;
head=head->next;
cout<<"\n"<<item<<" is deleted Sucesfully from List....\n";
delete(t);
}
}
void List::delete_end( )
{
node*t,*prev;
if(head==NULL)
cout<<"\nList is Underflow";
Department of IT Page 20
Date Structures using C++ LAB 2017-2018
else
{
t=head;
if(head->next==NULL)
{
cout<<"\n"<<t->data<<" is deleted Sucesfully from List....\n";
delete(t);
head=NULL;
}
else
{
while(t->next!=NULL)
{
prev=t;
t=t->next;
}
prev->next=NULL;
cout<<"\n"<<t->data<<" is deleted Sucesfully from List....\n";
delete(t);
}
}
}
//Delete a node before a position
void List::delete_before_pos( )
{
int i=1;
int pos;
node*t,*prev;
if(head==NULL)
cout<<"\nList is Underflow";
else
{ cout<<"Enter position at which node has to be deleted:";
cin>>pos;
t=head;
int nc=node_count();
if(pos>nc||pos<=0)
cout<<"invalid position ...try again\n";
else
{
cout<<"Before Deletion elements in the List are..\n";
display();
while(i<pos)
{
prev=t;
t=t->next;
i++;
}
if(i==1)
{
Department of IT Page 21
Date Structures using C++ LAB 2017-2018
Department of IT Page 22
Date Structures using C++ LAB 2017-2018
if(head->next==NULL)
head=NULL;
else
{
t=head;
head=head->next;
cout<<"\n"<<t->data<<" is deleted Sucesfully from List....\n";
delete(t);
}
}
else
{
prev->next=t->next;
cout<<"\n"<<t->data<<" is deleted Sucesfully from List....\n";
delete(t);
}
cout<<"After Deletion elements in the List are..\n";
display();
}
}
}
void List::display()
{
node*t;
if(head==NULL)
cout<<"\nList Under Flow";
else
{
cout<<"\nElements in the List are....\n";
t=head;
while(t!=NULL)
{
cout<<"|"<<t->data<<"|->";
t=t->next;
}
}
}
//code to count no of nodes
int List::node_count( )
{
int nc=0;
node*t;
if(head==NULL)
{
cout<<"\nList Under Flow"<<endl;
// cout<<"No Nodes in the Linked List are: "<<nc<<endl;
}
else
{
Department of IT Page 23
Date Structures using C++ LAB 2017-2018
t=head;
while(t!=NULL)
{
nc++;
t=t->next;
}
// cout<<"No Nodes in the Linked List are: "<<nc<<endl;
}
return nc;
}
int main( )
{
int choice;
List LL;
while(1)
{
cout<<"\n\n***Menu for Linked List operations***\n\n";
cout<<"1.Insert Front\n2.Insert end\n3.Delete front\n4.Delete End\n5.DISPLAY\n";
cout<<"6.Node Count\n7.Del before a position\n8.Del after position\n";
cout<<"9.Clear Scrn\n10.Exit\nEnter Choice:";
cin>>choice;
switch(choice)
{
case 1: LL.insert_front( );
break;
case 2: LL.insert_end( );
break;
case 3: LL.delete_front( );
break;
case 4: LL.delete_end( );
break;
case 5: LL.display( );
break;
case 6:cout<<"No of nodes in List:"<<LL.node_count();
break;
case 7:LL.delete_before_pos();
break;
case 8:LL.delete_after_pos();
break;
case 9:clrscr();
break;
case 10:exit(0);
default:cout<<"Invalid choice...Try again...\n";
}
}
}
Department of IT Page 24
Date Structures using C++ LAB 2017-2018
Results
Assignment:-
Department of IT Page 25
Date Structures using C++ LAB 2017-2018
Week 5: Write C++ programs to implement the following using a singly linked list.
a) Stack ADT b) Queue ADT
sort To implement Stack ADT and Queue ADT using a singly linked list.
Aim:
Description:
A Stack is a collection of items in which new items may be deleted at end to
implement stack using linked list we need to define a node which in turn consist of data a
pointer to the next node. The advantage of representing stack using linked lists is that we can
decide which end should be top of a stack. And since the array size is fixed, in the array
(linear) representation of stack, only fixed number of elements can be pushed onto the stack.
If in a program the number of elements to be pushed exceeds the size of the array, the
program may terminate in an error. We must overcome these problems.
By using linked lists we can dynamically organize data (such as an ordered
list).Therefore , ;ogically the stack is never full. The stack is full only if we run out of
memory space. In the below program we select front end as top if stack in which we cab add
or remove data.
#include<stdlib.h>
#include<iostream>
using namespace std;
template <class T>
class node
{
public:
T data;
node<T>*next;
};
Department of IT Page 26
Date Structures using C++ LAB 2017-2018
void stack<T>::push()
{
node<T>*t;
node<T>*p;
cout<<"Enter an item to be pushed:";
cin>>item;
p=new node<T>;
p->data=item;
p->next=top;
top=p;
cout<<"\nPushed Sucesfully....\n";
}
}
template <class T>
void stack<T>::display()
{
node<T>*t;
if(top==NULL)
cout<<"\nStack Under Flow";
else
{ cout<<"\nElements in the Stack are....\n";
t=top;
while(t!=NULL)
{
cout<<"|"<<t->data<<"|\n";
cout<<"----\n";
t=t->next;
}
}
}
int main()
{
int choice;
stack<int>st;
while(1)
{
Department of IT Page 27
Date Structures using C++ LAB 2017-2018
Results
Description: Queue is a data structure in which the elements are added at one end, called the
rear, and deleted from the other end, called the front. A First In First Out data structure
(FIFO). The rear of the queue is accessed whenever a new element is added to the queue, and
the front of the queue is accessed whenever an element is deleted from the queue. As in a
stack, the middle elements in the queue are in accessible, even if the queue elements are
sorted in an array.
Source code: To implement QUEUE ADT using a singly linked list
#include<stdlib.h>
#include<iostream.h>
template <class T>
class node
{
public:
T data;
node<T>*next;
};
Department of IT Page 28
Date Structures using C++ LAB 2017-2018
Department of IT Page 29
Date Structures using C++ LAB 2017-2018
while(1)
{
cout<<"\n\n***Menu for Queue operations***\n\n";
cout<<"1.Insert\n2.Delete\n3.DISPLAY\n4.EXIT\n";
cout<<"Enter Choice:";
cin>>choice;
switch(choice)
{
case 1: q1.insert_q();
break;
case 2: q1.delete_q();
break;
case 3: q1.display_q();
break;
case 4: exit(0);
default:cout<<"Invalid choice...Try again...\n";
}
}
return 0;
}
Department of IT Page 30
Date Structures using C++ LAB 2017-2018
Results
Assignment:-
Department of IT Page 31
Date Structures using C++ LAB 2017-2018
Week 6: Write C++ programs to implement the de queue (double ended queue) ADT using a
doubly linked list and an array.
Aim: To implement the de queue (double ended queue) ADT using a doubly linked list and
an array.
sort
Source code: To implement the de queue (double ended queue) ADT
#include <iostream.h>
#include<stdlib.h>
#include <conio.h>
template<class T>
class node
{
public:
T data;
node*prev;
node*next;
};
template<class T>
class dll
{
node<T>*head;
public:
dll();
void insert_front();
void insert_end();
void delete_front();
void delete_end();
void display();
void insert_at_pos();
int node_count();
};
template<class T>
dll<T>::dll()
{
head=NULL;
}
//code to insert node at front of list...
template<class T>
void dll<T>::insert_front()
{
node<T>*new_node;
int x;
new_node=new node<T>;
cout<<"Enter data into node:\n";
cin>>x;
new_node->data=x;
new_node->prev=NULL;
new_node->next=NULL;
Department of IT Page 32
Date Structures using C++ LAB 2017-2018
if(head==NULL)
head=new_node;
else
{
new_node->next=head;
head->prev=new_node;
head=new_node;
}
cout<<"Inserted node sucesfully...";
}
//code to insert node at end of list...
template<class T>
void dll<T>::insert_end()
{
node<T>*new_node;
node<T>*t;
int x;
new_node=new node<T>;
cout<<"Enter data into node:\n";
cin>>x;
new_node->data=x;
new_node->next=NULL;
new_node->prev=NULL;
if(head==NULL)
head=new_node;
else
{
t=head;
while(t->next!=NULL)
t=t->next;
t->next= new_node;
new_node->prev=t;
}
cout<<"Inserted node sucesfully...";
}
template<class T>
void dll<T>::delete_front()
{
node<T>*temp;
if(head==NULL)
cout<<"List is empty....\n ";
else if(head->next==NULL)
{
temp=head;
cout<<"Deleted element from Doubly Linked List is "<<temp->data<<endl;
delete temp;
head=NULL;
}
else
Department of IT Page 33
Date Structures using C++ LAB 2017-2018
{
temp=head;
head=head->next;
head->prev=NULL;
cout<<"Deleted element from Doubly Linked List is "<<temp->data<<endl;
delete temp;
cout<<"Elements after deletion from Front are...\n";
display();
}
}
template<class T>
void dll<T>::delete_end()
{
node<T>*t1;
node<T>*t2;
if(head==NULL)
cout<<"List is empty....\n ";
else
{
t1=t2=head;
if(head->next==NULL)
{
head=NULL;
cout<<"Deleted element from Doubly Linked List is "<<t1->data<<endl;
delete t1;
}
else
{
while(t1->next!=NULL)
{
t2=t1;
t1=t1->next;
}
t2->next=NULL;
cout<<"Deleted element from Doubly Linked List is "<<t1->data<<endl;
delete t1;
cout<<"Elements after Deletion from End are...\n";
display();
}
}
}
template<class T>
void dll<T>::insert_at_pos()
{
node<T>*new_node;
node<T>*t1;
node<T>*t2;
int x,pos,nc;
new_node=new node<T>;
cout<<"Enter data into node:\n";
Department of IT Page 34
Date Structures using C++ LAB 2017-2018
cin>>x;
cout<<"enter Pos at which node has to be inserted:";
cin>>pos;
new_node->data=x;
new_node->next=NULL;
new_node->prev=NULL;
nc=node_count();
cout<<"node count="<<nc<<endl;
if(pos<=0||pos>nc+1)
cout<<"invalid position";
else
{
if(pos==1)
{
if(head==NULL)
head=new_node;
else
{
new_node->next=head;
head->prev=new_node;
head=new_node;
}
}
else
{
t1=t2=head;
int i=1;
while(i<pos)
{
t2=t1;
t1=t1->next;
i++;
}
if(t1==NULL)
{
new_node->next=NULL;
}
else
{
t1->prev=new_node;
}
t2->next= new_node;
new_node->prev=t2;
}
cout<<"Inserted node sucesfully...";
}
Department of IT Page 35
Date Structures using C++ LAB 2017-2018
template<class T>
int dll<T>:: node_count()
{
int i=0;
node<T> *t;
t=head;
while(t!=NULL)
{
t=t->next;
i++;
}
return i;
}
template<class T>
void dll<T>::display()
{
node<T>*t;
int count;
t=head;
if(head==NULL)
{
cout<<"Doubly linked list is empty.....\n";
}
else
{
cout<<"Elements in the list are........\n";
while(t!=NULL)
{
cout<<"|"<<t->data<<"|-> ";
t=t->next;
}
}
count=node_count();
cout<<"\n Total No of nodes in Doubly linked List are:"<<count<<endl;
}
int main()
{
dll<int> d;
int choice;
while(1)
{ cout<<"\n***Menu for Doubly linked list operations***\n";
cout<<"\n1.insert front";
cout<<"\n2.insert end";
cout<<"\n3.delete front";
cout<<"\n4.delete end";
cout<<"\n5.Display";
cout<<"\n6.insert at pos";
Department of IT Page 36
Date Structures using C++ LAB 2017-2018
cout<<"\n7.Exit";
cout<<"\nEnter Choice:";
cin>>choice;
switch(choice)
{
case 1:d.insert_front();
break;
case 2:d.insert_end();
break;
case 3:d.delete_front();
break;
case 4:d.delete_end();
break;
case 5:d.display();
break;
case 6:d.insert_at_pos();
break;
case 7:exit(0);
}
}
//return 0;
}
Results
Assignment:-
Department of IT Page 37
Date Structures using C++ LAB 2017-2018
Description:
10
7 15
5 9 12 18
Source code:
#include<stdlib.h>
#include<iostream.h>
class node
{
public:
int data;
node*lchild;
node*rchild;
};
class bst:public node
{ int item;
node *root;
public: bst();
void insert_node();
void delete_node();
void display_bst();
void inorder(node*);
Department of IT Page 38
Date Structures using C++ LAB 2017-2018
};
bst::bst()
{
root=NULL;
}
void bst:: insert_node()
{
node *new_node,*curr,*prev;
new_node=new node;
cout<<"Enter data into new node";
cin>>item;
new_node->data=item;
new_node->lchild=NULL;
new_node->rchild=NULL;
if(root==NULL)
root=new_node;
else
{ curr=prev=root;
while(curr!=NULL)
{ if(new_node->data>curr->data)
{ prev=curr;
curr=curr->rchild;
}
else
{ prev=curr;
curr=curr->lchild;
}
}
cout<<"Prev:"<<prev->data<<endl;
if(prev->data>new_node->data)
prev->lchild=new_node;
else
prev->rchild=new_node;
}
}
//code to delete a node
void bst::delete_node()
{
if(root==NULL)
cout<<"Tree is Empty";
else
{
int key;
cout<<"Enter the key value to be deleted";
cin>>key;
node* temp,*parent,*succ_parent;
temp=root;
while(temp!=NULL)
{ if(temp->data==key)
{ //deleting node with two childern
Department of IT Page 39
Date Structures using C++ LAB 2017-2018
if(temp->lchild!=NULL&&temp->rchild!=NULL)
{ //search for inorder sucessor
node*temp_succ;
temp_succ=temp->rchild;
while(temp_succ->lchild!=NULL)
{
succ_parent=temp_succ;
temp_succ=temp_succ->lchild;
}
temp->data=temp_succ->data;
succ_parent->lchild=NULL;
cout<<"Deleted sucess fully";
return;
}
//deleting a node having one left child
if(temp->lchild!=NULL&temp->rchild==NULL)
{
if(parent->lchild==temp)
parent->lchild=temp->lchild;
else
parent->rchild=temp->lchild;
temp=NULL;
delete(temp);
cout<<"Deleted sucess fully";
return;
}
//deleting a node having one right child
if(temp->lchild==NULL&temp->rchild!=NULL)
{
if(parent->lchild==temp)
parent->lchild=temp->rchild;
else
parent->rchild=temp->rchild;
temp=NULL;
delete(temp);
cout<<"Deleted sucess fully";
return;
}
//deleting a node having no child
if(temp->lchild==NULL&temp->rchild==NULL)
{
if(parent->lchild==temp)
parent->lchild=NULL;
else
parent->rchild=NULL;
temp=NULL;
delete(temp);
cout<<"Deleted sucess fully";
return;
}
Department of IT Page 40
Date Structures using C++ LAB 2017-2018
}
else if(temp->data<key)
{ parent=temp;
temp=temp->rchild;
}
else if(temp->data>key)
{ parent=temp;
temp=temp->lchild;
}
}//end while
}//end if
}//end delnode func
void bst::display_bst()
{
if(root==NULL)
cout<<"\nBST Under Flow";
else
inorder(root);
}
void bst::inorder(node*t)
{
if(t!=NULL)
{
inorder(t->lchild);
cout<<" "<<t->data;
inorder(t->rchild);
}
}
int main()
{
bst bt;
int i;
while(1)
{
cout<<"****BST Operations****";
cout<<"\n1.Insert\n2.Display\n3.del\n4.exit\n";
cout<<"Enter Choice:";
cin>>i;
switch(i)
{
case 1:bt.insert_node();
break;
case 2:bt.display_bst();
break;
case 3:bt.delete_node();
break;
case 4:exit(0);
default: cout<<"Enter correct choice";
}
Department of IT Page 41
Date Structures using C++ LAB 2017-2018
}
}
Results
Assignment:-
Department of IT Page 42
Date Structures using C++ LAB 2017-2018
Week 8 : Write C++ programs for implementing the following sorting methods:
a) Merge sort b) Heap sort
Description:
Merge sort is an O(n log n) comparison-based sorting algorithm. It is stable, meaning that
it preserves the input order of equal elements in the sorted output. It is an example of the
divide and conquer algorithmic paradigm. Merge sort is so inherently sequential that it's
practical to run it using slow tape drives as input and output devices. It requires very little
memory, and the memory required does not change with the number of data elements. If you
have four tape drives, it works as follows:
1. Divide the data to be sorted in half and put half on each of two tapes
2. Merge individual pairs of records from the two tapes; write two-record chunks
alternately to each of the two output tapes
3. Merge the two-record chunks from the two output tapes into four-record chunks; write
these alternately to the original two input tapes
4. Merge the four-record chunks into eight-record chunks; write these alternately to the
original two output tapes
5. Repeat until you have one chunk containing all the data, sorted --- that is, for log n
passes, where n is the number of records.
Conceptually, merge sort works as follows:
1. Divide the unsorted list into two sublists of about half the size
2. Divide each of the two sublists recursively until we have list sizes of length 1, in
which case the list itself is returned
3. Merge the two sublists back into one sorted list.
Source code:
#include<iostream>
using namespace std;
#define max 15
template<class T>
void merge(T a[],int l,int m,int u)
{
T b[max];
int i,j,k;
i=l; j=m+1;
k=l;
while((i<=m)&&(j<=u))
{
Department of IT Page 43
Date Structures using C++ LAB 2017-2018
if(a[i]<=a[j])
{
b[k]=a[i];
++i;
}
else
{
b[k]=a[j];
++j;
}
++k;
}
if(i>m)
{
while(j<=u)
{
b[k]=a[j];
++j;
++k;
}
}
else
{
while(i<=m)
{
b[k]=a[i];
++i;
++k;
}
}
for(int r=l;r<=u;r++)
a[r]=b[r];
}
int main()
{
Department of IT Page 44
Date Structures using C++ LAB 2017-2018
int n,i;
int list[30];
cout<<"enter no of elements\n";
cin>>n;
cout<<"enter "<<n<<" numbers ";
for(i=0;i<n;i++)
cin>>list[i];
mergesort (list,0,n-1);
cout<<" after sorting\n";
for(i=0;i<n;i++)
cout<<list[i]<<endl;
return 0;
}
Results
HEAP SORT
Heap sort is a method in which a binary tree is used. In this method first the heap is created
using binary tree and then heap is sorted using priority queue.
Department of IT Page 45
Date Structures using C++ LAB 2017-2018
int main()
{
int n,i;
int list[30];
cout<<"enter no of elements\n";
cin>>n;
cout<<"enter "<<n<<" numbers ";
for(i=0;i<n;i++)
cin>>list[i];
heapSort(list, n);
cout << "Sorted array is \n";
Department of IT Page 46
Date Structures using C++ LAB 2017-2018
printArray(list, n);
return 0;
}
Results
Assignment:-
Department of IT Page 47
Date Structures using C++ LAB 2017-2018
Week 9 : Write C++ programs that use recursive functions to traverse the given
binary tree in Preorder b) inorder and c) postorder
Description:
It is often convenient to a single list containing all the nodes in a tree. This list may
correspond to an order in which the nodes should be visited when the tree is being
searched. We define three such lists here, the preorder, postorder and inorder traversals of
the tree. The definitions themselves are recursive:
if T is the empty tree, then the empty list is the preorder, the inorder and the
postorder traversal associated with T;
if T = [N] consists of a single node, the list [N] is the preorder, the inorder and the
postorder traversal associated with T;
otherwise, T contains a root node n, and subtrees T1,..., Tn: and
o the preorder traversal of the nodes of T is the list containing N, followed, in
order by the preorder traversals of T1..., Tn;
o the inorder traversal of the nodes of T is the list containing the inorder
traversal of T1 followed by N followed in order by the inorder traversal of
each of T2,..., Tn.
o the postorder traversal of the nodes of T is the list containing in order the
postorder traversal of each of T1,..., Tn, followed by N.
Source code:
#include<stdlib.h>
#include<iostream.h>
class node
{
public:
int data;
node*Lchild;
node*Rchild;
};
class bst
{
int item;
node *root;
public: bst();
void insert_node();
void delete_node();
void display_bst();
void preeorder(node*);
void inorder(node*);
void postorder(node*);
};
Department of IT Page 48
Date Structures using C++ LAB 2017-2018
bst::bst()
{
root=NULL;
}
void bst:: insert_node()
{
node *new_node,*curr,*prev;
new_node=new node;
cout<<"Enter data into new node";
cin>>item;
new_node->data=item;
new_node->Lchild=NULL;
new_node->Rchild=NULL;
if(root==NULL)
root=new_node;
else
{
curr=prev=root;
while(curr!=NULL)
{
if(new_node->data>curr->data)
{
prev=curr;
curr=curr->Rchild;
}
else
{
prev=curr;
curr=curr->Lchild;
}
}
cout<<"Prev:"<<prev->data<<endl;
if(prev->data>new_node->data)
prev->Lchild=new_node;
else
prev->Rchild=new_node;
}
}
//code to delete a node
void bst::delete_node()
{
if(root==NULL)
cout<<"Tree is Empty";
else
{
int key;
cout<<"Enter the key value to be deleted";
cin>>key;
node* temp,*parent,*succ_parent;
temp=root;
Department of IT Page 49
Date Structures using C++ LAB 2017-2018
while(temp!=NULL)
{
if(temp->data==key)
{ //deleting node with two childern
if(temp->Lchild!=NULL&&temp->Rchild!=NULL)
{ //search for sucessor
node*temp_succ;
temp_succ=temp->Rchild;
while(temp_succ->Lchild!=NULL)
{
succ_parent=temp_succ;
temp_succ=temp_succ->Lchild;
}
temp->data=temp_succ->data;
succ_parent->Lchild=NULL;
cout<<"Deleted sucess fully";
return;
}
//deleting a node having one left child
if(temp->Lchild!=NULL&temp->Rchild==NULL)
{
if(parent->Lchild==temp)
parent->Lchild=temp->Lchild;
else
parent->Rchild=temp->Lchild;
temp=NULL;
delete(temp);
cout<<"Deleted sucess fully";
return;
}
//deleting a node having one right child
if(temp->Lchild==NULL&temp->Rchild!=NULL)
{
if(parent->Lchild==temp)
parent->Lchild=temp->Rchild;
else
parent->Rchild=temp->Rchild;
temp=NULL;
delete(temp);
cout<<"Deleted sucess fully";
return;
}
//deleting a node having no child
if(temp->Lchild==NULL&temp->Rchild==NULL)
{
if(parent->Lchild==temp)
parent->Lchild=NULL;
else
parent->Rchild=NULL;
temp=NULL;
Department of IT Page 50
Date Structures using C++ LAB 2017-2018
delete(temp);
cout<<"Deleted sucess fully";
return;
}
}
else if(temp->data<key)
{
parent=temp;
temp=temp->Rchild;
}
else if(temp->data>key)
{
parent=temp;
temp=temp->Lchild;
}
}//end while
}//end if
}//end delnode func
void bst::display_bst()
{
if(root==NULL)
cout<<"\nBinary Search Tree is Under Flow";
else
{
int ch;
cout<<"\t\t**Binart Tree Traversals**\n";
cout<<"\t\t1.Pree order\n\t\t2.Inorder\n\t\t3:PostOrder\n";
cout<<"\t\tEnter Your Chice:";
cin>>ch;
switch(ch)
{
case 1: cout<<"Pree order Tree Traversal\n ";
preeorder(root);
break;
case 2: cout<<"Inorder Tree Traversal is\n ";
inorder(root);
break;
case 3: cout<<"Inorder Tree Traversal is\n";
postorder(root);
break;
}
}
}
void bst::inorder(node*t)
{
if(t!=NULL)
{
inorder(t->Lchild);
cout<<" "<<t->data;
Department of IT Page 51
Date Structures using C++ LAB 2017-2018
inorder(t->Rchild);
}
}
void bst::preeorder(node*t)
{
if(t!=NULL)
{
cout<<" "<<t->data;
preeorder(t->Lchild);
preeorder(t->Rchild);
}
}
void bst::postorder(node*t)
{
if(t!=NULL)
{
postorder(t->Lchild);
postorder(t->Rchild);
cout<<" "<<t->data;
}
}
int main()
{
bst bt;
int i;
while(1)
{ cout<<"\n\n***Operations Binary Search Tree***\n";
cout<<"1.Insert\n2.Display\n3.del\n4.exit\n";
cout<<"Enter Choice:";
cin>>i;
switch(i)
{
case 1:bt.insert_node();
break;
case 2:bt.display_bst();
break;
case 3:bt.delete_node();
break;
case 4:exit(0);
Department of IT Page 52
Date Structures using C++ LAB 2017-2018
Results
Assignment:-
Department of IT Page 53
Date Structures using C++ LAB 2017-2018
Source code:
#include<iostream.h>
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
#define MAX 4
#define MIN 2
typedef char Type[10];
typedef struct Btree
{
Type key;
}BT;
Department of IT Page 54
Date Structures using C++ LAB 2017-2018
Department of IT Page 55
Date Structures using C++ LAB 2017-2018
return New;
}
return root;
}
int B::MoveDown(BT New,node *current,BT *med,node **medright)
{
int pos;
if(current==NULL)
{
*med=New;
*medright=NULL;
return 1;
}
else
{
if(SearchNode(New.key,current,&pos))
cout<<"Duplicate key\n";
if(MoveDown(New,current->branch[pos],med,medright))
if(current->count<MAX)
{
InsertIn(*med,*medright,current,pos);
return 0;
}
else
{
Split(*med,*medright,current,pos,med,medright);
return 1;
}
return 0;
}
}
void B::InsertIn(BT med,node *medright,node *current,int pos)
{
int i;
for(i=current->count;i>pos;i--)
{
current->entry[i+1]=current->entry[i];
current->branch[i+1]=current->branch[i];
}
current->entry[pos+1]=med;
current->branch[pos+1]=medright;
current->count++;
}
void B::Split(BT med,node *medright,node *current,int pos,BT *newmedian,node
**newright)
{
int i;
int median;
if(pos<=MIN)
median=MIN;
Department of IT Page 56
Date Structures using C++ LAB 2017-2018
else
median=MIN+1;
*newright=new node;
for(i=median+1;i<=MAX;i++)
{
(*newright)->entry[i-median]=current->entry[i];
(*newright)->branch[i-median]=current->branch[i];
}
(*newright)->count=MAX-median;
current->count=median;
if(pos<=MIN)
InsertIn(med,medright,current,pos);
else
InsertIn(med,medright,*newright,pos-median);
*newmedian=current->entry[current->count];
(*newright)->branch[0]=current->branch[current->count];
current->count--;
}
Department of IT Page 57
Date Structures using C++ LAB 2017-2018
Del_node(target,current->branch[pos]);
if(current->branch[pos])
if(current->branch[pos]->count<MIN)
Adjust(current,pos);
}
}
Department of IT Page 58
Date Structures using C++ LAB 2017-2018
node *t;
t=current->branch[pos];
for(i=t->count;i>0;i--)
{
t->entry[i+1]=t->entry[i];
t->branch[i+1]=t->branch[i];
}
t->branch[1]=t->branch[0];
t->count++;
t->entry[1]=current->entry[pos];
t=current->branch[pos-1];
current->entry[pos]=t->entry[t->count];
current->branch[pos]->branch[0]=t->branch[t->count];
t->count--;
}
Department of IT Page 59
Date Structures using C++ LAB 2017-2018
for(c=pos;c<current->count;c++)
{
current->entry[c]=current->entry[c+1];
current->branch[c]=current->branch[c+1];
}
current->count--;
free(right);
}
int main()
{
int choice,targetpos;
Type inKey;
BT New;
B obj;
node *root,*target;
root=NULL;
while(1)
{
cout<<"\n IMPLEMENTATION OF B-TREE\n";
cout<<"\n1.INSERT\n2.DELETE\n3.SEARCH\n4.DISPLAY\n5.EXIT\n";
cout<<"Enter Your Choice\n";
cin>>choice;
switch(choice)
{
case 1:cout<<"enter the key to be inserted\n";
fflush(stdin);
gets(New.key);
root=obj.Insert(New,root);
break;
Department of IT Page 60
Date Structures using C++ LAB 2017-2018
break;
case 3:cout<<"enter the key to be searched\n";
fflush(stdin);
gets(New.key);
target=obj.Search(New.key,root,&targetpos);
if(target)
cout<<"The searched item"<<target->entry[targetpos].key<<endl;
else
cout<<"Element not found\n";
break;
Results
Assignment:-
Department of IT Page 61
Date Structures using C++ LAB 2017-2018
Department of IT Page 62
Date Structures using C++ LAB 2017-2018
if (p==NULL)
cout<<"Out of Space";
}
else
{
if (x<p->element)
{
insert(x,p->left);
if ((bsheight(p->left) - bsheight(p->right))==2)
{
if (x < p->left->element)
p=srl(p);
else
p = drl(p);
}
}
else if (x>p->element)
{
insert(x,p->right);
if ((bsheight(p->right) - bsheight(p->left))==2)
{
if (x > p->right->element)
p=srr(p);
else
p = drr(p);
}
}
else
cout<<"Element Exists";
}
int m,n,d;
m=bsheight(p->left);
n=bsheight(p->right);
d=max(m,n);
p->height = d + 1;
}
//Finding the Smallest
np bstree::findmin(np p)
{
if (p==NULL)
{
cout<<"Empty Tree ";
return p;
}
else
{
while(p->left !=NULL)
p=p->left;
return p;
}
Department of IT Page 63
Date Structures using C++ LAB 2017-2018
}
//Finding the Largest
np bstree::findmax(np p)
{
if (p==NULL)
{
cout<<"Empty Tree ";
return p;
}
else
{
while(p->right !=NULL)
p=p->right;
return p;
}
}
//Finding an element
void bstree::find(int x,np &p)
{
if (p==NULL)
cout<<" Element not found ";
else
if (x < p->element)
find(x,p->left);
else
if (x>p->element)
find(x,p->right);
else
cout<<" Element found !";
}
//Copy a tree
void bstree::copy(np &p,np &p1)
{
makeempty(p1);
p1 = nodecopy(p);
}
// Make a tree empty
void bstree::makeempty(np &p)
{
np d;
if (p != NULL)
{
makeempty(p->left);
makeempty(p->right);
d=p;
free(d);
p=NULL;
}
}
Department of IT Page 64
Date Structures using C++ LAB 2017-2018
Department of IT Page 65
Date Structures using C++ LAB 2017-2018
Department of IT Page 66
Date Structures using C++ LAB 2017-2018
{
int t;
if (p == NULL)
return -1;
else
{
t = p->height;
return t;
}
}
np bstree:: srl(np &p1)
{
np p2;
p2 = p1->left;
p1->left = p2->right;
p2->right = p1;
p1->height = max(bsheight(p1->left),bsheight(p1->right)) + 1;
p2->height = max(bsheight(p2->left),p1->height) + 1;
return p2;
}
np bstree:: srr(np &p1)
{
np p2;
p2 = p1->right;
p1->right = p2->left;
p2->left = p1;
p1->height = max(bsheight(p1->left),bsheight(p1->right)) + 1;
p2->height = max(p1->height,bsheight(p2->right)) + 1;
return p2;
}
np bstree:: drl(np &p1)
{
p1->left=srr(p1->left);
return srl(p1);
}
np bstree::drr(np &p1)
{
p1->right = srl(p1->right);
return srr(p1);
}
int bstree::nonodes(np p)
{
int count=0;
if (p!=NULL)
{
nonodes(p->left);
nonodes(p->right);
count++;
}
return count;
Department of IT Page 67
Date Structures using C++ LAB 2017-2018
}
int main()
{
//clrscr();
np root,root1,min,max;//,flag;
int a,choice,findele,delele,leftele,rightele,flag;
char ch='y';
bstree bst;
//system("clear");
root = NULL;
root1=NULL;
while(1)
{
cout<<" \nAVL Tree\n";
cout<<" ========\n";
cout<<"1.Insertion\n2.FindMin\n";
cout<<"3.FindMax\n4.Find\n5.Copy\n";
cout<<"6.Delete\n7.Preorder\n8.Inorder\n";
cout<<"9.Postorder\n10.height\n11.EXIT\n";
cout<<"Enter the choice:";
cin>>choice;
switch(choice)
{
case 1:
cout<<"New node's value ?";
cin>>a;
bst.insert(a,root);
break;
case 2:
if (root !=NULL)
{
min=bst.findmin(root);
cout<<"Min element : "<<min->element;
}
break;
case 3:
if (root !=NULL)
{
max=bst.findmax(root);
cout<<"Max element : "<<max->element;
}
break;
case 4:
cout<<"Search node : ";
cin>>findele;
if (root != NULL)
bst.find(findele,root);
break;
case 5:
Department of IT Page 68
Date Structures using C++ LAB 2017-2018
bst.copy(root,root1);
bst.inorder(root1);
break;
case 6:
cout<<"Delete Node ?";
cin>>delele;
bst.del(delele,root);
bst.inorder(root);
break;
case 7:
cout<<" Preorder Printing... :";
bst.preorder(root);
break;
case 8:
cout<<" Inorder Printing.... :";
bst.inorder(root);
break;
case 9:
cout<<" Postorder Printing... :";
bst.postorder(root);
break;
case 10:
cout<<" Height and Depth is ";
cout<<bst.bsheight(root);
//cout<<"No. of nodes:"<<bst.nonodes(root);
break;
case 11:exit(0);
}
}
return 0;
}
Results
Assignment:-
Department of IT Page 69
Date Structures using C++ LAB 2017-2018
Week 12 : Write a C++ program to implement all the functions of a dictionary (ADT)
Department of IT Page 70
Date Structures using C++ LAB 2017-2018
else { p->next=prev->next;
prev->next=p;
}
}
else
{
p->next=prev->next;
prev->next=p;
}
cout<<"\nInserted into dictionary Sucesfully....\n";
}
}
void dictionary::delete_d( )
{
node*curr,*prev;
cout<<"Enter key value that you want to delete...";
cin>>k;
if(head==NULL)
cout<<"\ndictionary is Underflow";
else
{ curr=head;
while(curr!=NULL)
{
if(curr->key==k)
break;
prev=curr;
curr=curr->next;
}
}
if(curr==NULL)
cout<<"Node not found...";
else
{
if(curr==head)
head=curr->next;
else
prev->next=curr->next;
delete curr;
cout<<"Item deleted from dictionary...";
}
}
void dictionary::display_d( )
{
node*t;
if(head==NULL)
cout<<"\ndictionary Under Flow";
else
{
cout<<"\nElements in the dictionary are....\n";
t=head;
Department of IT Page 71
Date Structures using C++ LAB 2017-2018
while(t!=NULL)
{
cout<<"<"<<t->key<<","<<t->value<<">";
t=t->next;
}
}
}
int main( )
{
int choice;
dictionary d1;
while(1)
{
cout<<"\n\n***Menu for Dictrionay operations***\n\n";
cout<<"1.Insert\n2.Delete\n3.DISPLAY\n4.EXIT\n";
cout<<"Enter Choice:";
cin>>choice;
switch(choice)
{
case 1: d1.insert_d();
break;
case 2: d1.delete_d( );
break;
case 3: d1.display_d( );
break;
case 4: exit(0);
default:cout<<"Invalid choice...Try again...\n";
}
}
}
Results
Assignment:-
Task Date Sign Remark
1. Write a program to implement hash table
2.Explain DFS and BFS
Department of IT Page 72
ELECTRICAL AND ELECTRONICS
LABORATORY MANUAL
PART- B
S.NO: EXPERIMENT NAME PAGE NO:
PART-A
1
E&E LAB ECE, MRCET
AIM: To verify the Kirchhoff’s voltage law and Kirchhoff’s current law for
the given circuit.
APPARATUS REQUIRED:
6 Resistors 1kΩ 1 NO
680Ω 1 NO
CIRCUIT DIAGRAMS:
GIVEN CIRCUIT:
Fig (1)
2
E&E LAB ECE, MRCET
1. KVL:
Fig (1a)
PRACTICAL CIRCUIT:
3
E&E LAB ECE, MRCET
2. KCL:
PRACTICAL CIRCUIT:
Fig (2b)
4
E&E LAB ECE, MRCET
THEORY:
a) Kirchhoff’s Voltage law states that the algebraic sum of the voltage
around any closed path in a given circuit is always zero. In any circuit,
voltage drops across the resistors always have polarities opposite to
the source polarity. When the current passes through the resistor, there
is a loss in energy and therefore a voltage drop. In any element, the
current flows from a higher potential to lower potential. Consider the
fig (1a) shown above in which there are 3 resistors are in series.
According to kickoff’s voltage law….
V = V1 + V2 + V3
b) Kirchhoff’s current law states that the sum of the currents entering a
node equal to the sum of the currents leaving the same node. Consider
the fig(1b) shown above in which there are 3 parallel paths. According
to Kirchhoff’s current law...
I = I1 + I2 + I3
PROCEDURE:
5
E&E LAB ECE, MRCET
KCL:
S.NO CURRENT THEORETICAL PRACTICAL
THROUGH
PRECAUTIONS:
1. Avoid loose connections.
2. Keep all the knobs in minimum position while switch on and off of
the supply.
RESULT:
QUESTIONS:
1. What is another name for KCL & KVL?
2. Define network and circuit?
3. What is the property of inductor and capacitor?
6
E&E LAB ECE, MRCET
APPARATUS REQUIRED:
CIRCUIT DIAGRAM:
7
E&E LAB ECE, MRCET
PRACTICAL CIRCUITS:
Fig (2)
8
E&E LAB ECE, MRCET
Fig (3)
THEORY:
SUPERPOSITION THEOREM:
Superposition theorem states that in a lumped ,linear, bilateral network consisting more
number of sources each branch current(voltage) is the algebraic sum all currents (
branch voltages), each of which is determined by considering one source at a time and
removing all other sources. In removing the sources, voltage and current sources are
replaced by internal resistances.
PROCEDURE:
1. Connect the circuit as per the fig (1).
2. Adjust the output voltage of sources X and Y to appropriate values (Say 15V and20V
respectively).
3. Note down the current (IL) through the 560 0hm resistor by using the ammeter.
4. Connect the circuit as per fig (2) and set the source Y (20V) to 0V.
5. Note down the current ( ILl) through 560ohm resistor by using ammeter.
6. Connect the circuit as per fig(3) and set the source X (15V) to 0V and source Y to
20V.
7. Note down the current (ILll) through the 560 ohm resistor branch by using ammeter.
8. Reduce the output voltage of the sources X and Y to 0V and switch off the supply.
9. Disconnect the circuit.
9
E&E LAB ECE, MRCET
TABLER COLUMNS:
10
E&E LAB ECE, MRCET
PRECAUTIONS:
1. Initially keep the RPS output voltage knob in zero volt position.
2. Set the ammeter pointer at zero position.
3. Take the readings without parallax error.
4. Avoid loose connections.
5. Avoid short circuit of RPS output terminals.
RESULT:
QUESTIONS:
1) What do you man by Unilateral and Bilateral network? Give the limitations of
Superposition theorem?
2) What are the equivalent internal impedances for an ideal voltage source and for a
Current source?
3) Transform a physical voltage source into its equivalent current source.
11
E&E LAB ECE, MRCET
(B)RECIPROCITY THEOREM
APPARATUS REQUIRED:
CIRCUIT DIAGRAM:
12
E&E LAB ECE, MRCET
PRACTICAL CIRCUITS:
CIRCUIT - 2:
THEORY:
STATEMENT:
In any linear, bilateral, single source network, the ratio of response to the excitation is
same even though the positions of excitation and response are interchanged.
PROCEDURE:
1. Connect the circuit as per the fig (1).
2. Adjust the output voltage of the regulated power supply to an appropriate value (Say
20V).
ammeter.
13
E&E LAB ECE, MRCET
4. Reduce the output voltage of the RPS to 0V and switch-off the supply.
5. Disconnect the circuit and connect the circuit as per the fig (2).
6. Adjust the output voltage of the regulated power supply to an appropriate value (Say
20V).
7. Note down the current through 10K Ω resistor from ammeter.
8. Reduce the output voltage of the RPS to 0V and switch-off the supply.
9. Disconnect the circuit.
TABULAR FORM:
From fig 1
Current
Applied voltage
S. No IL
(V1) Volt
(mA)
From fig 2
Current
Applied voltage
S. No ILI
(V2) Volt
(mA)
14
E&E LAB ECE, MRCET
OBSERVATION TABLE:
PRECAUTIONS:
1. Initially keep the RPS output voltage knob in zero volt position.
2. Set the ammeter pointer at zero position.
3. Take the readings without parallax error.
4. Avoid loose connections.
5. Avoid short circuit of RPS output terminals.
6. If voltmeter gives negative reading then interchange the terminals connections of a
voltmeter
RESULT:
QUESTIONS:
1) What is reciprocity theorem?
2) Why it is not applicable for unilateral circuits.
15
E&E LAB ECE, MRCET
AIM: To verify the maximum power transfer theorem for the given circuit.
APPARTUS REQUIRED:
CIRCUIT DIAGRAM:
PRACTICAL CIRCUIT:
16
E&E LAB ECE, MRCET
THEORY:
STATEMENT:
It states that the maximum power is transferred from the source to load when the load
resistance is equal to the internal resistance of the source.
(or)
The maximum transformer states that “A load will receive maximum power from a linear
bilateral network when its load resistance is exactly equal to the Thevenin’s resistance of
network, measured looking back into the terminals of network.
PROCEDURE:
17
E&E LAB ECE, MRCET
TABULAR COLUMN:
1
2
3
4
5
6
7
8
9
10
Theoretical Calculations:-
R = (RS+ RL)=.………………..Ω
IL = V / R =…………..…….mA
RESULT:
QUESTIONS:
1) What is maximum power transfer theorem?
2) What is the application this theorem?
18
E&E LAB ECE, MRCET
AIM: To verify Theremin’s & Norton’s theorems for the given circuit.
APPARATUS REQUIRED:
CIRCUIT DIAGRAM:
GIVEN CIRCUIT:
19
E&E LAB ECE, MRCET
20
E&E LAB ECE, MRCET
TO FIND IN:
Fig (4)
STATEMENTS:
THEVENIN’S THEOREM:
It states that in any lumped, linear network having more number of sources and elements
the equivalent circuit across any branch can be replaced by an equivalent circuit
consisting of Theremin’s equivalent voltage source Vth in series with Theremin’s
equivalent resistance Rth. Where Vth is the open circuit voltage across (branch) the two
terminals and Rth is the resistance seen from the same two terminals by replacing all
other sources with internal resistances.
21
E&E LAB ECE, MRCET
NORTON’S THEOREM:
Norton’s theorem states that in a lumped, linear network the equivalent circuit across any
branch is replaced with a current source in parallel a resistance. Where the current is the
Norton’s current which is the short circuit current though that branch and the resistance is
the Norton’s resistance which is the equivalent resistance across that branch by replacing
all the sources sources with their internal resistances?
22
E&E LAB ECE, MRCET
PROCEDURE:
1. Connect the circuit as per fig (1)
2. Adjust the output voltage of the regulated power supply to an appropriate value (Say
25V).
3. Note down the response (current, IL) through the branch of interest i.e. AB (ammeter
reading).
4. Reduce the output voltage of the regulated power supply to 0V and switch-off the
supply.
5. Disconnect the circuit and connect as per the fig (2).
6. Adjust the output voltage of the regulated power supply to 25V.
7. Note down the voltage across the load terminals AB (Voltmeter reading) that gives
Vth.
8. Reduce the output voltage of the regulated power supply to 0V and switch-off the
supply.
9. Disconnect the circuit and connect as per the fig (3).
10. Adjust the output voltage of the regulated power supply to an appropriate value (Say
V =25V).
23
E&E LAB ECE, MRCET
11. Note down the current (I) supplied by the source (ammeter reading).
12. The ratio of V and I gives the Rth.
13. Reduce the output voltage of the regulated power supply to 0V and switch-off the
supply.
14. Disconnect the circuit and connect as per the fig (4).
15. Adjust the output voltage of the regulated power supply to 25V
16. Note down the response (current, IN) through the branch AB (ammeter reading).
17. Reduce the output voltage of the regulated power supply to 0V and switch-off the
supply.
18. Disconnect the circuit
THERITICAL VALUES:
Tabulation for Thevinen’s theorem:
VTh=
VTh=
RTH=
RTH=
IL=
IL=
IN= IN=
RN= RN=
IL= IL=
24
E&E LAB ECE, MRCET
RESULT:
QUESTIONS:
1) The internal resistance of a source is 2 Ohms and is connected with an
External load of 10 Ohms resistance. What is Rth ?
2) In the above question if the voltage is 10 volts and the load is of 50 ohms
What is the load current and Vth? Verify IL?
3) If the internal resistance of a source is 5 ohms and is connected with an
External load of 25 Ohms resistance. What is Rth?
25
E&E LAB ECE, MRCET
AIM: To conduct Open circuit and Short circuit tests on 1-phase transformer to pre-
determine the efficiency, regulation and equivalent parameters.
APPARATUS:
CIRCUIT DIAGRAM:
26
E&E LAB ECE, MRCET
THEORY:
Transformer is a device which transforms the energy from one circuit to other circuit
without change of frequency.
The performance of any transformer calculated by conducting tests .OC and SC tests are
conducted on transformer to find the efficiency and regulation of the transformer at any
desired power factor.
OC TEST:
The objectives of OC test are
1. To find out the constant losses or iron losses of the transformer.
2. To find out the no load equivalent parameters.
SC TEST:
The objectives of OC test are
1. To find out the variable losses or copper losses of the transformer.
2. To find out the short circuit equivalent parameters.
By calculating the losses and equivalent parameters from the above tests the efficiency
and regulation can be calculated at any desired power factor.
27
E&E LAB ECE, MRCET
28
E&E LAB ECE, MRCET
CALCULATIONS:
29
E&E LAB ECE, MRCET
30
E&E LAB ECE, MRCET
TBULAR COLUMN:
S.NO % OF LOAD EFFICIENCY
TABULATION:
LAGGING POWER FACTOR LEADING POWER FACTOR
SNO PF %REG SNO PF %REG
1 0.3 0.3
2 0.4 0.4
3 0.5 0.5
4 0.6 0.6
5 0.7 0.7
6 0.8 0.8
7 0.9 0.9
8 UNITY UNITY
MODEL GRAPHS:
1. EFFICIENCY VS OUTPUT
31
E&E LAB ECE, MRCET
RESULT:
QUESTIONS:
1) What is a transformer?
2) Draw the equivalent circuit of transformer?
3) What is the efficiency and regulation of transformer?
32
E&E LAB ECE, MRCET
AIM: To find out efficiency by conducting the load test on 1- Transformer.
APPARATUS:
CIRCUIT DIAGRAM:
RESISTIVE LOAD
33
E&E LAB ECE, MRCET
R-L LOAD
PROCEDURE:
34
E&E LAB ECE, MRCET
OBSERVATION TBLE:
S.NO % OF LOAD EFFICIENCY
MODEL GRAPHS:
EFFICIENCY VS OUTPUT
RESULT:
QUESTIONS:
1) What is load test on transformer and what is the advantage of this test?
2) What is other test to determine the efficiency and regulation of
transformer
35
E&E LAB ECE, MRCET
PART-B
36
E&E LAB ECE,MRCET
Colour Codes are used to identify the value of resistor. The numbers to the Colour are identified
in the following sequence which is remembered as BBROY GREAT BRITAN VERY GOOD
WIFE (BBROYGBVGW) and their assignment is listed in following table.
Black Brown Red Orange Yellow Green Blue Violet Grey White
0 1 2 3 4 5 6 7 8 9
First find the tolerance band, it will typically be gold ( 5%) and
sometimes silver (10%).
Starting from the other end, identify the first band - write down the
number associated with that color
Now read the next color, so write down a its vale next to the first
value.
Now read the third or 'multiplier exponent' band and write down that as
the number of zeros.
If the 'multiplier exponent' band is Gold move the decimal point one to
the left. If the 'multiplier exponent' band is Silver move the decimal point
two places to the left. If the resistor has one more band past the tolerance
band it is a quality band.
Read the number as the '% Failure rate per 1000 hour' This is rated
assuming full wattage being applied to the resistors. (To get better failure
rates, resistors are typically specified to have twice the needed wattage
dissipation that the circuit produces). Some resistors use this band for
temco information. 1% resistors have three bands to read digits to the
left of the multiplier. They have a different temperature coefficient in
order to provide the 1% tolerance. At 1% the temperature coefficient
starts to become an important factor. at +/-200 ppm a change in
temperature of 25 Deg C causes a value change of up to 1%
37
E&E LAB ECE,MRCET
38
E&E LAB ECE,MRCET
39
E&E LAB ECE,MRCET
There are a number of parameters of importance beyond the basic capacitance and
capacitive reactance when using electrolytic capacitors. When designing circuits
using electrolytic capacitors it is necessary to take these additional parameters into
consideration for some designs, and to be aware of them when using electrolytic
capacitors
Electrolytic capacitors are often used in circuits where current levels are
relatively high. Also under some circumstances and current sourced from them
needs to have low source impedance, for example when the capacitor is being
used in a power supply circuit as a reservoir capacitor. Under these conditions it
is necessary to consult the manufacturers’ datasheets to discover whether the
electrolytic capacitor chosen will meet the requirements for the circuit. If the
ESR is high, then it will not be able to deliver the required amount of current in
the circuit, without a voltage drop resulting from the ESR which will be seen as
a source resistance.
40
E&E LAB ECE,MRCET
Frequency response:
One of the problems with electrolytic capacitors is that they have a limited
frequency response. It is found that their ESR rises with frequency and this
generally limits their use to frequencies below about 100 kHz. This is
particularly true for large capacitors, and even the smaller electrolytic
capacitors should not be relied upon at high frequencies. To gain exact details it
is necessary to consult the manufacturer’s data for a given part.
Leakage:
Ripple current:
Tolerance:
Electrolytic capacitors have a very wide tolerance. Typically this may be -50%
+ 100%. This is not normally a problem in applications such as decoupling or
power supply smoothing, etc. However they should not be used in circuits
where the exact value is of importance.
41
E&E LAB ECE,MRCET
Polarization:
Unlike many other types of capacitor, electrolytic capacitors are polarized and
must be connected within a circuit so that they only see a voltage across them in
a particular way.
Inductor is just coil wound which provides more reactance for high frequencies
and low reactance for low frequencies.
Molded inductors follow the same scheme except the units are usually
micro henries. A brown-black-red inductor is most likely a 1000 uH. Sometimes a
silver or gold band is used as a decimal point. So a red-gold-violet inductor would
be a 2.7 uH. Also expect to see a wide silver or gold band before the first value
band and a thin tolerance band at the end. The typical Colour codes and their
values are shown in Figure 6.
42
E&E LAB ECE,MRCET
1000uH (1millihenry), 2%
6.8 uH, 5%
43
E&E LAB ECE,MRCET
2. CIRCUIT SYMBOLS
44
E&E LAB ECE,MRCET
45
E&E LAB ECE,MRCET
46
E&E LAB ECE,MRCET
47
E&E LAB ECE,MRCET
48
E&E LAB ECE,MRCET
DIODES
TRANSISTORS
6. A transistor amplifies
current. It can be used with
other components to make
TRANSISTOR PNP
an amplifier or switching
circuit.
49
E&E LAB ECE,MRCET
7. A light-sensitive transistor.
PHOTO
TRANSISTOR
4. A transducer which
PIEZO
converts electrical energy
TRANSDUCER
to sound.
5. An amplifier circuit with
one input. Really it is a
AMPLIFIER(GENER block diagram symbol
AL SYMBOL) because it represents a
circuit rather than just one
component.
6. A device which is designed
to receive or transmit radio
ARIEL (ANTENNA) signals. It is also known as
an antenna
50
E&E LAB ECE,MRCET
2. A transducer which
converts temperature (heat)
THERMISTOR
to resistance (an electrical
property).
51
E&E LAB ECE,MRCET
3. STUDY OF CRO
An oscilloscope is a test instrument which allows us to look at the 'shape' of
electrical signals by displaying a graph of voltage against time on its screen. It is
like a voltmeter with the valuable extra function of showing how the voltage varies
with time. A graticule with a 1cm grid enables us to take measurements of voltage
and time from the screen.
The graph, usually called the trace, is drawn by a beam of electrons striking
the phosphor coating of the screen making it emit light, usually green or blue. This
is similar to the way a television picture is produced.
The electrons are called cathode rays because they are emitted by the
cathode and this gives the oscilloscope its full name of cathode ray oscilloscope or
CRO. A dual trace oscilloscope can display two traces on the screen, allowing us
to easily compare the input and output of an amplifier for example. It is well worth
paying the modest extra cost to have this facility.
52
E&E LAB ECE,MRCET
BASIC OPERATION:
Y plates
electron gun
cathode
fluorescent screen
Electron beam
anode
X plates
Setting up an oscilloscope:
Oscilloscopes are complex instruments with many controls and they require some
care to set up and use successfully. It is quite easy to 'lose' the trace off the screen
if controls are set wrongly.
There is some variation in the arrangement and labeling of the many controls
so the following instructions may need to be adapted for this instrument.
The following type of trace is observed on CRO after setting up, when there is
no input signal connected.
53
E&E LAB ECE,MRCET
Connecting an oscilloscope:
The Y INPUT lead to an oscilloscope should be a co-axial lead and the figure 4
shows its construction. The central wire carries the signal and the screen is
connected to earth (0V) to shield the signal from electrical interference (usually
called noise).
Most oscilloscopes have a BNC socket for the y input and the lead is connected
with a push and twist action, to disconnect we need to twist and pull. Professionals
use a specially designed lead and probes kit for best results with high frequency
signals and when testing high resistance circuits, but this is not essential for
simpler work at audio frequencies (up to 20kHz).
54
E&E LAB ECE,MRCET
55
E&E LAB ECE,MRCET
Frequency = 1
Time period
56
E&E LAB ECE,MRCET
Time period = 1
Frequency
A) Voltage: Voltage is shown on the vertical y-axis and the scale is determined
by the Y AMPLIFIER (VOLTS/CM) control. Usually peak-peak voltage is
measured because it can be read correctly even if the position of 0V is not
known. The amplitude is half the peak-peak voltage.
B) Time period: Time is shown on the horizontal x-axis and the scale is
determined by the TIMEBASE (TIME/CM) control. The time period (often just
called period) is the time for one cycle of the signal. The frequency is the number
of cycles per second, frequency = 1/time period.
57
E&E LAB ECE,MRCET
58
E&E LAB ECE,MRCET
Most function generators allow the user to choose the shape of the output from a small
number of options.
Square wave - The signal goes directly from high to low voltage.
The duty cycle of a signal refers to the ratio of high voltage to low voltage time in a square wave
signal.
Sine wave - The signal curves like a sinusoid from high to low voltage.
59
E&E LAB ECE,MRCET
Triangle wave - The signal goes from high to low voltage at a fixed rate.
The frequency control of a function generator controls the rate at which output
signal oscillates. On some function generators, the frequency control is a
combination of different controls. One set of controls chooses the broad frequency
range (order of magnitude) and the other selects the precise frequency. This allows
the function generator to handle the enormous variation in frequency scale needed
for signals.
60
E&E LAB ECE,MRCET
There are many types of power supply. Most are designed to convert high
voltage AC mains electricity to a suitable low voltage supply for electronic circuits
and other devices. A power supply can by broken down into a series of blocks,
each of which performs a particular function. For example a 5V regulated supply:
Dual Supplies:
Some electronic circuits require a power supply with positive and negative
outputs as well as zero volts (0V). This is called a 'dual supply' because it is like
two ordinary supplies connected together as shown in the diagram. Dual
supplies have three outputs, for example a ±9V supply has +9V, 0V and -9V
outputs.
Figure
2:
Dual
Supply
61
E&E LAB ECE,MRCET
Breadboard:
Strip board:
62
E&E LAB ECE,MRCET
Strip board has parallel strips of copper track on one side. The strips are 0.1"
(2.54mm) apart and there are holes every 0.1" (2.54mm). Strip board requires no
special preparation other than cutting to size. It can be cut with a junior hacksaw,
or simply snap it along the lines of holes by putting it over the edge of a bench or
table and pushing hard.
Printed circuit boards have copper tracks connecting the holes where
the components are placed. They are designed specially for each circuit and make
construction very easy. However, producing the PCB requires special equipment
so this method is not recommended if you are a beginner unless the PCB is
provided for you.
63
E&E LAB ECE,MRCET
PCBs are inexpensive, and can be highly reliable. They require much more layout
effort and higher initial cost than either wire-wrapped or point-to-point constructed
circuits, but are much cheaper and faster for high-volume production. Much of the
electronics industry's PCB design, assembly, and quality control needs are set by
standards that are published by the IPC organization.
64
E&E LAB ECE,MRCET
AIM:
1. To observe and draw the Forward and Reverse bias V-I Characteristics of
a P-N Junction diode.
2. To calculate static and dynamic resistance in both forward and Reverse
Bias conditions.
APPARATUS:
1. P-N Diode IN4007 - 1No.
2. Regulated Power supply (0-30V) - 1No.
3. Resistor 1KΩ - 1No.
4. Ammeter (0-20 mA) - 1No
5. Ammeter (0-200µA) - 1No.
6. Voltmeter (0-20V) - 2No.
7. Bread board
8. Connecting wires
THEORY:
A p-n junction diode conducts only in one direction. The V-I characteristics of
the diode are curve between voltage across the diode and current flowing through
the diode. When external voltage is zero, circuit is open and the potential barrier
does not allow the current to flow. Therefore, the circuit current is zero. When P-
type (Anode) is connected to +ve terminal and n- type (cathode) is connected to –
ve terminal of the supply voltage is known as forward bias. The potential barrier is
reduced when diode is in the forward biased condition. At some forward voltage,
the potential barrier altogether eliminated and current starts flowing through the
65
E&E LAB ECE,MRCET
diode and also in the circuit. Then diode is said to be in ON state. The current
increases with increasing forward voltage.
When N-type (cathode) is connected to +ve terminal and P-type
(Anode) is connected –ve terminal of the supply voltage is known as reverse
bias and the potential barrier across the junction increases. Therefore, the junction
resistance becomes very high and a very small current (reverse saturation current)
flows in the circuit. Then diode is said to be in OFF state. The reverse bias current
is due to minority charge carriers.
CIRCUIT DIAGRAM:
A) Forward bias:
B) Reverse Bias:
66
E&E LAB ECE,MRCET
MODEL GRAPH:
PROCEDURE:
A) FORWARD BIAS:
1. Connections are made as per the circuit diagram.
2. For forward bias, the RPS +ve is connected to the anode of the diode and
RPS –ve is connected to the cathode of the diode
3. Switch on the power supply and increases the input voltage (supply voltage) in
Steps of 0.1V
4. Note down the corresponding current flowing through the diode and voltage
across the diode for each and every step of the input voltage.
5. The reading of voltage and current are tabulated.
6. Graph is plotted between voltage (Vf) on X-axis and current (If) on Y-axis.
B) REVERSE BIAS:
1. Connections are made as per the circuit diagram
2. For reverse bias, the RPS +ve is connected to the cathode of the diode and
RPS –ve is connected to the anode of the diode.
3. Switch on the power supply and increase the input voltage (supply voltage) in
Steps of 1V.
67
E&E LAB ECE,MRCET
4. Note down the corresponding current flowing through the diode voltage across
the diode for each and every step of the input voltage.
5. The readings of voltage and current are tabulated
6. Graph is plotted between voltage (VR) on X-axis and current (IR) on Y-axis.
PRECAUTIONS:
1. All the connections should be correct.
2. Parallax error should be avoided while taking the readings from the Analog
meters.
VIVA QUESTIONS:
1. Define depletion region of a diode?
2. What is meant by transition & space charge capacitance of a diode?
3. Is the V-I relationship of a diode Linear or Exponential?
4. Define cut-in voltage of a diode and specify the values for Si and Ge diodes?
5. What are the applications of a p-n diode?
6. Draw the ideal characteristics of P-N junction diode?
7. What is the diode equation?
8. What is PIV?
9. What is the break down voltage?
10. What is the effect of temperature on PN junction diodes?
68
E&E LAB ECE,MRCET
OBSERVATIONS:
A) FORWARD BIAS:
B) REVERSE BIAS:
69
E&E LAB ECE,MRCET
RESULT:
Calculating Static and Dynamic Resistance of given diode.
In forward bias condition:
70
E&E LAB ECE,MRCET
APPARATUS:
1. Zener diode -1No.
2. Regulated Power Supply (0-30v) -1No.
3. Voltmeter (0-20v) -1No.
4. Ammeter (0-20mA) -1No.
5. Resistor (1K ohm)
6. Bread Board
7. Connecting wires
THEORY:
A zener diode is heavily doped p-n junction diode, specially made to
operate in the break down region. A p-n junction diode normally does not conduct
when reverse biased. But if the reverse bias is increased, at a particular voltage it
starts conducting heavily. This voltage is called Break down Voltage. High
current through the diode can permanently damage the device
To avoid high current, we connect a resistor in series with zener
diode. Once the diode starts conducting it maintains almost constant voltage
across the terminals whatever may be the current through it, i.e., it has very low
dynamic resistance. It is used in voltage regulators.
71
E&E LAB ECE,MRCET
PROCEDURE :
CIRCUIT DIAGRAM :
A) FORWARD CHARACTERISTICS :
B) REVERSE CHARACTERISTICS:
72
E&E LAB ECE,MRCET
Model Graph:
PRECAUTIONS:
1. The terminals of the zener diode should be properly identified
2. While determined the load regulation, load should not be immediately shorted.
3. Should be ensured that the applied voltages & currents do not exceed the
ratings of the diode.
VIVAQUESTIONS:
1. What type of temp? Coefficient does the zener diode have?
2. If the impurity concentration is increased, how the depletion width effected?
3. Does the dynamic impendence of a zener diode vary?
4. Explain briefly about avalanche and zener breakdowns?
5. Draw the zener equivalent circuit?
6. Differentiate between line regulation & load regulation?
7. In which region zener diode can be used as a regulator?
73
E&E LAB ECE,MRCET
A) Static characteristics:
74
E&E LAB ECE,MRCET
B) Reverse Characteristics:
RESULT:
75
E&E LAB ECE,MRCET
AIM: To examine the input and output waveforms of half wave Rectifier and
APPARATUS:
THEORY:
76
E&E LAB ECE,MRCET
output voltage across the load resistor RL, which has the same shape as the +ve half
cycle of the input voltage.
During the negative half-cycle of the input voltage, the diode is reverse
biased and there is no current through the circuit. i.e., the voltage across R L is
zero. The net result is that only the +ve half cycle of the input voltage appears
across the load. The average value of the half wave rectified o/p voltage is the
value measured on dc voltmeter.
For practical circuits, transformer coupling is usually provided for two reasons.
1. The voltage can be stepped-up or stepped-down, as needed.
2. The ac source is electrically isolated from the rectifier. Thus preventing
shock hazards in the secondary circuit. The efficiency of the Half Wave Rectifier
is 40.6%
CIRCUIT DIAGRAM:
77
E&E LAB ECE,MRCET
PROCEDURE:
78
E&E LAB ECE,MRCET
MODEL WAVEFORMS:
A) INPUT WAVEFORM
79
E&E LAB ECE,MRCET
PRECAUTIONS:
VIVA QUESTIONS:
80
E&E LAB ECE,MRCET
AIM:
To Examine the input and output waveforms of Full Wave Rectifier and also
calculate its load regulation and ripple factor.
1. with Filter
2. without Filter
APPARATUS:
Digital multimetersMultimeter - 1No.
Transformer (6V-0-6V) - 1No.
Diode, 1N4007 - 2No.
Capacitor 100μf/470 μf - 1No.
Decade Resistance Box -1No.
Bread board
CRO and CRO probes
Connecting wires
THEORY:
The circuit of a center-tapped full wave rectifier uses two diodes
D1&D2. During positive half cycle of secondary voltage (input voltage), the
diode D1 is forward biased and D2is reverse biased. So the diode D1 conducts
and current flows through load resistor RL.
81
E&E LAB ECE,MRCET
CIRCUIT DIAGRAM:
82
E&E LAB ECE,MRCET
PROCEDURE:
THEORITICAL CALCULATIONS:
Vrms = Vm/ √2
Vm =Vrms√2
Vdc=2Vm/П
(i)Without filter:
83
E&E LAB ECE,MRCET
MODEL WAVEFORMS:
A) INPUT WAVEFORM
84
E&E LAB ECE,MRCET
PRECAUTIONS:
VIVA QUESTIONS:
RESULT
85
E&E LAB ECE,MRCET
AIM:
THEORY:
In common emitter configuration, input voltage is applied between base and
emitter terminals and out put is taken across the collector and emitter terminals.
Therefore the emitter terminal is common to both input and output.
The input characteristics resemble that of a forward biased diode curve.
This is expected since the Base-Emitter junction of the transistor is forward
biased. As compared to CB arrangement IB increases less rapidly with VBE.
Therefore input resistance of CE circuit is higher than that of CB circuit.
86
E&E LAB ECE,MRCET
The output characteristics are drawn between Ic and VCE at constant IB. the
collector current varies with VCE upto few volts only. After this the collector
current becomes almost constant, and independent of VCE. The value of VCE up to
which the collector current changes with V CE is known as Knee voltage. The
transistor always operated in the region above Knee voltage, IC is always constant
and is approximately equal to IB.The current amplification factor of CE
configuration is given by
β = ΔIC/ΔIB
Input Resistance, ri = ∆VBE /∆IB (μA) at Constant VCE
Output Résistance, ro = ∆VCE /∆IC at Constant IB (μA)
CIRCUIT DIAGRAM:
87
E&E LAB ECE,MRCET
MODEL GRAPHS:
A) INPUT CHARACTERISTICS:
B) OUTPUT CHARACTERSITICS:
88
E&E LAB ECE,MRCET
PROCEDURE:
A) INPUT CHARECTERSTICS:
B) OUTPUT CHARACTERSTICS:
PRECAUTIONS:
1. The supply voltage should not exceed the rating of the transistor
2. Meters should be connected properly according to their polarities
89
E&E LAB ECE,MRCET
VIVA QUESTIONS:
1. What is the range of β for the transistor?
2. What are the input and output impedances of CE configuration?
3. Identify various regions in the output characteristics?
4. What is the relation between α and β?
5. Define current gain in CE configuration?
OBSERVATIONS:
A) INPUT CHARACTERISTICS:
90
E&E LAB ECE,MRCET
B) OUTPUT CHAREACTARISTICS:
IB = 50 μA IB = 75 μA IB = 100 μA
S.NO
VCE(V) IC(mA) VCE(V) IC(mA) VCE(V) IC(mA)
RESULT:
91
E&E LAB ECE,MRCET
Aim:
To study the input and output characteristics of a transistor in Common Base
Configuration.
Components:
Equipment
92
E&E LAB ECE,MRCET
Specifications:
For Transistor BC 107:
Circuit Diagram:
93
E&E LAB ECE,MRCET
Operation:
The basic circuit diagram for studying input characteristics is shown in the
circuit diagram. The input is applied between emitter and base, the output is taken
between collector and base. Here base of the transistor is common to both input
and output and hence the name is Common Base Configuration.
Input characteristics are obtained between the input current and input
voltage at constant output voltage. It is plotted between VEE and IE at
constant VCB in CB configuration.
Output characteristics are obtained between the output voltage and output
current at constant input current. It is plotted between VCB and IC at constant IE in
CB configuration.
94
E&E LAB ECE,MRCET
Procedure:
Input Characteristics:
Output Characteristics:
95
E&E LAB ECE,MRCET
Observations:
Input Characteristics
Output Characteristics
96
E&E LAB ECE,MRCET
Graph:
1. Plot the input characteristics for different values of VCB by taking VEE on X-
axis and IE on Y-axis taking VCB as constant parameter.
2. Plot the output characteristics by taking VCB on X-axis and taking IC on Y-
axis taking IE as a constant parameter.
97
E&E LAB ECE,MRCET
Inference:
Precautions:
1. While performing the experiment do not exceed the ratings of the transistor.
This may lead to damage the transistor.
2. Connect voltmeter and ammeter in correct polarities as shown in the circuit
diagram.
3. Do not switch ON the power supply unless you have checked the circuit
connections as per the circuit diagram.
4. Make sure while selecting the emitter, base and collector terminals of the
transistor.
Result:
98
E&E LAB ECE,MRCET
Discussion/Viva Questions:
1. What is transistor?
Ans:
Ans: The important parameter is the common-base current gain, . The common-
base current gain is approximately the gain of current from emitter to collector in
the forward-active region. This ratio usually has a value close to unity; between
0.98 and 0.998.
Ans: It is less than unity due to recombination of charge carriers as they cross the
base region.
99