Docsity

Applied Data Structures Examination - Autumn 2011/12, Exams of Data Structures and Algorithms

Toggle sidebar
bg1
Page 1 of 9
CORK INSTITUTE OF TECHNOLOGY
INSTITIÚID TEICNEOLAÍOCHTA CHORCAÍ
Autumn Examinations 2011/12
Module Title: Applied Data Structures
Module Code: COMP6012
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_Y2
KCOMP_7_Y2
KSDEV_8_Y2
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.
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Applied Data Structures Examination - Autumn 2011/12 and more Exams Data Structures and Algorithms in PDF only on Docsity!

CORK INSTITUTE OF TECHNOLOGY

INSTITIÚID TEICNEOLAÍOCHTA CHORCAÍ

Autumn Examinations 2011/

Module Title: Applied Data Structures

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 140 marks

Question 3 Binary Trees & Searching

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 330 marks

Question 4 Sorting and Recursion

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 A16 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 B14 marks

Question 430 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; }