Sunday, 18 September 2011

Queue

Queue  is a particular kind of collection in which the entities in the collection are kept in order and the principal (or only) operations on the collection are the addition of entities to the rear terminal position and removal of entities from the front terminal position. This makes the queue a First-In-First-Out (FIFO) data structure. In a FIFO data structure, the first element added to the queue will be the first one to be removed. This is equivalent to the requirement that once an element is added, all elements that were added before have to be removed before the new element can be invoked. A queue is an example of a linear data structure


Queue are of different types:-


Linear Queue:-In this type of queue elements are in linear way where insertion can be done only from one end called REAR and deletion can be done only from one end called  FRONT.
 Representation Of Linear Queue as an array and linked list :-


Download Link:
http://www.fileserve.com/file/gYKD4BJ/Linear_Queue_as_an_array.txt
http://www.fileserve.com/file/bSFzAx6/Linear_Queue_as_linked_list.txt



Circular Queue:-


Representation Of Circular Queue as an array:-


Download Link:  http://www.fileserve.com/file/th7PZqE/CircularQueue_as_an_array.txt




Priority Queue:-Priority Queue is a collection of elements such that each element has been assigned a priority and such that the order in which the element are deleted and processed from the following rule:

  • An element of higher priority is processed before any other element of lower priority.
  • Two elements with the same priority are processed according to order in which they are added to the queue. 

Representation Of Priority Queue as a linked list :-


Download Link:  http://www.fileserve.com/file/97zVuRT/PriorityQueue_as_a_linked_list.txt




DE-Queue:-DEQueue is a linear list in which element can be added or removed at either end but not in middle .The term DEQueue is contraction of name Double Ended Queue









Wednesday, 31 August 2011

Tower Of Hanoi


The Tower of Hanoi or Towers of Hanoi , also called the Tower of Brahma or Towers of Brahma, is a mathematical game or puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape.
The objective of the puzzle is to move the entire stack to another rod, obeying the following rules:
  • Only one disk may be moved at a time.
  • Each move consists of taking the upper disk from one of the rods and sliding it onto another rod, on top of the other disks that may already be present on that rod.
  • No disk may be placed on top of a smaller disk

The solution of the Tower of Hanoi problem by recursive method for n>1 disks may be reduced to the following sub problems:
  • Move the top n-1 disks from peg A to peg B
  • Move the top disk from peg A to peg C : A->C
  • Move the top n-1 disk from peg B to peg C



In general recursive solution requires 2n-1 moves for n disks.

Download Link: 


Tuesday, 30 August 2011

Stack

In computer science, a stack is a last in, first out (LIFO) abstract data type and data structure.A stack is a list of elements may be inserted or deleted only at one end called top of the stack .This means,in particular that elements are removed from a stack in  the reverse order of that in which they were inserted into the stack A stack can have any abstract data type as an element, but is characterized by only two fundamental operations:


PUSH:"PUSH" is the term used to insert an element into a stack.


POP:"POP" is the term used to delete an element from a stack.





Overflow condition in stack:Stack is already fully filled ,you can't enter (push) new element in stack.


Underflow condition in stack:Stack is empty i.e. there is no element in stack ,you can't delete(pop) any element from the stack.








Stack implementation using array and linked list:


Download Link : http://www.fileserve.com/file/mUXxmeu/Stack.rar

Sunday, 28 August 2011

Saddle Point

Saddle Point of a matrix is the element which is smallest in the row and the highest in the corresponding column. A matrix may have One or Two saddle points or may not have a saddle point.


Coding:


#include<stdio.h>
#include<conio.h>

void main()
{
int a[3][3],i,j,k,b,pos,sp;
clrscr();
printf("enter the elements of matrix of order 3");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\nmatrix is\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d",a[i][j]);
printf(" ");
}
printf("\n");
}
for(i=0;i<3;i++)
{
b=1;
sp=a[i][0];
pos=0;
for(j=0;j<3;j++)
{
if(a[i][j]<sp)
{
sp=a[i][j];
pos=j;
}
}
for(k=0;k<3;k++)
{
if(a[k][pos]>sp)
{
b=0;
break;
}
}
if(b==1)
printf("saddle point is %d at position a[%d][%d]",sp,i+1,pos+1);}
if(b==0)
printf("no saddle point");
getch();
}


Output:







Linked List


In computer science, a linked list is a data structure consisting of a group of nodes which together represent a sequence. Under the simplest form, each node is comprised of a datum and a reference(in other words, a link) to the next node in the sequence; more complex variants add additional links. This structure allows for efficient insertion or removal of elements from any position in the sequence.
                       Singly-linked-list.svg
A linked list whose nodes contain two fields: an integer value 
and a link to the next node. 
                   


In the C language, linked lists combine the concept of an array with structures and pointers. In a way, a linked list is really like an array of structures.But, unlike with an array of structures, you can add and remove structures from the linked list easily.


Linked list can be accessed in a flexible fashion, because each piece of information carries with it a link to the next data item in the chain. In addition, a linked list retrieval operation does not remove and destroy an item from the list. In fact, you need to add a specific deletion operation to do this.

Linked lists can be :


Linear and Circular linked list:  In the last node of a list, the link field often contains a null reference, a special value used to indicate the lack of further nodes. A less common convention is to make it point to the first node of the list; in that case the list is said to be circular or circularly linked; otherwise it is said to be open or linear.


Circularly-linked-list.svg


Singly linked listSingly-linked lists contain nodes which have a data field as well as a next field, which points to the next node in the linked list.

                               Singly-linked-list.svg
                                                
Download Link: 
http://www.fileserve.com/file/dgxgZ4P/Dynamic_representation_of_singly_Linked_list.txt


Doubly linked list: In a doubly linked list, each node contains, besides the next-node link, a second link field pointing to the previous node in the sequence. The two links may be called forward(s) and backwards, or next and previous.


Doubly-linked-list.svg