Route Information Table - Applied Data Structure - Past Exam, Exams of Data Structures and Algorithms

Main points of this exam paper are: Memory Allocation, Linked Lists, Distinct, Dynamic Arrays, Contrast, Departure, Destination, Aeroplane Seating, Price Per Adult, Empty List

Typology: Exams

2012/2013

Uploaded on 03/24/2013

bakula
bakula 🇮🇳

4.4

(5)

35 documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Page 1
CORK INSTITUTE OF TECHNOLOGY
INSTITIÚID TEICNEOLAÍOCHTA CHORCAÍ
Semester 2 Examinations 2008/09
Module Title: Applied Data Structures
Module Code: COMP6012
School: Computing
Programme Title: Bachelor of Science in Computing – Year 2
Bachelor of Science (Honours) in Software Development –
Year 2
Programme Code: KCOMP_7_Y2
KSDEV_8_Y2
KCOME_6_Y2
External Examiner(s): Ms. M. Meagher
Internal Examiner(s): Ms. G. McSweeney
Instructions: Answer Question 1 and TWO other questions
Duration: 2 Hours
Sitting: Summer 2009
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 paper.
If in doubt please contact an Invigilator.
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Route Information Table - Applied Data Structure - Past Exam and more Exams Data Structures and Algorithms in PDF only on Docsity!

CORK INSTITUTE OF TECHNOLOGY

INSTITIÚID TEICNEOLAÍOCHTA CHORCAÍ

Semester 2 Examinations 2008/

Module Title: Applied Data Structures

Module Code: COMP

School: Computing

Programme Title: Bachelor of Science in Computing – Year 2 Bachelor of Science (Honours) in Software Development – Year 2

Programme Code: KCOMP_7_Y KSDEV_8_Y KCOME_6_Y

External Examiner(s): Ms. M. Meagher Internal Examiner(s): Ms. G. McSweeney

Instructions: Answer Question 1 and TWO other questions

Duration: 2 Hours

Sitting: Summer 2009

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 paper. If in doubt please contact an Invigilator.

Question 1 is compulsory

Question 1

Section A

Compare and contrast the types of memory allocation used for Linked Lists as distinct

from either static or dynamic arrays. 2 marks

Section A Î 2 marks

Section B

Data to be stored in a node of a linked list should include the following data on route information for flights 9 route id 9 departure 9 destination 9 Aeroplane Seating 9 Price per Adult

(i) Write the code to set up a node for a given route 2 marks

(ii) Describe how to represent the following in memory

(a) An empty list (b) A link list with 1 node 2 marks

(iii) Write a function to search for a position in a list according to the route id.

The function should determine if the node is present and return a pointer to the previous position to the node. It should return null if the node does not exist. 8 marks

(iv) Write the code for adding a route to a list in order of route id. 4 marks

Section B Î 16 marks

Question 2 Binary Trees

(i) Set up a root node struct as given in Q1 to hold the route id, the departure, the destination, adult pricing and aeroplane seating and 2 pointers left and right. 3 marks

(ii) Set up the memory for the node in (i) and set the left and right pointer to NULL. 2 marks

(iii) Write a function for attaching the node given in (i) to a binary tree based on the key route Id. 5 marks

(iv) Explain how to use recursion to add 37 to the tree in (vii) below. 4 marks

(v) Build up the expression given the following PostOrder traversal example. 3 marks

(vi) How does PostOrder traversal work for the above diagram? 3 marks

(vii) Given the following tree, demonstrate how to use recursion down to the lowest

level to display (PostOrder) the contents of the following tree. 5 marks

(vi) Explain how recursion is used to remove a node with one child. The function code to

remove a node is given in Appendix 3. 5 marks

Question 2 Î 30 marks

Root

Section C: Main Program: Use the functions written in Section B

(i) Set up Linear Queue 1 mark

(ii) Initialise a Linear Queue. 1 mark

(iii) While the queue is not empty, output the details of a stock item from the queue.

5 marks

Section C Î 7 marks

Question 3 Î 30 marks

Question 4 Sorting and Recursion

Section A

(i) Explain what is recursion 1 mark

(ii) Give an example of an anchor statement and explain its purpose.

2 marks

(iii) Write a recursive function to find the power of ( x n^ .) 3 marks

(iv) Show the steps involved when using the function to calculate 6^4.

Show how a stack is involved in the process. 9 marks

Section A Î 15 marks

Question 4 (contined)

Section B

Consider the following sort code.

void Sort( int x[], int n) { int smallPos, smallest; for( int i=0; i < n; i++) { smallPos = i; smallest = x[ smallPos ];

for(int j=i +1 ; j < n ; j++)

if ( x[j] < smallest) { smallPos = j; smallest = x [smallPos ]; }

x[ smallPos ] = x[i ]; x[i] = smallest; } }

(i) Show the steps that would have to be carried to sort the following data using the above function. You are required to show what is required for 2 passes through the code. 45, 12, 56, 78, 23 10 marks

(ii) Describe in English how this sorting function works. 2 marks

(iii) Name this sort and compare with the bubble sort. 3 marks

Section B Î 15 marks

Question 4 Î 30 marks

Appendix 2

int binarySearch(Cust * customersarray, int accno, int left, int right) {

int mid;

if (right < left) return -1;

mid = (left+right)/2;

if (accno > customersarray[mid].accno) return binarySearch(customersarray,accno,mid+1,right);

else if (accno < customersarray[mid].accno) return binarySearch(customersarray,accno,left,mid-1);

else return mid; }

Appendix 3 tree * remove_node( tree * parent, int num, int *success) { tree * temp; int new_num;

if( parent != NULL) { if ( num ==parent->num) { *success = 1; if (parent->left ==NULL && parent->right == NULL) { temp = parent; free(temp); parent = NULL; } else if (parent->left ==NULL) { temp = parent; parent = parent->right; free( temp); } else if (parent->right ==NULL) { temp = parent; parent = parent->left; free( temp); } else // find the left most node on the right side { parent-> right = successor(parent->right, &num); parent->num = num; } }// number not equal to parent_number

else if ( num < parent->num) parent->left = remove_node(parent->left, num, success); else parent->right = remove_node(parent->right, num, success); } else //parent ==null *success =0; return parent; }//end function