0% found this document useful (0 votes)
18 views3 pages

Data Structures and Algorithms Exam 2017

The document outlines the examination details for a Bachelor of Science in Information Technology, focusing on Data Structures and Algorithms. It includes various questions covering topics such as algorithm analysis, data structures, sorting algorithms, and graph representations. The exam consists of five questions, with students required to answer question one and any two additional questions.

Uploaded by

natembeatallia
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views3 pages

Data Structures and Algorithms Exam 2017

The document outlines the examination details for a Bachelor of Science in Information Technology, focusing on Data Structures and Algorithms. It includes various questions covering topics such as algorithm analysis, data structures, sorting algorithms, and graph representations. The exam consists of five questions, with students required to answer question one and any two additional questions.

Uploaded by

natembeatallia
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

UNIVERSITY EXAMINATIONS: 2016/2017

EXAMINATION FOR THE DEGREE IN BACHELOR OF


SCIENCE IN INFORMATION TECHNOLOGY/
BACHELOR OF BUSINESS INFORMATION TECHNOLOGY/
BIT2102 BIT 3101A BBIT 106 DATA STRUCTURES AND
ALGORITHMS
MODE: FULL TIME/PART TIME/DISTANCE LEARNING
ORDINARY EXAMINATIONS
DATE: AUGUST, 2017 DURATION: 2 HOURS

INSTRUCTIONS: Answer question ONE and any other TWO questions

QUESTION ONE [30 MARKS]

a) Differentiate between the following concepts as used in algorithm analysis.


i. Space complexity and time complexity
ii. Big O notation and theta notation
[4 Marks]
b) If you push the letters D, C, B and A in order onto a stack of characters and then pop
them, in what order will they be deleted from the stack?
[4 Marks]
c) Define a recursive function and give any two examples that can be solved recursively.
[4 Marks]
d) The numbers 20, 70, 68, 59,30,15,90,70,60,85 are to be stored for some processing in
that order. Write down the order in which the numbers will be printed if they are:
i. stored in a queue
ii. stored in a stack and
iii. stored in a binary search tree and traversed in order.
[9 Marks]
e) Explain the sufficient conditions for a binary tree to be a heap.
[2 Marks]
f) Design an algorithm for calculating Fibonacci series and estimate its big O.
[7 Marks]
QUESTION TWO [20 MARKS]

a) Write down the algorithm for merge sort and state its big O.
[6 Marks]
b) Performing operations such as delete and insert in a doubly linked list is not easy.
Explain.
[4 Marks]
c) Explain how the divide and conquer technique works. Give two examples.
[4 Marks]
d) Represent the following expression tree: (((A+B)*C+D)*E)-((A+B)*C-D) and write
the prefix and postfix expressions.
[6 Marks]

QUESTION THREE [20 MARKS]


a) Distinguish between preorder and postorder traversal of a binary tree
[4 Marks]
b) Consider the following of a table fields, construct a binary tree to represent them.

[4 Marks]
c) Describe two applications of binary search trees.
[2 Marks]
d) ) Explain why a queue is a two-point structure where a stack is one point structure
[3 Marks]
e) What is an algorithm?
[2 Marks]
f) Describe the following properties that an algorithm must have: precision, uniqueness,
finiteness, input and output.
[5 Marks]

QUESTION FOUR [20 MARKS]


a) Explain what is an in-order traversal for a binary tree?
[2 Marks]
b) Write an algorithm to execute an in-order traversal.
[3 Marks]
c) Estimate the order of magnitude for the expression 3n  2 
2

[4 Marks]
d) Describe two ways of representing a graph ADT.
[4 Marks]
e) Construct a directed graph with the vertices A,B,C,D and E using the information
below.
A B C D E
A 0 0 5 6 0
B 0 0 4 5 2
C 4 5 0 4 6
D 6 0 0 0 0
E 5 0 0 0 0
[5 Marks]
f) Briefly describe the depth first search algorithm as used in graph traversal.
[2 Marks]
QUESTION FIVE [20 MARKS]
a) If two or more values in a hash function, map to the same key, a collision is said to
occur. Collisions are not allowed in a hash table. Briefly describe the following
techniques for resolving collisions.
i. re-hashing
ii. chaining
iii. linear probing.
[6 Marks]
b) Differentiate between dynamic programming and backtracking algorithms. Give one
example for each.
[4 Marks]
c) Describe the guidelines for developing an algorithm using a pseudo code.
[5 Marks]
d) Describe the procedure for insert sort.
[3 Marks]
e) Re-arrange the following numbers in descending order using insert sort.
2,4,8,6,10,16,12,14,20,18.
[2 Marks]

Common questions

Powered by AI

A depth-first search (DFS) algorithm traverses a graph by starting at a root node and exploring as far as possible along each branch before backtracking. DFS employs a stack data structure, either explicitly or via recursive function calls, to keep track of nodes to explore further. It systematically visits nodes, marking them as visited to avoid cycles and finding connected components or spanning trees .

Recursive functions can effectively break down complex problems into simpler sub-problems by repeatedly calling themselves. Two classic examples are the calculation of factorial numbers and solving the Fibonacci sequence, where each problem can be defined in terms of a smaller case of itself, hence systematically arriving at a solution .

Dynamic programming is an optimization technique that breaks problems into subproblems, solving each one only once and storing their solutions to avoid redundant calculations; an example is the matrix chain multiplication. Backtracking is a trial-and-error method to explore possibilities to find solutions; it systematically searches paths and backtracks upon reaching dead ends, exemplified by the N-Queens problem .

Space complexity refers to the amount of memory space required by an algorithm as it runs, whereas time complexity represents the amount of computation time the algorithm needs to complete. Space complexity focuses on the memory usage considering the variables, data structures, and call stack, while time complexity evaluates the algorithm's speed, such as number of iterations or recursive calls .

Merge sort is a divide-and-conquer algorithm that involves dividing the array into halves, recursively sorting each half, and then merging the sorted halves into a complete, sorted array. It leverages recursion to handle partitioning and employs an auxiliary merging step to combine subarrays. The overall time complexity is O(n log n) resulting from the log n levels of recursion needed for division and the linear time merging step at each level .

For a binary tree to be considered a heap, it must satisfy two conditions: it should have a complete binary tree structure, where all levels are filled except possibly for the last one, which is filled from left to right, and it should adhere to the heap property, which means each node's key is greater than or equal to its children for a max-heap or is less than or equal to its children for a min-heap .

The time complexity of the straightforward recursive Fibonacci sequence calculation algorithm is O(2^n). This results from the exponential growth of recursive tree calls, where each Fibonacci number computation involves two previous computations, causing overlapping subproblems without storing intermediate results, leading to a highly redundant and inefficient process .

Big O notation describes the upper bound of an algorithm's running time, providing a worst-case scenario. Conversely, Theta notation offers a tighter bound by describing both the upper and lower bounds, representing the average-case time complexity where an algorithm's performance can be guaranteed to fall between both thresholds .

Re-hashing involves recalculating a new hash index and placing the key in the newly calculated slot upon a collision. Chaining, on the other hand, stores colliding entries in a linked list or another data structure associated with the hash index. Linear probing resolves collisions by sequentially checking the next slots in the hash table until an empty one is found. These techniques balance between handling collisions, managing the load factor, and maintaining efficient retrieval times .

When letters D, C, B, and A are pushed onto a stack and then popped, they will be popped in the reverse order, A, B, C, D. This is because stacks follow a Last In, First Out (LIFO) principle, meaning the last element added is the first to be removed .

You might also like