Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

UNIVERSITY OF LIMPOPO

TURFLOOP CAMPUS

FACULTY OF SCIENCE AND AGRICULTURE

SCHOOL OF MATHEMATICAL AND COMPUTER SCIENCES

DEPARTMENT OF COMPUTER SCIENCE

DEGREE AND DIPLOMA EXAMINATION MAY/JUNE: 2018

MODULE: SCOA021 PAPER: P

(DATA STRUCTURES)

TIME: 3 HOURS MARKS: 100

INTERNAL EXAMINER: MS DZ MASUKU

: MR MJ MATJUDA

EXTERNAL EXAMINER: MR V BALOYI

THIS PAPER CONSISTS OF …6…PAGES INCLUDING COVER PAGE

INSTRUCTIONS:

1. Answer all the questions


2. Write neatly and legibly
SCOA021 MAY/JUNE EXAMINATION 2018

SECTION A: DATA STUCTURES [50]

QUESTION 1 [10]

1.1 Write the specification for a stack ADT. [5]

1.2 Define the following concepts as applied in C++ data structure applications:
1.2.1 Data structures [1]
1.2.2 Generic data type [1]
1.2.3 Preorder traversal algorithm [1]
1.2.4 Template [1]
1.2.5 Memory leak [1]

QUESTION 2 [10]

2.1 Use a suitable ADT to create a structure called Node having two data members: item and next,
where the latter is a pointer to another node and item is of type double. Instantiate two variables
Node1, and Node2 from the created structure type. [5]
2.2 Suppose that you have the following declaration; where StackType is a template class.
StackType <double> stack(50);
double num;
input : 25 60 -10 40 -3.7 90 -12 9
Write C++ code that processes input as follows: If the number is non- negative, it pushes the square
root of the number onto the stack; otherwise it pushes the square of the number onto the stack. After
processing these numbers show code that outputs the elements of the stack. [5]

QUESTION 3 [10]
3.1 Create a data type called Book based on the following properties:
 the title of the book is 25 characters long, price R175.50
 Author first name, last name and gender
Instantiate two objects of type Book and declare them book1 and book2 respectively. Show how you
will initialize members of book1. [6]
3.2 Consider the following linked list of integer values and implement the statements below

10 50 100 200

Header
2|Page
SCOA021 MAY/JUNE EXAMINATION 2018

3.2.1 Insert a node with the value 300 at the end of the list. [2]
3.2.2 Update the second node of the list by replacing the value 50 with 225. [1]
3.2.3 Delete the node with value 200. [1]

QUESTION 4 [10]
4.1 Differentiate between a struct and a class [2]
4.2 Contrast static and dynamic allocation of memory. [2]
4.3 In general, the basic operations that are performed on an abstract data type are classified into
four (4) categories. Briefly describe each. [4]
4.4 Describe the accessing protocol of a queue at the logical level [2]

QUESTION 5 [10]
Multiple – choice
Write down the question number and correct answer in your answer book

5.1 An array element is accessed using [1]

5.1.1 A first- in – first – out approach

5.1.2 The dot operator

5.1.3 A member name

5.1.4 An index number

5.2. Element double Array [7] is which element of the array? [1]

5.2.1 The sixth

5.2.2 The seventh

5.2.3 The eighth

5.2.3 Impossible to tell

5.3 In a stack, the data item placed on the stack first is [1]

5.3.1 Not given an index number

5.3.2 Given the index number 0

5.3.3 The first data item to be removed

3|Page
SCOA021 MAY/JUNE EXAMINATION 2018

5.3.4 The last data item to be removed

5.4 Which of the following statements is false [1]

5.4.1 An array is a random – access structure

5.4.2 A sequential list is a random-access structure

5.4.3 A linked list is a random-access structure

5.4.4 A sequential list is always stored in a statically allocated structure

5.5 Objects of the string class [1]

5.5.1 Are zero – terminated

5.5.2 Can be copied with the assignment operator

5.5.3 NULL terminated

5.5.4 Have no member functions

5. 6 Operator overloading is [1]

5.6.1 Making C++ operators work with objects

5.6.2 Giving C++ operators more than they can handle

5.6.3 Giving new meanings to existing C++ operators

5.6.4 Making new C++ operators

5.7 When writing the code to define a member function, the name of ______ must precede the

function name with the:: operator in between. [1]

5.7.1 The class

5.7.2 The prototype

5.7.3 Scope resolution operator

5.8 Testing based on code coverage [1]

5.8.1 Regression testing

5.8.2 Black box testing

5.8.3 Clear (white box) testing

4|Page
SCOA021 MAY/JUNE EXAMINATION 2018

5.8.4 Unit testing

5.9 The programming practice of hiding the representation of data from the applications that

use the data at the logical level. [1]

5.9.1 Information hiding

5.9.2 Robustness

5.9.3 Abstraction

5.9.4 Encapsulation

5.10 In a linked list [1]

5.10.1 Each link contains a pointer to the next link

5.10.2 An array of pointers point to the links

5.10.3 Each link contains data or a pointer to data

5.10.4 The links are stored in an array

SECTION B: COMPILER THEORY (50)

QUESTION 1 [20]

1.1 Differentiate between the compiler and the interpreter. [2]


1.2 List the phases in the analysis process [3]
1.3 Give three goals of the semantic analyzer and three examples of errors reported by
the semantic analyzer. [6]
1.4 Mention any two goals for the error handler [2]
1.5 Discus static checking for the intermediate code generator. [2]
1.6 Differentiate between the analysis(front-end) and synthesis (back-end) [2]
1.7 Discuss any two error recovery methods/strategies in syntax analysis. [2]
1.8 Explain why there is a need for code optimization [1]

QUESTION 2 [30]

2.1 Suppose L1 and L2 denote languages and L1 = {a, b, c, d, e} and L2 = {1, 2}, compute the
following operations on languages? [5]
2.1.1 L1L2

5|Page
SCOA021 MAY/JUNE EXAMINATION 2018

2.1.2 L1UL2
2.1.3 L1*
2.1.4 L1+
2.1.5 L1
2.2 Consider the statement
If (A+3<400) A = 0;
else B = A∗A;
Create the tokens returned by the lexical analyzer [5]
2.3 Consider the Regular Expression (RE): (a | b)* a b b
Construct an NFA and a DFA for the above. [10]

2.4 For the following expression generate an intermediate and the final code. [10]

X=a+b
X=x*c
T = t/d

6|Page

You might also like