Malabar Institute of Technology, Anjarakandy: Mcs207 (P) Software Systems Lab
Malabar Institute of Technology, Anjarakandy: Mcs207 (P) Software Systems Lab
Malabar Institute of Technology, Anjarakandy: Mcs207 (P) Software Systems Lab
TECHNOLOGY, ANJARAKANDY
LAB RECORD
By
YOUR NAME
YOUR REG NUMBER
DEPARTMENT OF CSE
MALABAR INSTITUTE OF TECHNOLOGY,
ANJARAKANDY - 670612
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
CERTIFICATE
Certified that this is a bonafide record of the laboratory work done in the
MCS207(P) SOFTWARE SYSTEMS LAB
by
YOUR NAME
Your Reg No
of second semester M. Tech in partial fulfillment of the requirements for the award of the
degree of Master of Technology in Computer Science and Engineering of the Kannur
University/Kerala Technological University during the academic year 2014-2015
Contents
1.1 AIM
Write a program to find the k-th largest element in an array.
1.2 OBJECTIVE
The aim can be achieved by modifying a selection sort program that sorts n elements
in descending order to stop iteration after selecting k elements.
1.4 PROCEDURE
The procedure adopted for implementing the aim is as follows.
1.5 ALGORITHMS
1.5.1 Modified Selection Sort
The input parameters to the algorithm are the array (denoted as A), the number of
elements in that array (denoted as n) and the value of k (denoted as k). The output of
the algorithm will be the k-th largest element of that array.
1.6 PROGRAM
1.6.1 kth largest.c
#include<stdio.h>
#define MAX_SIZE 10
if( k > n ) {
printf( "k cannot be greater than n." );
return 2;
}
kth = k_selection_sort( A, n, k );
return 0;
}
return A[k-1];
}
1.8 RESULT
The k-th largest element of an array was found out and displayed. The scalability and
the accuracy of the program were verified.
1.9 INFERENCES
The selection sort algorithm for sorting elements in descending order can be used to
find the k-th largest element. The time complexity of the modified selection sort was
found to be O(n.k).
2 ALICE IN WONDERLAND
Experiment Number : 2 Date : 06-11-2014
2.1 AIM
Alice and her family are residents of Wonderland. One day Alice decided to pay a visit
to her uncle who is living in a far away place. She looked up the possible routes using
Google Maps. She was astounded by the number of paths returned by Google Maps.
Your task is to help Alice find the least possible amount of money with which she can
make the travel to her uncles home.
The transportation system of Wonderland was created in a special way to avoid
accidents. All the roads in Wonderland are one-way roads. But the roads are designed
in such a way that one can reach from a place to any other place.
2.2 OBJECTIVE
The problem at hand can be solved using the Dijkstras Algorithm for finding the
shortest path between two nodes in a graph. The cities in Wonderland can be seen as
the nodes and the roads can be seen as the edges.
From the description of the transportation system, it is evident that the edges
are directional. Thus, we can use the matrix representation of graph for solving the
problem.
2.4 PROCEDURE
The procedure adopted for implementing the aim is as follows.
1. Read the number of cities, the details of the roads in between them
2.5 ALGORITHMS
2.5.1 Dijkstras Algorithm
The input parameters to the algorithm are the graph, source and destination. The
array dist[i] stores the distance between the source and the corresponding city i. The
array prev[i] stores the city visited just before the city i.
The data structure Q is a priority queue with operations such as add with priority,
decrease priority, etc. The function length(u, v) will give the cost of travelling from city
u to v.
2.6 PROGRAM
2.6.1 Alice.c
#include<stdio.h>
#include<stdlib.h>
struct node {
int data;
int priority;
struct node *link;
};
int ADJACENT[MAX][MAX];
int DISTANCE[MAX];
int STATUS[MAX];
init( N );
while( 1 )
{
scanf( "%d %d %d", &v1, &v2, &w );
if( v1 == -1 && v2 == -1 && w == -1 )
break;
if( ADJACENT[v1][v2] > w )
ADJACENT[v1][v2] = w;
}
dijkstra( s, N, d );
return 0;
}
DISTANCE[source] = 0;
for( i=1; i<=N; i++ )
{
if( STATUS[i] == INITIAL )
{
enqueue( &front, &rear, i, DISTANCE[i] );
STATUS[i] = WAITING;
}
}
if( v == destination )
return;
{
DISTANCE[i] = alt;
decrease_priority( &front, &rear, i, alt );
}
}
}
}
}
void enqueue( struct node **frontp, struct node **rearp, int data, int
priority )
{
struct node *new_node = (struct node *)malloc(sizeof(struct node));
new_node->data = data;
new_node->priority = priority;
new_node->link = NULL;
return data;
}
void decrease_priority( struct node **frontp, struct node **rearp, int data,
int priority )
{
struct node *p = *frontp, *t=(*frontp)->link;
if( t == NULL || p->data == data )
p->priority = priority;
else
{
while( t->data != data )
{
p = t;
t = t->link;
}
p->link = t->link;
enqueue( frontp, rearp, data, priority );
}
}
2.8 RESULT
The least possible ticket cost for Alice to reach her uncles home is found out and
displayed.
2.9 INFERENCES
The Single Source Shortest Path algorithm deviced by Dijkstra was implemented using
C. The graph was represented using adjacency matrix and the Dijkstras algorithm was
implemented using a Priority Queue.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: