BITH132 Nov Final

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 5

FACULTY OF INFORMATION TECHNOLOGY

AND MULTIMEDIA COMMUNICATION

DEPARTMENT OF INFORMATION
TECHNOLOGY/SOFTWARE ENGINEERING

BITH132: DATA STRUCTURES AND ALGORITHMS

November/December 2016

Time: 3 Hours

INSTRUCTIONS
Answer all five (5) questions.

Each question carries 20 marks.

Answer all questions in Answer Books provided.

BITH132: DATA STRUECTURES AND ALGORITHMS


PAGE 1 OF 5
Question 1

(a) What is a binary search tree? [2]

(b) Define a typical node of a BST using a structure (struct). [3]

(c) See the below image of a binary search tree, and traverse it using all
available methods.

 In-order traversal [3]

 Pre-order traversal [3]

 Post-order traversal [3]

(d) How is node balancing implemented in

(i) AVL trees? [3]

(ii) Red-Black trees? [3]

BITH132: DATA STRUECTURES AND ALGORITHMS


PAGE 2 OF 5
Question 2

(a) Define a

(i) Graph

[3]

(ii) Tree [3]

(b) Problem: Jealous Husbands

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

(a) Define the following terms:

(i) Space complexity [3]

(ii) Time complexity


[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]

BITH132: DATA STRUECTURES AND ALGORITHMS


PAGE 3 OF 5
(c) (i) Write an algorithm for binary search. [5]

(ii) Estimate its time complexity using Big-O notation [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]

(b) Represent the wagon as a structure with two elements: the


wagon_id and pointer to type wagon which represents a link to its
next neighbour.
[3]

Implement a singly -linked list with the following operations.

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]

(d) Remove Wagon()- this operation removes a wagon at any position.


[5]

Hint: write a menu driven program with options to add and remove
wagon.

(e ) What do you use the following functions for?

(i) Malloc() [2]


(ii) Size of() [2]
(iii) Free() [1]

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]

BITH132: DATA STRUECTURES AND ALGORITHMS


PAGE 5 OF 5

You might also like