0% found this document useful (0 votes)
56 views13 pages

CSc9618 (A2) - Mock 3 - Paper 3

The document is a mock test for CSc-9618(A2) covering various topics including grammar rules, database design, infix and reverse Polish notation, syntax diagrams, artificial neural networks, and recursion. It consists of multiple sections with questions requiring explanations, rule modifications, and algorithm implementations. The test is structured to assess understanding of theoretical concepts and practical applications in computer science.
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)
56 views13 pages

CSc9618 (A2) - Mock 3 - Paper 3

The document is a mock test for CSc-9618(A2) covering various topics including grammar rules, database design, infix and reverse Polish notation, syntax diagrams, artificial neural networks, and recursion. It consists of multiple sections with questions requiring explanations, rule modifications, and algorithm implementations. The test is structured to assess understanding of theoretical concepts and practical applications in computer science.
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
You are on page 1/ 13

CSc-9618(A2) Mock Test 3(Session 2022-2023)

A2 Level
Exam Topic: Full Syllabus
Paper 3 Duration: 1.5 hours Total Marks: 70

Student Name: Date:


1 The grammar for a language is defined using a set of Backus-Naur rules as follows:

Rule Number Rule


1 <article> ::= a | the

2 <verb> ::= sat | walked | ate | slept

3 <noun> ::= dog | cat | person | snake

4 <nounPhrase> ::= <article><noun> | <noun>

5 <verbPhrase> ::= <nounPhrase><verb>

6 <sentence> ::= <verbPhrase> | <sentence><nounPhrase>

(a) A rule may be recursive.

State what is meant by recursive.

...................................................................................................................................................

...................................................................................................................................................

Identify the rule which is recursive.

Rule number ........................... [2]

(b) Using the above rules, explain the following statements:

(i) dog
is a valid <nounPhrase>

...........................................................................................................................................

...................................................................................................................................... [2]

(ii) a puppy sat


is an invalid <sentence>

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...................................................................................................................................... [2]
(iii) a cat slept the snake
is a valid <sentence>

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...................................................................................................................................... [4]

(iv) The adverbs quietly, quickly and slowly are to be included in the rules.
When an adverb is used in a sentence it always precedes the verb.

The rules are to be changed to make:

the cat quietly slept


a valid <sentence>

This needs a new rule. Write this new rule.

...........................................................................................................................................

It also needs a change to an existing rule. Write the amended rule.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...................................................................................................................................... [3]
2 A number of music bands use a manager to organise their bookings.
Each manager will manage one or more bands.
Each band:

• has one manager


• has a set fee payable for a booking
• plays a particular genre of music

Data for bands and managers are to be organised and stored in a relational database.

(a) A first attempt at the table design is:

MANAGER(ManagerName, Telephone, BandName, Genre, NumberInBand, SetFee)

ManagerName Telephone BandName Genre NumberInBand SetFee($)

Yi Ling Chen 908765 Rachael Daz Covers 1 200


Jazz Tones Modern jazz 4 450
Lockwood Bros 674442 Midnight Blues Modern jazz 5 350
Loose Beats Dance 3 400
Asyraf Duo Covers 2 250
The Flying Fleas Hip hop 8 700
Rachael Wang 118976 Li Wei Chen Covers 1 250
Gig Associates 567575 Buster Beats Reggae 6 600
Hits Forever Covers 3 300
Rap Incorporated Hip hop 5 800

State why the table MANAGER is not in First Normal Form (1NF).

...................................................................................................................................................

.............................................................................................................................................. [1]

(b) The database design is changed to:

BAND(BandName, Genre, NumberInBand, SetFee, ManagerName)

MANAGER(ManagerName, Telephone)

The primary key for each table has not been shown.

Assume that the band names and manager names are unique.

(i) State the relationship that exists between BAND and MANAGER.

...................................................................................................................................... [1]

(ii) Explain how this relationship is implemented.

...........................................................................................................................................

...........................................................................................................................................

...................................................................................................................................... [2]
(c) The database is to be re-designed. It will store a date for each booking made.

A band does not have more than one booking on any one date.

This additional table is suggested:

BOOKING(BandName, BookingDate, Genre, NumberInBand, SetFee)

Describe why the table BOOKING is not in Second Normal Form (2NF).

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

.............................................................................................................................................. [2]

(i) Complete the table below to show the primary key and any foreign key(s) present in each
database table.

Foreign key(s)
Table Primary key
(if any)

..............................................................................
BAND BandName
..............................................................................

..............................................................................
MANAGER ManagerName
..............................................................................

..............................................................................
BOOKING
...................................................... ..............................................................................

..............................................................................
VENUE
...................................................... ..............................................................................
[4]
3 (a) Convert the following infix expressions into reverse Polish notation:

(i) x / (a + b)

...................................................................................................................................... [1]

(ii) p ^ 2 + (2 + q) / 3
Note: ^ denotes ‘to the power of’

...................................................................................................................................... [2]

(b) Convert the following reverse Polish expression to infix notation:

3 a b + c + d + e - *

.............................................................................................................................................. [2]
4 The following syntax diagrams for a particular programming language show the syntax of:

a. a digit
b. a capital letter
c. a character.

digit capital letter


0 A

1 E

2 I

3 O

4 U

5 character
$

6
%

7
&

8
*

9
#

(a) Write the Backus-Naur Form (BNF) notation of the syntax diagram for character.

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]
(b) A password must begin with a character and be followed by one or more digits or capital
letters.

(i) State an example of a valid password.

..................................................................................................................................... [1]

(ii) A valid password is represented by the syntax diagram:

character digit

capital letter

Write the BNF notation of the syntax diagram for password.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [5]
11

5 (a) The diagram shown represents an artificial neural network.

Output
Layer
Input
Layer
Hidden Hidden
Layer 1 Hidden Layer 3
Layer 2

(i) State the reason for having multiple hidden layers in an artificial neural network.

...........................................................................................................................................

..................................................................................................................................... [1]

(ii) Explain how artificial neural networks enable machine learning.

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

...........................................................................................................................................

..................................................................................................................................... [4]
(b) Find the shortest path between the Home and School nodes using the A* algorithm.
Show your working in the table provided.

The first two rows in the table have been completed.

14

h = 10 Home 9
g=1 4
A 5 C
3
7
B 6
2
6
D 6
3
7
F
1
2
3
E
3 5
School

Node Cost from Home node (g) Heuristic (h) Total (f = g + h)

Home 0 14 14

A 1 10 11

Final path
[5]
6 (a) State three essential features of recursion.

1 ................................................................................................................................................

...................................................................................................................................................

2 ................................................................................................................................................

...................................................................................................................................................

3 ................................................................................................................................................

...................................................................................................................................................
[3]

(b) Explain the reasons why a stack is a suitable Abstract Data Type (ADT) to implement
recursion.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

............................................................................................................................................. [3]

(c) Identify two ADTs other than a stack.

1 ................................................................................................................................................

2 ................................................................................................................................................
[2]
(d) The function StackFull() checks whether a stack is full.

The function uses the variable TopOfStack to represent the pointer to the most recent
position used on the stack, and the variable Max to represent the maximum size of the stack.
Assume TopOfStack and Max are global variables.

FUNCTION StackFull() RETURNS BOOLEAN


IF TopOfStack = Max THEN
RETURN TRUE
ELSE
RETURN FALSE
ENDIF
ENDFUNCTION

An algorithm AddInteger is required to add a new integer data element to a stack.

The stack is implemented as an array ArrayStack.

The function AddInteger() calls StackFull() and returns an appropriate message.

Complete the pseudocode for the function AddInteger().

FUNCTION AddInteger(NewInteger : INTEGER) RETURNS STRING

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

ENDFUNCTION
[5]
(c) The reverse Polish expression RPNString consists of a sequence of characters. Each
character is either:

• a single character identifier or digit


• an operator

The following algorithm inputs RPNString and output the corresponding infix expression
InfixString.

The algorithm uses a stack data structure, Stack.

INPUT RPNString

WHILE characters in RPNString

ThisChar  next character

IF ThisChar is an identifier or digit

THEN

Push ThisChar to Stack

ELSE // next character is an operator

Pop item from Stack and store as Temp

InfixString  Temp

// the & operator concatenates two strings

InfixString  ThisChar & InfixString

Pop item from Stack and store as Temp

InfixString  Temp & InfixString

Place brackets around InfixString

Push InfixString to Stack

ENDIF

ENDWHILE
Complete the trace table for the input of the reverse Polish expression:

x y +

The first two iterations of the WHILE loop have been done for you.

RPNString ThisChar Stack contents Temp InfixString

x y + x
x

y y
x

[8]

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy