Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 1 1a) Discuss how Linked Lists use Dynamic Memory Allocation while Arra

ID: 662485 • Letter: Q

Question

Question 1

1a) Discuss how Linked Lists use Dynamic Memory Allocation while Arrays do not. [3 marks]

1b) Compare the memory efficiency of linked list with Multi-Dimensional Arrays for storing double precision numbers in a spreadsheet assuming there are 2000 rows and 2000 columns used in total. [4 marks]

1c) Data to be stored in a node of a linked list should include the following: student number student name student address telephone number Course

(i) Describe how to create an instance of such a Node? [3 marks]

(ii) Create a sketch diagram to display the following:

(a) an empty list

(b) a link list with 3 nodes of information. [4 marks]

(iii) Write the code to explain the process involved in printing everything in a list from the first piece of data to the last piece of data in the list. Use detailed comments throughout to explain each step of the code. [4 marks]

(iv) Write the code to search for the position of student in a linked list. This code will receive a student number and print out the position of this student in the linked list. If the student number is not found in the list then your code should print a message indication the student could not be found. [4 marks]

(v) Write the code to add a number of students to a list, one at time in order of student number( Note not main ) [4 marks]

(vi) Write the code and explain how to delete a node from a linked list given the previous address. [6 marks]

1d) Student ID Code Student Name Address Telephone Course 0000123456 Jane Smith Midleton, Co.Cork 021 463456 DNet2 0012987899 Ann O Brien Youghal, Co.Cork 024 98845 Com2 0012789456 Bobby Kelly Cobh, Co.Cork 021 4345678 DCom2 Application Class

(i) Write the code to set up an empty list and add a given number of Student records to the list [4 marks]

(ii) Print the contents of each of the nodes in the list [4 marks]

Question 2

2a) What is generic programming? [5 marks]

2b) Write a generic class called Pair that stores a pair of references of any type. The class should have two accessors getFirst and getSecond to access each of the references. [11 marks]

2c) Using an appropriate sorting algorithm write the code to sort an array of integers. [7 marks] 2d) Using code, explain how you would sort an ArrayList of Strings. [7 marks]

Question 3

3a) Explain the following terms: a binary tree [2 marks] root node [2 mark] a leaf node [2 mark]

3b) Create a tree from the following values 22, 3, 44, 22, 25, 56, 76, 2, 97, 33, 98, 100 [3 marks]

3c) Explain in detail what is happening in the following three methods of the tree class. Use the class created above. What is the output if you apply the three methods below to the tree in part 3c) above. [6 marks]

//Preorder Traversal public synchronized void preorderTraversal() { preorderHelper( root); } // root is a TreeNode //Recursive method to perform preorder traversal private void preorderHelper (TreeNode node) { if ( node == null ) return; System.out.print (node.data + " "); preorderHelper ( node.left ); preorderHelper ( node.right ); }[5 marks]

//Inorder Traversal public synchronized void inorderTraversal() { inorderHelper( root); } // Recursive method to perform inorder traversal private void inorderHelper (TreeNode node) { if ( node == null ) return; inorderHelper ( node.left ); System.out.print (node.data + " "); inorderHelper ( node.right ); } [5 marks]

//Postorder Traversal public synchronized void postorderTraversal() { postorderHelper( root); } // root is a TreeNode // Recursive method to perform postorder traversal private void postorderHelper (TreeNode node) { if ( node == null ) return; preorderHelper ( node.left ); preorderHelper ( node.right ); System.out.print (node.data + " "); } [5 marks]

Question 4

4a) Using examples explain in detail what recursion is. Include the 3 characteristics of recursion in your answer. [5 marks] 4b) Develop a recursive program to calculate the factorial of an integer. For example 7! equals 7*6*5*4*3*2*1 = 5040. Clearly identify your base case. [7 marks]

4c) What do we mean by the term

Explanation / Answer

Answer(1 a) Memory Should be allocated at Compile-Time in Stack . i.e at the time when Programmer is Writing Program

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote