Question Details

(solution) a) Determine the step count of each line in this method (fill in


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 x[i] += 2; ???

int i = 1; ???

while (i { 0

x[i] += x[i+1]; ???

i++; ???

} 0

} ???

Total


M180: Data Structure and Algorithms in Java Tutor-Marked Assignment (Fall 2015/2016)

 

Arab Open University 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:???????????????????? 1 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

 

abcd- What will be the elements of arr1 after executing the code?

 

What will be the elements of arr2 after executing the code?

 

Draw the stack s after executing the code.

 

Draw the queue myQueue after executing the code, indicating Front and Rear.

 

2 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[0] myList 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; 3 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

 

}

 

??? T Total 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

 

4

 


Solution details:
STATUS
Answered
QUALITY
Approved
ANSWER RATING

This question was answered on: Jan 30, 2021

PRICE: $15

Solution~0001016977.zip (25.37 KB)

Buy this answer for only: $15

This attachment is locked

We have a ready expert answer for this paper which you can use for in-depth understanding, research editing or paraphrasing. You can buy it or order for a fresh, original and plagiarism-free solution (Deadline assured. Flexible pricing. TurnItIn Report provided)

Pay using PayPal (No PayPal account Required) or your credit card . All your purchases are securely protected by .
SiteLock

About this Question

STATUS

Answered

QUALITY

Approved

DATE ANSWERED

Jan 30, 2021

EXPERT

Tutor

ANSWER RATING

GET INSTANT HELP/h4>

We have top-notch tutors who can do your essay/homework for you at a reasonable cost and then you can simply use that essay as a template to build your own arguments.

You can also use these solutions:

  • As a reference for in-depth understanding of the subject.
  • As a source of ideas / reasoning for your own research (if properly referenced)
  • For editing and paraphrasing (check your institution's definition of plagiarism and recommended paraphrase).
This we believe is a better way of understanding a problem and makes use of the efficiency of time of the student.

NEW ASSIGNMENT HELP?

Order New Solution. Quick Turnaround

Click on the button below in order to Order for a New, Original and High-Quality Essay Solutions. New orders are original solutions and precise to your writing instruction requirements. Place a New Order using the button below.

WE GUARANTEE, THAT YOUR PAPER WILL BE WRITTEN FROM SCRATCH AND WITHIN A DEADLINE.

Order Now