6
nAmiBIA UniVERSITY OF SCIEnCE AnD TECHnOLOGY Faculty of Computing and Informatics Department of Computer Science QUALIFICATION: Bachelor of Computer Science, Bachelor of Informatics, Bachelor of Engineering : Electronics and Telecommunications, Bachelor of Engineering : Mechanical, Bachelor of Engineering : Electrical Power QUALIFICATION CODE: 07BACS, 07BAIF, 35BEET, LEVEL: NQF 6 35BEME, 35BEEP COURSE: Data Structures and Algorithms COURSE CODE: DSA610S DATE: July 2016 DURATION: 3 Hours EXAMINER(S) MODERATOR SESSION: 2 MARKS: 100 SECOND OPPORTUNITY EXAMINATION QUESTION PAPER MR MIKEABIA DR SHAULU H. NGGADA THIS QUESTION PAPER CONSISTS OF 5 PAGES (Excluding this front page) INSTRUCTIONS 1. Respond to ALL problems in sections A, B and C. 2. Respond to only ONE problem in section D. 3. Use the examination script booklet provided. 4. Each section must be started on a new page. 5. NUST examination rules and regulations apply. 6. Follow instructions in the examination script booklet. 7. Write clearly and neatly.

nAmiBIA UniVERSITYexampapers.nust.na/greenstone3/sites/localsite/collect...Problem A7 Given a binary search tree, which traversal type would print the values in the nodes in sorted

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: nAmiBIA UniVERSITYexampapers.nust.na/greenstone3/sites/localsite/collect...Problem A7 Given a binary search tree, which traversal type would print the values in the nodes in sorted

nAmiBIA UniVERSITY OF SCIEnCE AnD TECHnOLOGY

Faculty of Computing and Informatics

Department of Computer Science

QUALIFICATION: Bachelor of Computer Science, Bachelor of Informatics, Bachelor of Engineering : Electronics and Telecommunications, Bachelor of Engineering : Mechanical, Bachelor of Engineering : Electrical Power

QUALIFICATION CODE: 07BACS, 07BAIF, 35BEET, LEVEL: NQF 6

35BEME, 35BEEP

COURSE: Data Structures and Algorithms COURSE CODE: DSA610S

DATE: July 2016

DURATION: 3 Hours

EXAMINER(S)

MODERATOR

SESSION: 2

MARKS: 100

SECOND OPPORTUNITY EXAMINATION QUESTION PAPER

MR MIKEABIA

DR SHAULU H. NGGADA

THIS QUESTION PAPER CONSISTS OF 5 PAGES (Excluding this front page)

INSTRUCTIONS

1. Respond to ALL problems in sections A, B and C.

2. Respond to only ONE problem in section D.

3. Use the examination script booklet provided.

4. Each section must be started on a new page.

5. NUST examination rules and regulations apply.

6. Follow instructions in the examination script booklet.

7. Write clearly and neatly.

Page 2: nAmiBIA UniVERSITYexampapers.nust.na/greenstone3/sites/localsite/collect...Problem A7 Given a binary search tree, which traversal type would print the values in the nodes in sorted

SECTION A: Multiple Choice [10 marks]

• Respond to ALL problems in this section. • Select the best option in each of the problems in this section. • Your responses must be written in the answer booklet provided. • Marks to each question or part of question are given in [ ].

ProblemAl Which one of the below mentioned data structures is a linear data structure?

A. Binary tree B. Binary search tree C. Queue D. Tree

[1 mark] ProblemA2 Which ofthe following is true about recursion?

A. A recursive algorithm does not call itself. B. A recursive algorithm calls itself. C. A recursive algorithm works with integer arguments only. D. A recursive algorithm has the same name as its class.

[1 mark] Problem A3 Which of the following algorithms makes use of the divide and conquer approach to solving a problem?

A. Binary search B. Program C. Binary search tree D. Graph

[1 mark] ProblemA4 Which ofthe following operations can be performed on singly-linked list, doubly-linked list and circular linked list?

A. Insertion-adding an element to the list B. Deletion-removing an element from the list C. Search-seek for an element in a given list D. All of the above

[1 mark] ProblemAS A diagrammatic representation that illustrates the sequence of operations to be performed to get the solution of a problem is called ___ _

A. Program B. Pseudo code C. Flow chart D. Data structure [1 mark]

ProblemAS If the number of records to be sorted is small, then __ sorting can be efficient.

A. Merge B. Heap C. Selection

·D. Bubble

1

[1 mark]

Page 3: nAmiBIA UniVERSITYexampapers.nust.na/greenstone3/sites/localsite/collect...Problem A7 Given a binary search tree, which traversal type would print the values in the nodes in sorted

Problem A7 Given a binary search tree, which traversal type would print the values in the nodes in sorted order?

A. Preorder B. Postorder C. lnorder D. level order

[1 mark] Problem AS After deleting the key 77 using the Hibbard algorithm, which key replaces it?

A. 41 B. 47 C. 80 D. 52

[1 mark] ProblemA9 1fT is a binary search tree storing 128 elements. What is the biggest possible height ofT?

A. 125 or 126 B. 127 or 128 C. 129 or 130 D. 131 or 132

[1 mark]

Problem AlO Bubble sort is similar to selection sort in the sense that

A. Both algorithms compare every element of the list with its predecessor only if the predecessor of the given element exists.

B. Both algorithms sort the list by pushing the biggest or the smallest element to the extreme end of the list.

C. Both algorithms are used in the binary search algorithm. D. None of the above answers.

[1 mark]

SECTION B [10 marks]

• Respond to ALL problems in this section • Clearly mark each of the following assertions as true (T) or false (F) • Your responses must be written in the answer booklet provided. • Marks to each question or part of question are given in [ ].

Problem Bl A doubly-linked list is a linear data structure. [1 mark]

Problem 82 It is not sensible to discuss depth-first and breath-first searches in graphs. [1 mark]

2

Page 4: nAmiBIA UniVERSITYexampapers.nust.na/greenstone3/sites/localsite/collect...Problem A7 Given a binary search tree, which traversal type would print the values in the nodes in sorted

Problem 83 A stack follows a LILO (last-in-last-out) rule. [1 mark]

Problem 84 Push and pop operations are associated with queue data structure. [1 mark]

Problem 85 Probabilistic complexity represents the probability of an algorithm processing input in a specific time. [1 mark]

Problem 86 An algorithm is needed for every useful computer program. [1 mark]

Problem 87 Arrays can store non-homogeneous data elements. [1 mark]

Problem 88 Big-0 and Big-8 (Big-Theta) are both asymptotic notations. [1 mark]

Problem 89 A queue is a last-in-first-out (LIFO) data structure. [1 mark]

Problem 810 Singly-linked lists and doubly-linked lists have no root node. [1 mark]

SECTION C [SO marks]

• Respond to ALL problems in this section. • Your responses must be written in the answer booklet provided. • Marks to each question or part of question are given in [ ].

Problem Cl Suppose we begin with an empty stack, and perform the following operations: push 9, push 4, push 11, push 8, pop, peek, push 3, push 5, peek, push 10, pop, peek, pop, pop, push 7, push 6, pop, push 10. What is contained on the stack when we are done? Write out the contents

from top to bottom. [10 marks]

Problem C2 The following sequence of numbers needs to be sorted in descending order: 17,14,11,15,18,12,10,13,9,16. Copy and complete the table below.

Insertion Sort Selection Sort Sequence after I swap

Sequence after 2 swap

Sequence after 3 swap

Sequence after 4 swap

3

[16 marks]

Page 5: nAmiBIA UniVERSITYexampapers.nust.na/greenstone3/sites/localsite/collect...Problem A7 Given a binary search tree, which traversal type would print the values in the nodes in sorted

Problem C3 Binary search was used to search for an element in a list of elements. The element searched was found at position 3 after visiting 3 elements (including element at position 3). Assume the position numbers start at position 1.

a. Give the number of elements that were in the list if no rounding was necessary in the calculations. [3 marks]

b. Give the number of elements that were in the list if rounding down was necessary three times in the calculations. [7 marks]

Problem C4 Parallel arrays are important for many real world applications. Analyse the following and respond to problems that follow.

public boolean arrayTest(int a[ ],int b[ ]) {

}

if (a.length() != b.length()) return false;

Array.sort(a); Array. sort (b) ; for (inti= 0; i < a.length(); i++) {

if (a[i] != b[i]) return false;

} return true;

a. Explain what the algorithm expressed in the program above does. b. Explain one area where the algorithm is applicable in real life.

Problem CS

[4 marks] [4 marks]

An algorithm accepts a string, and returns a string. The returned string should be the reverse of the input string. For example, if the string "Namibia" is passed to the algorithm "aibimaN" is returned. Explain the convenience of using the stack data structure to reverse the input string by focussing on:

a. how elements are added to a stack, and [3 marks] b. how elements are removed from a stack. [3 marks]

SECTION D [30 marks] • Respond to ONE problem in this section. • Your responses must be written in the answer booklet provided. • Marks to each question or part of question are given in [ ].

Problem Dl: Binary Search Tree Given the following sequence of keys: 63 28 51 53 80 35 57 61 42 81;

a. Construct a binary search tree (BST), start with the first key in the sequence {63) as the root and proceed from left to right of the sequence. [10 marks]

b. Give the level-order traversal of the BST. Your answer should be a sequence of 10 integers, separated by whitespace. [10 marks]

c. Give the in-order traversal of the BST. Your answer should be a sequence of 10 integers, separated by whitespace. [10 marks]

4

Page 6: nAmiBIA UniVERSITYexampapers.nust.na/greenstone3/sites/localsite/collect...Problem A7 Given a binary search tree, which traversal type would print the values in the nodes in sorted

Problem 02: Mystery Code Analyse the following code:

public static void mystery(double[ ] a) {

}

int N = a.length; for (int i = 0; i < N; i++) {

}

int r i + StdRandom.uniform(N-i); //swapping code missing

Hint: StdRandom. uniform (N) returns a random integer between 0 and N-1.

a. What data type is acceptable for elements ofthe variable a? [3 marks] b. Explain what the statement int N = a .length; does. [6 marks] c. Write code in java code or pseudo code for swapping of the element at position i with the

element at r. [9 marks] d. When you put the swapping code where there is the comment I I swapping code

missing, explain the algorithmic complexity of the method. [6 marks] e. What does the mystery method do? [3 marks] f. Identify one possible application of such a method. [3 marks]

****End of Paper****

5