0% found this document useful (0 votes)
9 views4 pages

Data Structures and Algorithms Exam 2019

The document is an examination paper for a university course on Data Structures and Algorithms, detailing various questions related to algorithms, data types, and data structures. It includes questions on defining algorithms, characteristics of good algorithms, and practical applications of data structures like stacks and queues. The exam covers theoretical concepts as well as practical tasks such as converting expressions to postfix and performing tree traversals.

Uploaded by

shehmarl
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)
9 views4 pages

Data Structures and Algorithms Exam 2019

The document is an examination paper for a university course on Data Structures and Algorithms, detailing various questions related to algorithms, data types, and data structures. It includes questions on defining algorithms, characteristics of good algorithms, and practical applications of data structures like stacks and queues. The exam covers theoretical concepts as well as practical tasks such as converting expressions to postfix and performing tree traversals.

Uploaded by

shehmarl
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

l\1Io t111t I(e11,ra

'

UNIVERSITY EXAMINATION 2019/2020

SCHOOL OF COMPUTING AND INFORMATICS


DEPARTMENT OF INFORMATION TECHNOLOGY

BACHELOR OF SOENCE IN INFORMATION TECHNOLOGY/ BACHELOR OF BISINESS


INFORMATION TECHNOLOGY

REGULAR

UNIT CODE: BIT2203 UNIT TITLE: DATA STRUCTURES AND ALGORITHMS

DATE: DECEMBER, 2019 MAIN EXAM TIME: 2 HOURS

INSTRUCTIONS:
ANSWER QUESTION ONE AND ANY OTHER TWO QUESTIONS

Question 1 (30marks)
a) Define the term algorithm (2 Marks)

V f;,-.'l-+P"i 1
b) Outline four characteristics of a good algorithm. v "' ~ ~r i.... ~ 4 Marks) P~.I'\ ?~1'
v ~~ ·t... t tl""'i 1
c~ ·~
c) Explain the function of the following ADT primitives. Write the re levant syntax. ~ d~-:J
i) Enqueue ( ) (2 Marks)
ii) Push0 (2 Marks)
iii) IndexOf () (2 ~v1arks)

d) One of the applications of stacks in computing is to evaluc1te postfix cxpre::;.;ion. 1

From the given expression 5+4*6-3


y- i) Convert the expression into postfix expression . (2 Marks)

Paper One Pagel


ii) Using stack ADT, show how the expression will be evaluated. (4 Marks)

e) A queue is implemented using ADT list to presents its items. Discuss the efficiency
of the queue insertion and deletion operations when the ADT list Implementation
IS:

i) Array based.
ii) Pointer based. (6 Marks)

f) Outline four possible application of ADT Quey_ejn_cor:[Link]. (4 Marks)


------
9) In context of arrays, explain the term index. Show an example. (2 Marks)

Question 2 (20marlcs)
a) Using examples differentiate between a binary tree and general tree. (4 Marks)
I
b) Write a two dimensional array to explain the concept of row major order.
- I
(6 Marks)

c) Explain two types of complexities of study In data structures. (4 Marks)

d) Give the algebraic expression: (a-b/c)+d*e


i. Convert it into postfix expression. (3 Marks)

ii. Generate a binary tree from the expression. (3 Marks)

Question 3 (20marks)
a) Give three reasons why you woul d choose~ list over array. (3 Marks)

b) Name and explain th ree inpu t cases and the effect on running time of an
algorithm. (3 Marks)

Paper One Page2


• I

vr
c) D 'b
escn e th e concept and motivation of circular QUEUE. Use illustration.
(S Marks)

11
d) '. terms of computational complexity, using big o, Explain the cost of:
.') lnserting element at the end of array list. (3 Marks)
II) Inserting element at end linked list (3 Marks)

e) Write down the algorithms for inserting a new element into stack. (3 Marks)

~ -Question 4 (20marks)

a) Define the term "Algorithm analysis'. Explain two important quantitative metrics
of interest in algorithm analysis. (4 Marks)

b) Sort the array given below using INSERTION sort algorithm. (6 Marks)

130 120 16 115 8 3 4

1 1 1 I

c) Explain three characteristics of ADT Linked list. (6 Marks)

d) Using illustrative diagram, show how a new element is added in-between other
elements in linked list (4 Marks)

Question 5 (20marks)
a) Explain two data types used to Implement ADTs. (4 Marks)
,v 8 ~
v ~~
b) Perform Pre-Order, In-order and Post-Ordertraversal on the following tree.
(6 Marks)

Paper One
l
-p ( f ~~J
,._ {''1 f

~~' ~~ ~~~

c) Discuss five benefits of studying data structures and algorithms by software


developers. (10 Marks)

Paper One Page4

Common questions

Powered by AI

To evaluate the postfix expression from "a - b / c + d * e", you would process stack operations as follows: 1) Push operands onto the stack; 2) Apply the first operator to the top elements, replacing them with the result; 3) Move to the next operator, repeat the process until the stack reduces to a single element representing the final result; this emulates step-by-step calculation without explicit operator precedence handling .

A developer might prefer a linked list because it allows dynamic memory allocation, making it adaptable for varying data sizes. Additionally, linked lists facilitate easier insertion and deletion of elements without needing to shift data as required in arrays. They also support efficient memory usage since memory is allocated only as needed .

Tree traversals involve visiting all the nodes in a defined order. In Pre-Order, nodes are accessed in the order of root-left-right, which is useful for creating a copy of the tree. In-Order traversal displays nodes in a sorted sequence through left-root-right access, helpful in binary search trees. Post-Order, with its left-right-root sequence, is used for deleting the tree; understanding these procedures aids in various tree manipulations and optimizations .

Time complexity refers to the amount of computational time an algorithm takes relative to increasing input sizes, whereas space complexity concerns the amount of memory consumed during its execution. Both are critical for evaluating the efficiency of algorithms .

In an array-based queue, insertion and deletion can be inefficient because elements need to be shifted, leading to a time complexity of O(n) for these operations. Conversely, a pointer-based queue efficiently handles insertion and deletion with a time complexity of O(1) by rearranging pointers, which avoids the need to shift elements .

Software developers gain multiple benefits from studying data structures and algorithms: 1) Improved problem-solving abilities by selecting appropriate structures; 2) Efficiency in coding through understanding optimal data management; 3) Enhanced proficiency in algorithm optimization; 4) Ability to perform complexity analysis for better resource management; 5) Strong foundation for learning advanced computational techniques .

A good algorithm should have the following characteristics: 1) Input - It should take input values from a specified set; 2) Output - It should produce output values from a specified set; 3) Definiteness - Each step must be clear and unambiguous; 4) Termination - It must eventually stop after a finite number of steps .

Inserting a new element into a linked list involves: 1) Creating a new node; 2) Adjusting the pointers of the preceding node to point to this new node; 3) Setting the new node’s pointer to the successor node. This requires traversal to the correct position and re-linking, which simplifies without requiring data shifts characteristic of arrays .

Converting an algebraic expression into a postfix expression simplifies computation, as it removes the need for parentheses and operator precedence rules are inherently applied. It is particularly beneficial when evaluating mathematical expressions using stack-based algorithms, where operators follow their corresponding operands .

The computational complexity of inserting an element at the end of a linked list is O(n) if the list is singly linked, as it typically requires traversal from the head to the last node. However, if a tail pointer is maintained, this operation can be performed in O(1) time by directly linking the new node to the tail .

You might also like