...::: Recent Updates :::...

Wednesday, March 30, 2011

OOPS C++ ( 620003 ) Material







----------------------------
RAJ SOLUTION'S
www.rajsolution.com
www.sahinraj.blogspot.com

Tuesday, March 29, 2011

DS UNIT I – LINEAR STRUCTURES 2 Marks Questions

DATA STRUCTURES

Questions and Answers - 2 Marks

UNIT I – LINEAR STRUCTURES

1. Define Data Structures
Data Structures is defined as the way of organizing all data items that consider not
only the elements stored but also stores the relationship between the elements.

2. Define Linked Lists
Linked list consists of a series of structures, which are not necessarily adjacent in memory. Each structure contains the element and a pointer to a structure containing its successor. We call this theNext Pointer. The last cell’sNext pointer points to NULL.


3. State the different types of linked lists
The different types of linked list include singly linked list, doubly linked list and
circular linked list.

4. List the basic operations carried out in a linked list
The basic operations carried out in a linked list include:
• Creation of a list
• Insertion of a node
• Deletion of a node
• Modification of a node
• Traversal of the list

5. List out the advantages of using a linked list
• It is not necessary to specify the number of elements in a linked list during its
declaration
• Linked list can grow and shrink in size depending upon the insertion and deletion that occurs in the list
• Insertions and deletions at any place in a list can be handled easily and efficiently
• A linked list does not waste any memory space

6. List out the disadvantages of using a linked list
• Searching a particular element in a list is difficult and time consuming
• A linked list will use more storage space than an array to store the same number
of elements

7. List out the applications of a linked list
Some of the important applications of linked lists are manipulation of
polynomials, sparse matrices, stacks and queues.

8. State the difference between arrays and linked lists
Arrays Linked Lists
Size of an array is fixed Size of a list is variable
It is necessary to specify the number of elements during declaration. It is not necessary to specify the number of elements during declaration
Insertions and deletions are
somewhat difficult
Insertions and deletions are carried
out easily

It occupies less memory than a linked list for the same number of elements It occupies more memory


9. Define a stack
Stack is an ordered collection of elements in which insertions and deletions are
restricted to one end. The end from which elements are added and/or removed is referred
to as top of the stack. Stacks are also referred as piles, push-down lists and last-in-first-
out (LIFO) lists.

10. List out the basic operations that can be performed on a stack
The basic operations that can be performed on a stack are
• Push operation
• Pop operation
• Peek operation
• Empty check
• Fully occupied check

11. State the different ways of representing expressions
The different ways of representing expressions are
• Infix Notation
• Prefix Notation
• Postfix Notation

12. State the rules to be followed during infix to postfix conversions
• Fully parenthesize the expression starting from left to right. During
parenthesizing, the operators having higher precedence are first parenthesized
• Move the operators one by one to their right, such that each operator replaces
their corresponding right parenthesis
• The part of the expression, which has been converted into postfix is to be
treated as single operand

13. State the difference between stacks and linked lists
The difference between stacks and linked lists is that insertions and deletions may
occur anywhere in a linked list, but only at the top of the stack

14. Mention the advantages of representing stacks using linked lists than arrays
• It is not necessary to specify the number of elements to be stored in a stack during its declaration, since memory is allocated dynamically at run time when an element is added to the stack
• Insertions and deletions can be handled easily and efficiently
• Linked list representation of stacks can grow and shrink in size without wasting memory space, depending upon the insertion and deletion that occurs in the list
• Multiple stacks can be represented efficiently using a chain for each stack

15. Define a queue
Queue is an ordered collection of elements in which insertions are restricted to one end called the rear end and deletions are restricted to other end called the front end. Queues are also referred as First-In-First-Out (FIFO) Lists.

16. Define a priority queue
Priority queue is a collection of elements, each containing a key referred as the priority for that element. Elements can be inserted in any order (i.e., of alternating priority), but are arranged in order of their priority value in the queue. The elements are deleted from the queue in the order of their priority (i.e., the elements with the highest priority is deleted first). The elements with the same priority are given equal importance and processed accordingly.

17. State the difference between queues and linked lists
The difference between queues and linked lists is that insertions and deletions may occur anywhere in the linked list, but in queues insertions can be made only in the rear end and deletions can be made only in the front end.

18. Define a Deque
Deque (Double-Ended Queue) is another form of a queue in which insertions and deletions are made at both the front and rear ends of the queue. There are two variations of a deque, namely, input restricted deque and output restricted deque. The input
restricted deque allows insertion at one end (it can be either front or rear) only. The
output restricted deque allows deletion at one end (it can be either front or rear) only.

19. Define an Abstract Data Type (ADT)
An abstract data type is a set of operations. ADTs are mathematical abstractions; nowhere in an ADT’s definition is there any mention of how the set of operations is implemented. Objects such as lists, sets and graphs, along with their operations can be viewed as abstract data types.

20. What are the advantages of modularity?
• It is much easier to debug small routines than large routines
• It is easier for several people to work on a modular program simultaneously
• A well-written modular program places certain dependencies in only one
routine, making changes easier

21. What are the objectives of studying data structures?
• To identify and create useful mathematical entities and operations to determine what classes of problems can be solved using these entities and operations
• To determine the representation of these abstract entities and to implement the
abstract operations on these concrete representation

22. What are the types of queues?
• Linear Queues – The queue has two ends, the front end and the rear end. The rear end is where we insert elements and front end is where we delete elements. We can traverse in a linear queue in only one direction ie) from front to rear.
• Circular Queues – Another form of linear queue in which the last position is connected to the first position of the list. The circular queue is similar to linear queue has two ends, the front end and the rear end. The rear end is where we insert elements and front end is where we delete elements. We can traverse in a circular queue in only one direction ie) from front to rear.
• Double-Ended-Queue – Another form of queue in which insertions and
deletions are made at both the front and rear ends of the queue.

23. List the applications of stacks
• Towers of Hanoi
• Reversing a string
• Balanced parenthesis
• Recursion using stack
• Evaluation of arithmetic expressions

24. List the applications of queues
• Jobs submitted to printer
• Real life line
• Calls to large companies
• Access to limited resources in Universities
• Accessing files from file server

25. Why we need cursor implementation of linked lists?
Many languages such as BASIC and FORTRAN do not support pointers. If linked lists are required and pointers are not available, then an alternative implementation must be used known as cursor implementation.



----------------------------
RAJ SOLUTION'S
www.rajsolution.com
www.sahinraj.blogspot.com

Monday, March 28, 2011

Video Lecture Search Trees Data Structures With C Part III


Video Lecture Search Trees Data Structures With C
Part III




----------------------------
RAJ SOLUTION'S
www.rajsolution.com
www.sahinraj.blogspot.com

Video Lecture Search Trees Data Structures With C Part II


Video Lecture Search Trees Data Structures With C
Part II




----------------------------
RAJ SOLUTION'S
www.rajsolution.com
www.sahinraj.blogspot.com

Video Lecture Search Trees Data Structures With C


Video Lecture Search Trees Data Structures With C
Part I




----------------------------
RAJ SOLUTION'S
www.rajsolution.com
www.sahinraj.blogspot.com

Question Set 1 Data Structures ( Tree )

Laxmi Institute of Computer Applications (MCA)

Subject: 620001 – Data Structure Sem: II

Question set - I

Academic Year: 2010 - 2011

By : ManjoorHussain Kapoor 1

Q1) Define and explain trees and binary trees.

Q2) What is binary search tree? Write an algorithm to insert and delete an item from a binary search tree.

Q3) What are different methods of binary tree traversal with examples?

Q4) Write an algorithm for the in-order traversal of a binary tree.

Q5) Explain the structure of a threaded tree. What are the conventions of representing threads

Q6) Explain a height balanced binary tree.

Q7) Discuss the improvement in performance of binary trees brought by using threads.

Q8) Discuss the difference between a general tree and a binary tree. What is a complete binary tree?

Q9) What is a threaded binary tree? Explain in-order threading.

Q10) Given an account of the different classification of trees.

Q11) What are common operations performed on binary trees?

Q12) Write notes on height balanced and weight balanced trees.

Q13) Discuss the linked storage representation for binary trees.

Q14) What is a height of a binary tree?

Q15) Draw a binary tree for the expression A*B–(C+D)*(P/Q).

Q16) Discuss the internal memory representation of a binary tree using sequential and linked representation?

Q17) Give an algorithm for deleting information value X from a given lexically ordered binary tree.

Q18) How to insert a node to the right of a given node in a threaded binary tree?

Q19) Give a non-recursive algorithm for post order traversal of a binary tree.

Q20) What are the applications of tree data structure?

Q21) Explain preorder, Inorder and Post order traversals.

Q22) Explain binary tree traversals. Write an iterative function for inorder traversal. Explain the advantages of threaded binary tree over ordinary binary tree.

Q23) Explain the techniques for balancing heights of a binary tree.

Q24) What is a threaded binary tree? Write algorithm for adding an element to a threaded binary tree.

Q25) Define Binary search tree and its operations.

Q26) Define various tree traversal methods. Write non-recursive algorithm for in-order tree traversal.

Q27) What is Weight balanced tree?

Q28) Write an algorithm to convert a general tree to binary tree.

Q29) Define single rotation on AVL tree.

Q30) What is the difference between binary tree and binary search tree?

Q31) Write iterative procedure for preorder tree traversal.

Q32) Write an algorithm to traverse a binary tree in port order.

Q33) What are the uses of tree traversals?

Q34) Give the binary tree representation.

Q35) Write an iterative procedure for post-order tree traversal.

Q36) Draw a binary tree for the following expression A * B - (C - D) * (P / Q).

Q37) Write an algorithm to count the leaf nodes in a binary tree.

----------------------------

RAJ SOLUTION'S:



Sunday, March 20, 2011

GTU Question 7 (Sem 2 OOCP Practical)

//Coded By - Raj Sahin N.
//LICA MCA II
//GTU Question 7 (Sem 2 OOCP Practical)
/*Overload all the four arithmetic
operators to operate on a vector class
and also the overload the * operator to multiply scalar values to the vector class.
Overload the >> operator to input a vector and the << operator to display the vector in the form (10,20,.....).
Also overload the [] operator to access the indivisual member of the
vector.
Use Dynamic memory allocation to achieve the solution.
Write appropriate constructor and destructure for the class */

#include
#include
#include
class vector
{
int *v;
int size;
public:
vector(){};
vector(int a)
{

size=a;
v=new int[size];
for(int i=0;i {
v[i]=0;
}

}
vector operator + (vector b)
{
vector temp(size);
for(int i=0;i {
temp.v[i]=v[i]+b.v[i];
}
return temp;
}
vector operator -(vector b)
{
vector temp(size);
for(int i=0;i {
temp.v[i]=v[i]-b.v[i];
}
return temp;
}
vector operator /(vector b)
{
vector temp(size);
for(int i=0;i {
temp.v[i]=v[i]/b.v[i];
}
return temp;
}
vector operator *(vector b)
{
vector temp(size);
for(int i=0;i {
temp.v[i]=v[i]*b.v[i];
}
return temp;
}
vector operator *(int b)
{ vector temp(size);
for(int i=0;i {
temp.v[i]=v[i]*b;
}
return temp;
}
void operator << (vector b)
{
for(int i=0;i {
cout< }
}
vector operator >> (vector b)
{
for(int i=0;i {

b.v[i]=v[i];
}

}
vector operator [](int index)
{
cout< }
void disp()
{
for(int i=0;i {
cout< }
}
void read()
{
for(int i=0;i {
cin>>v[i];
}
}


};
void main()
{
clrscr();
int ch;
char conn;
vector a(5),b(5),c(c);
cout<<"Enter elements for Vector A"< a.read();
cout<<"Enter elements for Vector A"< b.read();
clrscr();
do
{
clrscr();
cout<<"1.Add + "< cout<<"2.Sub - "< cout<<"3.Mul * "< cout<<"4.Div / "< cout<<"5.Mul Value"< cout<<"6.Copy >> "< cout<<"7.Disp << "< cout<<"8.Disp Item v[i] "< cout< cin>>ch;
switch(ch)
{
case 1:
c=a+b;
c.disp();
break;
case 2:
c=a-b;
c.disp();
break;
case 3:
c=a*b;
c.disp();
break;
case 4:
c=a/b;
c.disp();
break;
case 5:
clrscr();
int val;
cout< cin>>val;
c=a*val;
c.disp();
break;
case 6:
clrscr();
a>>b;
cout< b.disp();
break;
case 7:
clrscr();
cout< a< break;
case 8:
int val1;
clrscr();
cout< cin>>val1;
a[val1-1];
break;



};
fflush(0);
cout< cin>>conn;

}while(conn=='y' || conn=='Y');
getch();
}

----------------------------
RAJ SOLUTION'S
www.rajsolution.com
www.sahinraj.blogspot.com

Simple Linklist Wit Pointers And Reference...

//Raj Sahin Nisar.
//LICA...MCA SEM-2
//Simply singly linklist..
//Same as maulin but maulin has done it wit doubly


#include
#include
#include
struct node
{
int data;
struct node *next;
};

void addbeg(struct node **start)
{
struct node *temp,*t;
temp=(struct node *)malloc(sizeof(struct node));
printf("Enter Data Value\n");
scanf("%d",&temp->data);
if(*start==NULL)
{
temp->next=NULL;
*start=temp;
}
else
{ t=(struct node *)malloc(sizeof(struct node));
t=*start;
temp->next=*start;
*start=temp;
}


}
void addend(struct node **start)
{

struct node *temp,*list;
list=(struct node *)malloc(sizeof(struct node));
temp=(struct node *)malloc(sizeof(struct node));
printf("\nEnter Data: ");
scanf("%d",&temp->data);
temp->next=NULL;
list=*start;
if(*start==NULL)
{

*start=temp;
}
else
{

while(list->next!=NULL)
{
list=list->next;
}


list->next=temp;
list=temp;

}


}
void addinbet(struct node **start)
{
int n,count=0;

struct node *temp,*list;
temp=(struct node *)malloc(sizeof(struct node));

printf("Enter Value: ");
scanf("%d",&temp->data);

printf("Enter Node Position You Want to Add After :");
scanf("%d",&n);

list=*start;
while(list->next!=NULL)
{
count++;
if(count==n)
{
temp->next=list->next;
list->next=temp;
printf("Element Added Succesfully\n");

}
/* else
{
printf("Linklist is not yet reached this limit");
}*/
list=list->next;
}


}
void delstart(struct node **start)
{
// **start=start->next;
}
void delend(struct node **start)
{
struct node *list;
list=*start;
while(list->next->next!=NULL)
{
list=list->next;
}
list->next=NULL;

}
void delinbet(struct node **start)
{
int cout=0;
int n;
struct node *list;
list=*start;
printf("Enter postion you want to delete\n");
scanf("%d",&n);

while(list->next!=NULL)
{
cout++;
if(cout==n-1)
{
list->next=list->next->next;
printf("Node Deleted Succesfully\n");
}

list=list->next;
}
}
void linksort(struct node **start)
{
int temp ;
struct node *t1,*t2=(struct node *)malloc(sizeof(struct node));
for(t1=*start;t1;t1=t1->next)
{
for(t2=t1;t2;t2=t2->next)
{
if(t1->data>t2->data)
{
temp=t1->data;
t1->data=t2->data;
t2->data=temp;
}

}

}

}
void display(struct node **start)
{
struct node * disp;
disp=(struct node *)malloc(sizeof(struct node));
disp=*start;
while(disp)
{
printf("%d\t",disp->data);

disp=disp->next;

}
}
void main()
{
int ch;
struct node *start=NULL;
char conn;
clrscr();
do
{
printf("\n1.Create @ Begning");
printf("\n2.Create @ End");
printf("\n4.Inbetween");
printf("\n5.Delete Start");
printf("\n6.Delete End");
printf("\n7.Delete Inbetween");
printf("\n8.LinkList Sort");
printf("\n3.Display");
printf("\n0.Exit\n");
scanf("\n%d",&ch);
switch(ch)
{
case 1:
addbeg(&start);
break;
case 2:

addend(&start);
break;
case 3:
display(&start);
break;
case 4:
addinbet(&start);
break;
case 5:
delstart(&start);
break;
case 6:
delend(&start);
break;
case 7:
delinbet(&start);
break;
case 8:
linksort(&start);
break;
case 0:
break;
};
printf("\nWant to continue\n");
fflush(0);
scanf("%c",&conn);
}while(conn=='y'||conn=='Y');
getch();

}


----------------------------
RAJ SOLUTION'S
www.rajsolution.com
www.sahinraj.blogspot.com

infix to postfix conversion and evollution

/* Maulin Desai
Infix To postfix conversion and evollution
Any error please cheack and mail me :)
used opeartor are
$,*,/,+,-,%
LICENCE:- GNU/GPL :) :)
MCA II sem
*/
#include
#include
#include
int top=-1;
int cnt;
int power(int a,int b)
{
int i,t=1;
for(i=0 ;i lessthan b ;)
{
t=t*a;
i++;
}
return t;
}
int priority(char t)
{
if(t=='$')
return(3);
else if(t=='^')
return(4);
else if(t=='*' || t=='/'|| t=='%')
return(5);
else if(t=='+'||t=='-')
return(6);
else
return 10;
}
void main()
{
char input[80],stack[80],postfix[80],evo[80],t;
void push(char ,char *);
char pop(char *);
int priority(char);
int i,a,b;
printf("\nEnter Prefix String:-\t");
scanf("%s",&input);
for(i=0;input[i]!='\0';increment)
{
if((priority(input[i]))==10)
{
if(input[i]=='(')
{
push(input[i],stack);
}
else if(input[i]==')')
{
while(stack[top]!='(')
{
postfix[cnt]=stack[top];
cnt++;
top--;
}
top--;
}
else
{
postfix[cnt]=input[i];
cnt++;
}

}
else if(top==-1)
{
push(input[i],stack);
}
else if((priority(input[i]))<(priority(*(stack+top))))
{
push(input[i],stack);
}
else if((priority(input[i]))>=(priority(*(stack+top))))
{
while((priority(input[i]))>=(priority(*(stack+top))))
{
postfix[cnt]=pop(stack);
cnt++;
}
push(input[i],stack);
}
}
while(top!=-1)
{
postfix[cnt]=pop(stack);
cnt++;
}
postfix[cnt]='\0';
printf("\n\nPostfix is:-\n");
puts(postfix);
top=-1;
for(i=0;postfix[i]!='\0';increment)
{
printf("\nvalue of top is\t%d",top);
if(priority(postfix[i])==10)
{
push(postfix[i],evo);
}
else
{
b=pop(evo)-48;
a=pop(evo)-48;
switch(postfix[i])
{
case '+':
push((a+b)+48,evo);
break;
case '-':
push((a-b)+48,evo);
break;
case '^':
break;
case '$':
printf("\npush vale :-\t%d",power(a,b));
push((power(a,b))+48,evo);
break;
case '*' :
push((a*b)+48,evo);
break;
case '/':
push((a/b)+48,evo);
break;
case '%':
push((a%b)+48,evo);
break;
}
}
}
printf("\n\nAns is:-\t%d",pop(evo)-48);
}
void push(char input,char *stack)
{
top=top+1;
stack[top]=input;
}
char pop(char *stack)
{
char k;
k=*(stack+top);
top=top-1;
return k;
}

Overater Overloading GTU OOPS

//Operater Overloading
//By Debashish Mahapatra
//LICA Sem II.

#include
#include
#include
#define size 10
class vector
{
int v[size];
int *list;
public:
int &operator[](int index)
{
if((index<0) || (index>9))
{
cout<<"Subscirpt out of range !";
}
else return v[index];
}
vector(int a)
{
list=new int [a];
size=a;
for(int i=0;i {
list[i]=0;
}
}
~vector(){};
vector()
{
for(int i=0;i {
v[i]=0;
}
}
friend ostream & operator<<(ostream &,vector &);
friend istream & operator>>(istream &,vector &);
vector operator*(int val1)
{
vector v2;
for(int i=0;i {
v2.v[i]=v[i]*val1;
}
return v2;
}
vector operator+(vector v1)
{
vector v2;
for(int i=0;i {
v2.v[i]=v[i]+v1.v[i];
}
return v2;
}
vector operator-(vector v1)
{
vector v2;
for(int i=0;i {
v2.v[i]=v[i]-v1.v[i];
}
return v2;
}
vector operator/(vector v1)
{
vector v2;
for(int i=0;i {
v2.v[i]=(v[i])/(v1.v[i]);
}
return v2;
}
void operator++()
{
for(int i=0;i {
v[i]=++v[i];
}
}
void operator--()
{
for(int i=0;i {
v[i]=--v[i];
}
}
};
ostream & operator<<(ostream &tempout, vector &tempvector)
{
for(int i=0;i {
tempout< cout<<",";
}
return tempout;
}
istream & operator>>(istream & tempin,vector & tempvector)
{
for(int i=0;i {
tempin>>tempvector.v[i];
}
return tempin;
}
void main()
{
vector v1,v2,v3;
int a,b,c,ch;
clrscr();
do
{
cout<<"\n1.<<\n2.>>\n3.+\n4.-\n5.*\n6./\n7.++\n8.--\n9.[]\n10.Exit\n";
cout<";
cin>>ch;
switch(ch)
{
case 1: cout<<"\nEnter for first vertex==>\n";
cin>>v1;
cout<<"\nEnter for second vertex==>\n";
cin>>v2;
break;

case 2: cout<<"\nFirst vertex==>\n";
cout< cout<<"\nSecond vertex==>\n";
cout< break;

case 3: v3=v1+v2;
cout< break;

case 4: v3=v1-v2;
cout< break;

case 5: cout<<"\nEnter number to multiply==>\n";
cin>>a;
v3=v1*a;
cout< cout< v3=v2*a;
cout< break;

case 6: v3=v2/v1;
cout< break;

case 7: ++v1;
++v2;
cout< cout< cout< break;

case 8: --v1;
--v2;
cout< cout< cout< break;

case 9: cout<<"\nEnter index number for v1==>\n";
cin>>a;
cout< cout<<"\nEnter index number for v2==>\n";
cin>>b;
cout<
}

}while(ch!=10);
getch();
}



------------------------
RAJ SOLUTION'S
www.rajsolution.com
www.sahinraj.blogspot.com

Operation on Double LinkList

/* Maulin Desai
hello sorting is done through Data not a link i am try to do sorting through link (node change)
here i am using gcc thats why its not support conio.h header file so add it and plese run my prog and give me feedback to add somthing new in it
if Some of the opeartion not done in prog than please send me or suggest me please and thanx sahin to create nice blog.
one day laxmi institute beacame no 1 institute :)
LICENCE :-GNU/GPL :) :) :) :) :)
*/
#include
#include
#include
struct maulin
{
int n;
char name[30];
struct maulin *next;
struct maulin *prev;
};
char ans;
int flag=0;
void main()
{
int choice;
void add(struct maulin **);
void display(struct maulin *);
void add_at(struct maulin **);
void first(struct maulin **);
void del(struct maulin **);
void sort_asc(struct maulin **);
void sort_desc(struct maulin **);
void inode_afterv(struct maulin **);
void inode_beforev(struct maulin **);
void reverse(struct maulin **);
struct maulin *header=(struct maulin *)malloc(sizeof(struct maulin));
header=NULL;
do
{
printf("\n1)Add\n2)insert node at beginning\n3)insert node before value\n4)insert node after value\n5)insert node at specific place\n6) delete\n7) sort linklist ascending\n8)sort linklist descending\n9)display\n10)Exit\n11)Reverse\nEnter choice:-");
scanf("%d",&choice);
switch(choice)
{
case 1:
add(&header);
break;
case 2:
first(&header);
break;
case 3:
inode_beforev(&header);
break;
case 4:
inode_afterv(&header);
break;
case 5:
add_at(&header);
break;
case 6:
del(&header);
break;
case 7:
sort_asc(&header);
display(header);
break;
case 8:
sort_desc(&header);
display(header);
break;
case 9:
display(header);
break;
case 10:
exit(0);
case 11:
reverse(&header);
break;
default:
printf("\nno case found\n");
}
printf("\nDo you want to continue:-");
scanf("%s",&ans);
}
while(ans!='n');
}
void add(struct maulin **head)
{
struct maulin *k,*temp;
temp=(struct maulin *)malloc(sizeof(struct maulin));
printf("\nEnter Number:-\t");
scanf("%d",&temp->n);
printf("\nEnter Name:-\t");
scanf("%s",&temp->name);
temp->next=NULL;
temp->prev=NULL;
if((*head)==NULL)
{
(*head)=temp;
}
else
{
k=(*head);
while(k->next!=NULL)
{
k=k->next;
}
k->next=temp;
temp->prev=k;
}
}
void first(struct maulin **head)
{
struct maulin *temp;
temp=(struct maulin *)malloc(sizeof(struct maulin));
printf("\nEnter Number:-\t");
scanf("%d",&temp->n);
printf("\nEnter Name:-\t");
scanf("%s",&temp->name);
temp->next=NULL;
temp->prev=NULL;
temp->next=(*head);
(*head)=temp;
}
void inode_afterv(struct maulin **head)
{
int value;
struct maulin *temp,*search;
printf("\nEnter Value for Search:-\t");
scanf("%d",&value);
search=(*head);
while(search!=NULL)
{
if(search->n==value)
{
if(search->next==NULL)
{
flag=1;
temp=(struct maulin *)malloc(sizeof(struct maulin));
printf("\nEnter Number:-\t");
scanf("%d",&temp->n);
printf("\nEnter Name:-\t");
scanf("%s",&temp->name);
temp->next=NULL;
temp->prev=NULL;
temp->prev=search;
search->next=temp;
break;
}
flag=1;
temp=(struct maulin *)malloc(sizeof(struct maulin));
printf("\nEnter Number:-\t");
scanf("%d",&temp->n);
printf("\nEnter Name:-\t");
scanf("%s",&temp->name);
temp->next=NULL;
temp->prev=NULL;
temp->prev=search;
temp->next=search->next;
search->next=temp;
(temp->next)->prev=temp;
}
search=search->next;
}
(flag==1)?printf("\nNode Found And New Node Added After Node\n"):printf("\nNo Record Found\n");
flag=0;

}
void inode_beforev(struct maulin **head)
{
int value;
struct maulin *temp,*search;
printf("\nEnter Value for Search:-\t");
scanf("%d",&value);
search=(*head);
while(search!=NULL)
{
if((*head)->n==value)
{
printf("\nmaulin in\n");
flag=1;
temp=(struct maulin *)malloc(sizeof(struct maulin));
printf("\nEnter Number:-\t");
scanf("%d",&temp->n);
printf("\nEnter Name:-\t");
scanf("%s",&temp->name);
temp->next=NULL;
temp->prev=NULL;
search->prev=temp;
temp->next=search;
(*head)=temp;
break;
}
if(search->n==value)
{
flag=1;
temp=(struct maulin *)malloc(sizeof(struct maulin));
printf("\nEnter Number:-\t");
scanf("%d",&temp->n);
printf("\nEnter Name:-\t");
scanf("%s",&temp->name);
temp->next=NULL;
temp->prev=NULL;
temp->prev=search->prev;
temp->next=search;
search->prev=temp;
(temp->prev)->next=temp;
}
search=search->next;
}
(flag==1)?printf("\nNode Found And New Node Added befor Node\n"):printf("\nNo Record Found\n");
flag=0;
}
void del(struct maulin **head)
{
struct maulin *del;
int val;
printf("\nEnter Value for delete:-\t");
scanf("%d",&val);
del=(*head);
while(del!=NULL)
{
if((*head)->n==val)
{
if((*head)->next==NULL)
{
free(*head);
printf("\n LinkList is Empty oops\n :(");
return;
}
flag=1;
(del->next)->prev=NULL;
*head=(del->next);
free(del);
goto a;
}
if(del->n==val)
{
if(del->next==NULL)
{
flag=1;
(del->prev)->next=NULL;
free(del);
goto a;
}
flag=1;
(del->next)->prev=del->prev;
(del->prev)->next=del->next;
free(del);
}
del=del->next;
}
a:
(flag==1)?printf("\nNode Deleted Succesfully\n"):printf("\nNo Node Found");
}
void display(struct maulin *p)
{
while(p!=NULL)
{
printf("%d\t",p->n);
puts(p->name);
p=p->next;
}
printf("End of line:)");
}
void add_at(struct maulin **t)
{
int n,i;
printf("Enter a Postion to Enter a Particular Node:-\t");
scanf("%d",&n);
struct maulin *node =(struct maulin *)malloc(sizeof(struct maulin)),*temp=(struct maulin *)malloc(sizeof(struct maulin));
temp=*t;
for(i=1;i {
temp=temp->next;
if(temp==NULL)
{
flag=0;
goto k;
}
else
{
flag=1;
}
}
if(n==1)
{
printf("Enter value in node no:-");
scanf("%d",&node->n);
printf("Enter value in node name:-");
scanf("%s",&node->name);
node->prev=NULL;
node->next=temp;
temp->prev=node;
(*t)=node;
}
else
{
printf("Enter value in node no:-");
scanf("%d",&node->n);
printf("Enter value in node name:-");
scanf("%s",&node->name);
node->prev=temp->prev;
node->next=temp;
temp->prev=node;
(node->prev)->next=node;
}
k:
(flag==1)?printf("\nNode Found And New Node Added befor Node\n"):printf("\nNo Record Found\n");
}
void sort_asc(struct maulin **h)
{
struct maulin *i,*j;
int temp;
char temp_name[30];
i=(*h);
j=(*h);
for(;i!=NULL;i=i->next)
{
for(j=i->next;j!=NULL;j=j->next)
{
if(i->n>=j->n)
{
temp=i->n;
i->n=j->n;
j->n=temp;
strcpy(temp_name,i->name);
strcpy(i->name,j->name);
strcpy(j->name,temp_name);

}
}
}
}
void sort_desc(struct maulin **h)
{
struct maulin *i,*j;
int temp;
char temp_name[30];
i=(*h);
j=(*h);
for(;i!=NULL;i=i->next)
{
for(j=i->next;j!=NULL;j=j->next)
{
if(i->n<=j->n)
{
temp=i->n;
i->n=j->n;
j->n=temp;
strcpy(temp_name,i->name);
strcpy(i->name,j->name);
strcpy(j->name,temp_name);
}
}
}
}
void reverse(struct maulin **head)
{
struct maulin *f,*s;
f=(*head);
s=(*head);
(*head)=(*head)->next;
f->next=NULL;
f->prev=(*head);
while((*head)!=NULL)
{
f=s;
s=(*head);
(*head)=(*head)->next;
s->next=f;
s->prev=(*head);
if((*head)->next==NULL)
{
(*head)->prev=NULL;
(*head)->next=s;
return;
}
}
}

Saturday, March 19, 2011

Questions On Queues- Data Structure Sem: II

Laxmi Institute of Computer Applications (MCA)
Subject: 620001 – Data Structure Sem: II
Question set - II Academic Year: 2010 - 2011
By : ManjoorHussain Kapoor 1

Q1) Write an algorithm to add a new element of information to a circular queue?

Q2) Write algorithms for inserting and deleting items from a DEQUE?

Q3) Distinguish between Queues and Deques?

Q4) Describe a circular DEQUEUE? Write algorithms for insertion into front end and deletion
from the back end of this structure?

Q5) Explain the implementation of circular queue using array. How an “empty queue” is distinguished
from a “full queue”? Write necessary functions to perform all valid operations on circular queue.

Q6) Discuss the advantages of Circular queue with example.

Q7) What are the various queue operations? Explain.

Q8) What are dequeues ? Explain various representations of dequeues.

Q9) What are the difference between a stack and a queue?

Q10) Write the insertion and deletion procedures in a queue.

Q11) Mention and explain various types of queues. Compare them.

Q12) What is meant by circular queue and deque ?

Q13) What is meant by priority queue?

Questions On Stack- Data Structure Sem: II

Laxmi Institute of Computer Applications (MCA)
Subject: 620001 – Data Structure Sem: II
Question set - I Academic Year: 2010 - 2011
By : ManjoorHussain Kapoor 1

Q1) What is meant by recursive algorithm?

Q2) Define and explain the data structure stacks.

Q3) What are the operations on stack and an important use for this structure?

Q4) Explain how infix expressions are converted to polish notation. Illustrate the answer
with suitable example ?

Q5) Discuss the use of a stack in implementing recursive procedures.

Q6) Explain recursion with one example.

Q7) Write an algorithm for deleting an element from a stack.

Q8) Show how to evaluate the expression in the postfix using stack.

Q9) Discuss the application of stacks.

Q10) Write an algorithm to transform from prefix to postfix.

Q11) Explain the principle of recursive algorithm.

Q12) Outline an algorithm to convert a given postfix expression to infix form.

Q13) Explain the implementation of stack using arrays and linked list. Write appropriate functions to
perform valid operations on stack.

Q14) What is a Stack? Explain any two operations performed on a Stack with required algorithms.

Q15) Convert the following infix expression into postfix form (A + B)* (C + B)* (ElF).

Q16) What is recursion? Give the application of recursion with programs.

Q17) What are the various stack operations? Explain.

Q18) Explain the application of stack for conversion of infix to postfix.

Q19) Write procedures for Push and Prop operations on stacks.

Q20) Write procedure to convert infix to portfix expressions.

Q21) Explain the linked list implementation of a LIFO structure.

Q22) Write the prefix and postfix form for: A + B * (C - D) / (E - F).

Q23) Which data structure would you use for recursive procedures?

Q24) Explain how a postfix expression is evaluated using stack with suitable example ?

Questions On Link list Data Structure Sem: II

Laxmi Institute of Computer Applications (MCA)
Subject: 620001 – Data Structure Sem: II
Question set - II Academic Year: 2010 - 2011
By : ManjoorHussain Kapoor 1

Q1) Write an algorithm to count the number of nodes in a singly linked list?

Q2) Write an algorithm to insert a node in a linked list?

Q3) Describe how a polynomial is represented using singly linked lists. Write an algorithm to add two
polynomials represented using linked list?

Q4) What is doubly linked list? Write an algorithm to add and delete a node from it?

Q5) Explain the array representation of a priority queue? Write an algorithm for deleting and inserting
in a priority queue? Mention its Applications?

Q6) Discuss the advantages and disadvantages of singly linked list?

Q7) Explain the structure of a doubly linked list. Write a general algorithm for inserting and deleting
nodes in the middle?

Q8) Compare and distinguish between singly linked lists and doubly linked lists?

Q9) Discuss the advantages and disadvantages of linked list over arrays?

Q10) Write down the steps to invert a singly-linked circular linked list?

Q11) How do you use circular queue in programming?

Q12) How doubly linked list can be used for dynamic storage?

Q13) What is a Priority queue? How is it represented in the memory?

Q14) What is a linked list? What are its advantages over array? How is linked list implemented
in the memory?

Q15) Develop an algorithm to insert a node to the right of kth node of a singly linked linear list.

Q16) Evaluate the complexity of the algorithm to add two polynomials in the form of linked lists.

Q17) Compare linear data structures with linked storage data types.

Q18) Explain the representation of polynomials using linked lists.

Q19) Write algorithms for adding and deleting elements from a circular queue implemented as linked
list.

Q20) Explain any three operations on a linked list. Write algorithms for these operations.

Q21) Discuss the advantage of circular queue with examples.

Q22) Explain how pointers are used to implement linked list structures.

Q23) Differentiate singly linked list and circularly linked list.

Q24) Write an algorithm to traverse elements in a singly linked list

Q25) Explain about frequency count and give an example. Write procedures for circular queue
operations.

Q26) Write procedure for searching an element in a singly linked list.

Q27) What is the advantage of a doubly linked list compared to a singly linked list?
// Singly Linked List With all Operations
// Pointers As Paramerter
// Raj Sahin N.
#include
#include

struct LL
{
char Name[30];
int Age;
struct LL *Next;
};

typedef struct LL Node;

void Insert(Node **Head,char *Name,int Age,int Pos)
{
int Temp=1;
Node *Curr,*NewNode;
NewNode=(Node *)malloc(sizeof(Node));
strcpy(NewNode->Name,Name);
NewNode->Age=Age;
if(Pos > Size(*Head)+1)
{
printf("Position Out Of Bound Exception...");
getch();
}
else if(Pos==1)
{
NewNode->Next=*Head;
*Head=NewNode;
}
else
{
Curr=*Head;
while(Curr->Next != NULL && Temp {
Curr=Curr->Next;
Temp++;
}
NewNode->Next=Curr->Next;
Curr->Next=NewNode;
}
}

void Create(Node **Head)
{
Node *Curr,*NewNode;
int Ch=0,Age;
char Name[30];
do
{
NewNode=(Node *)malloc(sizeof(Node));
printf("Enter Name : ");
fflush(stdin);
gets(NewNode->Name);
printf("Enter Age : ");
scanf("%d",&NewNode->Age);
NewNode->Next=NULL;
if(*Head==NULL)
*Head=NewNode;
else
{
Curr=*Head;
while(Curr->Next != NULL)
Curr=Curr->Next;
Curr->Next=NewNode;
}
printf("\n Enter Choice (1-Enter Data / 0-Exit):");
scanf("%d",&Ch);
}while(Ch);
}

int Delete(Node **Head,char *Name)
{
int Pos=0;
Node *Curr=*Head,*Prev=NULL;
while(Curr!=NULL)
{
Pos++;
if(strcmp(Curr->Name,Name) == 0)
{
if(Pos==1)
*Head=(*Head)->Next;
else
Prev->Next=Curr->Next;
return Pos;
}
Prev=Curr;
Curr=Curr->Next;
}
return 0;
}

void Show(Node *Head)
{
if(Head != NULL)
{
printf("---------------------------------------------\n");
printf("Name : %s\n",Head->Name);
printf("Age : %d\n",Head->Age);
Show(Head->Next);
}
}

void Reverse(Node *Head)
{
if(Head != NULL)
{
Reverse(Head->Next);
printf("---------------------------------------------\n");
printf("Name : %s\n",Head->Name);
printf("Age : %d\n",Head->Age);
}
}

void ReverseLL(Node **Head)
{
Node *TempCurr,*TempPrev,*Curr,*Prev;
Prev=*Head;
Curr=(*Head)->Next;
while(1)
{
TempCurr=Curr;
TempPrev=Prev;
Prev=Curr;
Curr=Curr->Next;
if(TempPrev==*Head)
TempPrev->Next=NULL;
if(TempCurr!=NULL)
{
TempCurr->Next=TempPrev;
}
else
{
*Head=TempPrev;
break;
}
}
}

int Size(Node *Head)
{
if(Head == NULL)
return 0;
else
return 1+Size(Head->Next);
}

void main()
{
char Name[30];
int Age;
Node *Head=NULL;
int Ch,Temp;
do
{
clrscr();
printf("-------------------------------------\n");
printf("1. Create Linked List.\n");
printf("2. Insert In Linked List.\n");
printf("3. Delete From Linked List.\n");
printf("4. Print Linked List in Order.\n");
printf("5. Print Linked List in Reverse Order.\n");
printf("6. Reverse The Whole Linked List.\n");
printf("0. Exit.\n");
printf("-------------------------------------\n\n");
printf("Enter Your Choice : ");
scanf("%d",&Ch);
switch(Ch)
{
case 1:
Create(&Head);
break;
case 2:
printf("Enter Name : ");
fflush(stdin);
gets(Name);
printf("Enter Age : ");
scanf("%d",&Age);
printf("Enter Position For Insert Node (Less Than %d) : ",Size(Head));
scanf("%d",&Temp);
Insert(&Head,Name,Age,Temp);
break;
case 3:
printf("Enter Name For Delete: ");
fflush(stdin);
gets(Name);
if((Temp = Delete(&Head,Name)) == 0)
printf("Record Not Found...");
else
printf("Record Deleted Successfully At Position ");
getch();
break;
case 4:
Show(Head);
getch();
break;
case 5:
Reverse(Head);
getch();
break;
case 6:
ReverseLL(&Head);
break;
}
}while(Ch);
}

Tuesday, March 15, 2011

LinkList

//Raj Sahin Nisar.
//LICA...MCA SEM-2
//All Operations of Linkllist
//Guided By: Manjoor Hussain Kapoor

#include
#include
#include
struct node
{
int data;
struct node *next;
}*start=NULL,*list;

void addbeg()
{
struct node *temp,*t;
temp=(struct node *)malloc(sizeof(struct node));
printf("Enter Data Value\n");
scanf("%d",&temp->data);
if(start==NULL)
{
temp->next=NULL;
start=temp;
}
else
{ t=(struct node *)malloc(sizeof(struct node));
t=start;
temp->next=start;
start=temp;
}


}
void addend()
{

struct node *temp;
temp=(struct node *)malloc(sizeof(struct node));
printf("\nEnter Data: ");
scanf("%d",&temp->data);
temp->next=NULL;
list=start;
if(start==NULL)
{

start=temp;
}
else
{

while(list->next!=NULL)
{
list=list->next;
}


list->next=temp;
list=temp;

}


}
void addinbet()
{
int n,count=0;

struct node *temp;
temp=(struct node *)malloc(sizeof(struct node));

printf("Enter Value: ");
scanf("%d",&temp->data);

printf("Enter Node Position You Want to Add After :");
scanf("%d",&n);

list=start;
while(list->next!=NULL)
{
count++;
if(count==n)
{
temp->next=list->next;
list->next=temp;
printf("Element Added Succesfully\n");

}
/* else
{
printf("Linklist is not yet reached this limit");
}*/
list=list->next;
}


}
void delstart()
{
start=start->next;
}
void delend()
{
list=start;
while(list->next->next!=NULL)
{
list=list->next;
}
list->next=NULL;

}
void delinbet()
{
int cout=0;
int n;
list=start;
printf("Enter postion you want to delete\n");
scanf("%d",&n);

while(list->next!=NULL)
{
cout++;
if(cout==n-1)
{
list->next=list->next->next;
printf("Node Deleted Succesfully\n");
}

list=list->next;
}
}
void linksort()
{
int temp ;
struct node *t1,*t2=(struct node *)malloc(sizeof(struct node));
for(t1=start;t1;t1=t1->next)
{
for(t2=t1;t2;t2=t2->next)
{
if(t1->data>t2->data)
{
temp=t1->data;
t1->data=t2->data;
t2->data=temp;
}

}

}

}
void display()
{
struct node * disp;
disp=(struct node *)malloc(sizeof(struct node));
disp=start;
while(disp)
{
printf("%d\t",disp->data);

disp=disp->next;

}
}
void main()
{
int ch;
char conn;
clrscr();
do
{
printf("\n1.Create @ Begning");
printf("\n2.Create @ End");
printf("\n4.Inbetween");
printf("\n5.Delete Start");
printf("\n6.Delete End");
printf("\n7.Delete Inbetween");
printf("\n8.LinkList Sort");
printf("\n3.Display");
printf("\n0.Exit\n");
scanf("\n%d",&ch);
switch(ch)
{
case 1:
addbeg();
break;
case 2:
addend();
break;
case 3:
display();
break;
case 4:
addinbet();
break;
case 5:
delstart();
break;
case 6:
delend();
break;
case 7:
delinbet();
break;
case 8:
linksort();
break;
case 0:
break;
};
printf("\nWant to continue\n");
fflush(0);
scanf("%c",&conn);
}while(conn=='y'||conn=='Y');
getch();

}