Problem Set 1D

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

CS6103 SS Lab Problem Set 1D 10-Aug-2017

The assignment consists of some introductory questions.


Submission date : on or before 17-AUG-17 Thursday 10:00 am
Submit as a single .tar file.

The name of this file must be PS1D_<FIRSTNAME>_<ROLLNO>.tar


(eg : PS1D_LAXMAN_M170xxxCS.tar)
Do not add any other files except your source code.
The source codes must be named as PS1D_<FIRSTNAME>_
<ROLLNO>_<QUESTION-NUMBER>.<extension>
(eg: PS1D_LAXMAN_M170xxxCS_1.c)
If there is a part a and part b for a particular question, then, name the source
files for each part separately as in PS1D_LAXMAN_M170xxxCS_1a.c
If you do not conform to the above naming conventions, your submission might
not be recognized by some automated tools, and hence will lead to a score of 0
for the submission.
So, make sure that you follow the proper naming conventions.
All Input must be read from file PS1D_<QUESTION-NUMBER>.in
(eg : PS1D_1.txt)
Any kind of plagiarism will not be entertained.

1. Write a program to implement binary search tree with the following operations:
Insertion
Deletion
Search

Input:
1 x Insert x in the tree
2 x Delete x from the tree
3 x Search x in the tree

Sample Input:
1 10
1 20
1 30
15
2 12
2 20
3 20
3 30

Sample Output:
12 is not present in the tree
20 deleted
CS6103 SS Lab Problem Set 1D Page 2 of 4

20 not found
30 found

2. Write a program to implement following traversal in a binary search tree.Insert the elements in the
order given.

Postorder
Preorder
Inorder
Input:
First line contains number of test cases. Each test cases contains the value N, the total number of
nodes and next line contains N values each indicating values to be inserted in BST in given order.
Sample Input:
1
6
123450

Sample Output:
Postorder: 0 5 4 3 2 1
Preorder: 1 0 2 3 4 5
Inorder: 0 1 2 3 4 5

3. Perform level order traversal in a binary search tree. Insert the elements in the order given.

Input:
First line contains number of test cases. Each test cases contains the value N, the total number of
nodes and next line contains N values each indicating values to be inserted in BST in given order.
Sample Input:
1
8
4 8 1 7 2 10 15 11

Sample Output:
4 1 8 2 7 10 15 11

4. Construct a undirected graph with its adjacency list representation. Print the list.
Input:
First line contains number of test cases. Each test cases contains two integers denoting the no of
vertices(n) and edges(m).Next m lines denote pair of vertices.Vertex ordering follow the natural number
sequence starting from 1
Output:
For each vertex print the vertices with which it is connected.
Sample Input:
1
46
14
13
12
23

Cont.
CS6103 SS Lab Problem Set 1D Page 3 of 4

24
34

Sample Output:
1 -> 2 3 4
2 -> 1 4 3
3 -> 1 4 2
4 -> 1 2 3

5. Given a graph implement the following in an undirected graph:

(a) Dijkstra Algorithm


(b) Bellman Ford Algorithm
(c) Floyd Warshall Algorithm
Input:
First line contains number of test cases. Each test cases contains no of vertices(N). Next N lines con-
tains the adjacency matrix representation of the graph.Next line contains the source vertex.

Output:
Print the shortest distance from source to every other vertex.
Sample Input:
1
9
040000080
4 0 8 0 0 0 0 11 0
080704002
0 0 7 0 9 14 0 0 0
0 0 0 9 0 10 0 0 0
0 0 4 14 10 0 2 0 0
000002016
8 11 0 0 0 0 1 0 7
002000670
0

Sample Output:
0 4 12 19 21 11 9 8 14

N.B. For Floyd Warshall start vertex will not be given. You have to display the resultant matrix.

6. Find the weight of minimum spanning tree of an undirected graph using:


Prims Algorithm
Kruskal Algorithm
Input:
First line contains number of test cases. Each test cases contains two integers denoting the no of
vertices(n) and edges(m).Next m lines denote the pair of edges and the corresponding weight.

Cont.
CS6103 SS Lab Problem Set 1D Page 4 of 4

Output:
For each test case print the weight of the minimum spanning tree.

Sample Input:
1
46
141
134
125
236
243
342

Sample Output:
Prim: 6
Kruskal: 6

7. Perform the following search in a directed graph


BFS
DFS

Input:
Input:
First line contains number of test cases. Each test cases contains two integers denoting the no of
vertices(n) and edges(m).Next m lines denote the pair of vertices representing edge. Next line contains
the source vertex.Vertex ordering follow the natural number sequence starting from 0

Output:
For each test case print the BFS and DFS traversal in two lines

Sample Input:
1
46
01
02
12
20
23
33
0

Sample Output:
DFS -> 0 1 2 3
BFS -> 0 1 2 3

The End.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy