BITH132 Nov Final
BITH132 Nov Final
BITH132 Nov Final
DEPARTMENT OF INFORMATION
TECHNOLOGY/SOFTWARE ENGINEERING
November/December 2016
Time: 3 Hours
INSTRUCTIONS
Answer all five (5) questions.
(c) See the below image of a binary search tree, and traverse it using all
available methods.
(a) Define a
(i) Graph
[3]
Three jealous husbands and their wives have to cross a river using a boat
that is only big enough for 2 people at a time. How can they cross the river
so that no woman is left in the company of any other woman's husband
unless her husband is also present?
(i) Represent this problem as a decision tree with node representing the
states of the problem after each boat transition. Show all the legal
states and transitions from states corresponding to all legal
operations. [5]
(ii) Using depth first search on the tree , illustrate how a solution can be
found [5]
(iii) Use a graph path to draw your solution to this problem. [4]
Question 3
(b) (i) Illustrate Quick Sort algorithm using the following array of numbers.
[4, 3, 2, 5, 7, 1, 0] [5]
(ii) What is the Time complexity of the Quick Sort algorithm? [2]
Question 4
The wagons at the rail station are identified with an integer number which is the
wagon_id. The locomotive is the head wagon.
(a) Which data structure can you use to represent the train and its
wagons? [2]
NB: [Do not write two different programs but implement the
operations as functions that you can call in the main program.]
(c) Add Wagon() -this operation adds a wagon at any position [5]
Hint: write a menu driven program with options to add and remove
wagon.
Question 5
(a) Discuss the advantages and disadvantages of linked list over arrays?
[2]
(b) Given the string "Data Structures & Algorithms", write a program that uses
sequential search to return the index of '&' [5]
BITH132: DATA STRUECTURES AND ALGORITHMS
PAGE 4 OF 5
(c) The header file string.h provides a function strcmp (s1, s2) which takes two
pointers to strings and returns 0 if the strings pointed to by s1 and s2 are
the same; less than 0 if s1<s2; greater than 0 if s1>s2.
Write a utility program called my Strcmp which will compare the strings
passed to it either as command line arguments or otherwise [5]
(d) Describe how a polynomial is represented using singly linked lists. [3]
(e) Write an algorithm to add two polynomials represented using singly linked
list. [5]