M180: Data Structure and Algorithms in Java Tutor-Marked - TopicsExpress



          

M180: Data Structure and Algorithms in Java Tutor-Marked Assignment (Spring 2013/2014) Cut-Off Date: May3rd, 2014 Total Marks: 40 Contents Warnings and Declaration…………………………………………………………………………..……..1 Question 1 (7 marks)…..……………………….………………………………………………………….2 Question 2 (7 marks)……..…………………………………………………………………………….….2 Question 3 (7 marks)………..………………………………………………………………………….….2 Question 4 (7 marks)…………..……………………………………………………………………….….3 Question 5 (7 marks)…………..……………………………………………………………………….….4 Question 6 (5 marks)…………..……………………………………………………………………….….4 Plagiarism Warning: As per AOU rules and regulations, all students are required to submit their own TMA work and avoid plagiarism. The AOU has implemented sophisticated techniques for plagiarism detection. You must provide all references in case you use and quote another persons work in your TMA. You will be penalized for any act of plagiarism as per the AOUs rules and regulations. Declaration of No Plagiarism by Student (to be signed and submitted by student with TMA work): I hereby declare that this submitted TMA work is a result of my own efforts and I have not plagiarized any other persons work. I have provided all references of information that I have used and quoted in my TMA work. Name of Student:……………………………….. Signature:…………………………………………... Date:…………………………………………………… Question 1: (7 marks) Write the Java code of the method Transpose2D that takes one 2-dimentional array (matrix) A and returns one 2-dimentional array B that is transpose of matrix A. (assume that all the rows are of the same length) For example, if A is as follows: 2 5 8 3 6 4 2 9 3 1 8 0 9 5 2 2 4 8 5 2 0 8 9 9 3 3 5 6 1 2 Question 2: (7 marks) Write a Java code of the method startsWithCount that takes an array of strings words and a String S. The method should return an integer that is the number of strings that starts with S. For example if: words = { All, Arab, size, Almond, Allowed, here} and S= All, then the method should return 2 Question 3: (7 marks) You are given a listNode class and a list class: public class listNode { int data; listNode next; listNode(int d, listNode n){ data = d; next = n; } } public class list { listNode first; } Write a Java function Sum2List that takes two lists L1 and L2 of the same size and returns list L that contains the sum of data inside the corresponding nodes of lists L1 and L2. For example: Question 4: (7 marks) Given a Node P in a list of nodes (linked list), as shown in the figure below. Draw the results of the following statements, applied in the same order below, be sure to show the position of P in each step: (a) P.next = new Node(‘A’, P.next); (b) P = P.next.next; (c) P.next =P.next.next; (d) P.next = null; Question 5: (7 marks) Write a recursive Java method countDigitx that takes two integer numbers as input (a number n and digit x) and returns the number of times digits x occurs in number n: For example if n=23242 and x=2 then the method should return 3 that is the number of times the number 2 found in n. Question 6: (5 marks) Consider the following recursive method that calculates the greatest common divisor using Euclidean method. public static int GCD ( int x , int y ) { if ( y == 0 ) return x; else if ( x >= y && y > 0) return GCD ( y , x % y ); else return GCD ( y , x ); } Trace the above method for x=32 and y=46 ______________________________________________________________________________ End Of Assessment
Posted on: Fri, 14 Mar 2014 02:55:34 +0000

Trending Topics



Recently Viewed Topics




© 2015