





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!






Autumn Examinations 2011/
Module Code: COMP
School: Science & Informatics
Programme Title: Higher Certificate in Computing – Year 2 BSc in Computing – Year 2 BSc (Hons) in Software Development – Year 2
Programme Code: KCOME_6_Y KCOMP_7_Y KSDEV_8_Y
External Examiner(s): Mr Peter Given Internal Examiner(s): Mr Gerard McSweeney Mrs Gemma McSweeney
Instructions: Answer Question 1 and 2 other questions.
Duration: 2 hours
Sitting: Autumn 2012
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.
Question 1 (mandatory question)
Section A (i) Compare and contrast the types of memory allocation used for Linked Lists as distinct from dynamic arrays. 2 marks (ii) Explain 2 steps that happen when ptr = new node 2 marks (iii) Link lists use non- contiguous memory- explain what happens using a memory diagram to display a link list that holds 2 nodes of information 4 marks (iv) What must be included in a link list to show where it starts and where it finishes. 2 marks (v) How do you code (a) An empty list (b) The end of a list that has last pointer to the last node 2 marks Section A 12 marks
Section B Consider the code in Appendix 1
Explain the code createNode to add a node to the end of a list Explain the code createList when a flight record is added to the end of a list Explain the code to empty a link list of its contents Section B 28 marks
Total marks Question 1 40 marks
Section A: Binary Trees
(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 clients of a flight system: flightId, full name, telephone, address , 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 should be read in from a file. 4 marks
(vi) Write a function to display the tree in any order. 3 marks
Section A ==> 20 marks
Section B : Binary Search i. Linear Searching or Binary Searching require a certain task to be carried out before searching must commence. What is it? 2 marks
ii. Given the code in Appendix 2 , show line by line what happens to find:
(a) A flight record present in an array of flights, where the flightID is the key – assume there is at least 8 flights present. note: the flight Ids are not automated 4 marks
(b) a flight record that is not present in an array of flights 4 marks
Section B ==> 10 marks
Question 3 30 marks
Section A (i) Explain what is recursion 1 mark (ii) Write a recursive function to find the factorial of a number 3 marks (iii) What is the purpose of an anchor statement 2 marks (iv) What is the anchor statement in factorial. 2 marks (v) Show the steps involved when using the function to calculate 4!. 4 marks (vi) What is a stack and how does it operate - show how a stack is involved in the process of recursive functions 4 marks
Section A 16 marks
Section B
(i) Show the steps that would have to be carried to sort the following data using the selection sort function in Appendix 3. You are required to show what is required for two passes through the code to sort the following: 98, 7, 32, 12, 2, 16 12 marks
(ii) Describe in English how this sorting function works. 2 marks
Section B 14 marks
Question 4 30 marks
node createList(node head) { C CDnode; node * next; cout << "Enter song (! to exit)" << endl; cin >> CDnode.song; while (song != "!"){ cout << "Enter artist"<> CDnode.artist; if (head == NULL) { head = createNode(head,CDnode); next = head; } else { next->link = createNode(next - >link, CDnode); next = next->link; } cout << "Enter song (! to exit" << endl; cin >> song; } return head; }
node * EmptyTheList(node * head) { node * current, * temp; current = head; //set to first node
while( current != NULL )//empty the linked list { //assign temp to the address of the next node temp = current-> link;
//free present node delete current;
//point current at the next node current = temp; } head = NULL; return head; }
Appendix 2 : Code for Binary Search
int binarySearch(int array[], int intNum, int left, int right) {
int mid; if (right < left) return -1; mid = (left+right)/2; if (intNum > array[mid]) return binarySearch(array,intNum,mid+1,right); else if (intNum < array[mid]) return binarySearch(array,intNum,left,mid-1); else return mid; }