



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Semester 2 Examinations 2010
Module Code: COMP 6012
School: Science and Computing
Programme Title: Bachelor of Science in Computing Bachelor of Science in Computing ACCS Bachelor of Science (Honours) in Software Development
Programme Code: KCOMP_7_Y2, KCOME_6_Y2 and KSDEV_8_Y
External Examiner(s): Mr. Peter Given Internal Examiner(s): Mr. Gerard MacSweeney and Ms. Gemma MacSweeney
Instructions: Answer Question 1 and TWO questions from Questions 2, 3 and 4.
Duration: 2 Hours
Sitting: Summer 2010
Requirements for this examination:
Note to Candidates: Please check the Programme Title and the Module Title to ensure that you have received the correct examination. If in doubt please contact an Invigilator.
(i) Set up a node to hold a fix length flight record of information and a link pointer. The flight information should include a flight id, departure airport, destination airport and the number of seats sold. Define the total number of seats as a constant. 5 marks
(ii) Write the details in the main program to update the last flight record. The last node in the flight list is referenced by the pointer last.
6 marks
(iii) Write code for in the main program to set up a new record. Automate the flight Id for each record. Note no seats are sold as yet. 4 marks
(iv) Write a function addFlight to add a new flight record to the end of a linked list. 6 marks
(v) Referring to (iv)
a. Explain what happens when a new node is created.
b. Explain how a record is added to the flight node. c. What value does the link of the node have and why?
d. If a node is added to an empty list, i. What would the starting head be?
ii. What happens to head after a call to the function addFlight? e. Write the code required to add a node after the first node.
9 marks
(vi) Write the code to empty a list of flights into a file called flights.dat 10 marks
Question 1 Î 40 marks
(i) With reference to binary trees, explain the terms node, child and leaf. 3 marks
(ii) Set up a node struct to hold the following data about bank customers: customerId, current balance, overdraft limit, left pointer and right pointer. 3 marks
(iii) Create an empty binary tree including allocation of memory. 2 marks
(iv) Write a function for attaching the node given in (ii) to the binary tree in (iii). 5 marks
(v) Write a function to create a binary tree using the function in (iv) to attach a number of nodes. The data can be read from the keyboard or from a file. 4 marks
(vi) Write a function to display the tree in any order. 3 marks
(vii) Define what is meant by:
Post-order traversal Pre-order traversal 4 marks
(viii) Write a recursive function which returns the factorial of an integer. The factorial of an integer is defined as n! = n(n -1)(n-2) …1. For example 4! = 4 x 3 x 2 x 1. 6 marks
Question 3 Î 30 marks
(i) Describe, in your own words, how the selection sort algorithm works. 4 marks
(ii) An array of integers contains five elements as follows: {63, 75, 90, 12, 27}. Trace the changing positions of the elements as the selection sort is implemented. 6 marks
(iii) Consider the sorting function code in Appendix 1. What is the name of this type of function? 2 marks
(iv) Trace how this function (in Appendix 1) might sort the following array {5, 28, 6, 9, 18, 21, 37, 17} 10 marks
(v) Write a function which implements a bubble sort to sort an array of integer elements. 8 marks
Total marks for Question 4 Î 30 marks