WhatsApp-00963951432013 Admin
عدد المساهمات : 2429 نقاط : 302124 السٌّمعَة : 4 تاريخ التسجيل : 20/09/2008 العمر : 54 الموقع : www.aoua.123.st
| موضوع: 1 M180: Data Structure and Algorithms in Java Tutor-Marked Assignment (Fall 2015/2016) Cut-Off Date: Total Marks: 40 Contents Warnings and Declaration………………………………………………………………………………..1 Question 1……………..……………………….………………………………………………………….2 Que الأربعاء نوفمبر 11, 2015 3:24 am | |
| 1 M180: Data Structure and Algorithms in Java Tutor-Marked Assignment (Fall 2015/2016) Cut-Off Date: Total Marks: 40 Contents Warnings and Declaration………………………………………………………………………………..1 Question 1……………..……………………….………………………………………………………….2 Question 2 ………………..…………………………………………………………………………….….3 Question 3 ………….………..………………………………………………………………………….….4 Question 4 ………….…………..……………………………………………………………………….….4 Question 5 ………….…………..……………………………………………………………………….….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 person's work in your TMA. You will be penalized for any act of plagiarism as per the AOU's 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 person's work. I have provided all references of information that I have used and quoted in my TMA work. Name of Student:……………………………….. Signature:…………………………………………... Date:…………………………………………………… Arab Open University 2 Question 1: (10 marks) Given the following method: public void guessIt(Stack s, int[] arr1, int[] arr2){ Stack s1=new Stack(); Queue myQueue=new Queue(); int i=0, j=0; while(!s.isEmpty()){ int x=s.pop(); if(x%3==0) arr1[i++]=x; if(x%5==0) arr2[j++]=x; s1.push(x); } while(!s1.isEmpty()) myQueue.enqueue(s1.peek()); s.push(2*s1.pop()); } Consider that the arrays were initially empty, and the initial state of the stack was as follows: 15 30 12 11 9 20 0 2 s a- What will be the elements of arr1 after executing the code? b- What will be the elements of arr2 after executing the code? c- Draw the stack s after executing the code. d- Draw the queue myQueue after executing the code, indicating Front and Rear. 3 Question 2: (11 marks) You are given a Node class and a List class: public class Node { int data; Node next; } public class List { Node first; } Given an array myArray and a linked list myList depicted in the following diagrams. myArray A- Write a code that takes the array and the list as arguments, and fills the first five nodes in the list with the first five positive numbers in the array using a proper loop. B- Draw the List after applying the code. C- Draw the Final shape of the List after applying the code and the following statements as well: Node p=first.next.next.next; p.next.next.data= myArray[11]; p.next.next.next=first; myArray[0] myList 4 Question 3: (6 marks) : For the following method findBigO: a) Determine the step count of each line in this method (fill in the ??? places) b) Find the Total of the total steps (T) c) Deduce , at the end , the final time complexity (Big-O notation) . Statement Total Steps/ line public static void findBigO(int [] x, int n) ??? { 0 for (int i = 0; i < n; i += 2) ??? x[i] += 2; ??? int i = 1; ??? while (i <= n/2) ??? { 0 x[i] += x[i+1]; ??? i++; ??? } 0 } ??? Total T Question 4: (8 marks) Write a Java method that takes a Stack myStack as an argument. The method should empty the stack and fill its elements in a doubly linked list myList , and returns this list. N.B: Use header in your method. Question 5: (5 marks) Given the code below, that includes a recursive method: class recursion { public static int func (int n) { int result; result = func (n - 1); return result; } } class Output { public static void main(String args[]) { recursion obj = new recursion() ; System.out.print(obj.func(12)); } } a) Run the given code on your computer, and provide a screenshot to display the result. b) Why do you think the output was like that? End of Assessment | |
|