Design RECURSIVE algorithm to find greatest common divisor

Assignment Help JAVA Programming
Reference no: EM132245752

Question 1 - The greatest common divisor (gcd) of two positive integers is the largest integer that divides evenly into both of them.

Design a RECURSIVE algorithm to find the greatest common divisor of two positive integers p and q, using the property:

  • If p > q, the gcd of p and q is the same as the gcd of q and p%q.

(Your solution must be recursive. Zero points will be given for solutions that do not use recursion.)

public static int gcd(int p, int q){

//...fill in this method...

}

Question 2 - Given a linked list comprised of nodes defined as below, and a pointer to the first node in the linked list (top), write a method (modifyList) to modify the given list in the following way. If the data in a given node is a positive number, insert data-1 copies of that node after the given node. If the data in a given node is zero or a negative number, remove that node from the list.

For example, if the initial list is

1 4 0 -3 2 -1

then the modified list would be

1 4 4 4 4 2 2

class Node {

public int data;

public Node next;

public Node(int d, Node n) {

data = d;

next = n;

}

}

void modifyList(Node top){

//...fill in this method...

}

Question 3 - Given an unordered array of integers that may contain duplicates, fill in the following method to remove duplicates, so that there is at most one element with any value.

Leave the first occurrence of an integer in the original order, and delete any later occurrences.

For example, given the array

2 8 4 8 9 4 8 5 4

the method would produce

2 8 4 9 5

public static void removeDuplicates(int[] x, int n){

//x is the array to be modified, n is the number of elements in the array

}

Reference no: EM132245752

Questions Cloud

Assessment options for measuring performance : Write the letter corresponding to each of the following assessment options for measuring performance before the situation describing it.
What effect will ESI have on an organization need : What likely effect will its emphasis on electronically stored information (ESI) have on an organization's need for a digital forensic capability?
Write the letter corresponding to the accuracy criterion : Write the letter corresponding to the accuracy criterion for a measure that is NOT met in the situation.
Conditions the productivity enhanced but outputs decreased : Under what conditions the productivity enhanced but outputs decreased?
Design RECURSIVE algorithm to find greatest common divisor : Design a RECURSIVE algorithm to find the greatest common divisor of two positive integers p and q, using the property
Discussion on sdlc method of system development : One alternative to the SDLC method of system development is the Joint Application Development method (JAD). The JAD uses a combination of developers.
Review given post related to the waterfall model : Based on my search of an SDLC alternative; the one that captured my attention is the Waterfall model. The waterfall process originated during the 1960s.
Job training and practices : Describe at least ten techniques and best practices used in employee training?
Discussion on the scrum development methodology : My company currently uses the Scrum Development Methodology. This methodology uses a time line called a sprint where development of software is done.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Ask user to enter a list of names

Write a program that ask a user to enter a list of names. When you finish, The program will show the total number of characters in all the names.

  Design java program to enter name in input dialog box

Design the program called MailingLabel.java Program must ask user to enter name and address in input dialog box with each component of address seperated by comma.

  Use data structures and algorithm to implement search engine

For the URLs in the keyword list, sort them by either the number of times the keyword appearing in the pages or the popularity of the pages.

  Declare a linkedlist that stores strings

Include a text file showing the output from at least 3 future value calculations

  Why the program only print the last book 4x

why the program only print the last book 4X - Problem with line 08 - Problem with line 27

  Assignmentwrite a gui-based application that allows a user

assignmentwrite a gui-based application that allows a user to play a simple trivia game. the game should have 5

  Demonstrate the class in a program that contains a car

Demonstrate the class in a program that contains a Car object, and then calls the accelerate method five times. After each call to the accelerate method

  Design and develop a class to capture information

Design and develop a class to capture this information. Then a program to follow to find the average marks scored by students in a given discipline across

  Create a version of the dice game pig that a user can play

Create a version of the dice game Pig that a user can play against the computer. The object of the game is to be the first to score 100 points.

  Find the errors in the javascript code

I get this error when running the Java Script above: JS Error: TypeError: Object # has no method 'error'

  What is an example of a javascript framework

What is an example of a JavaScript(r) framework? In the framework you have described, what is an example of an application that would work well on the site you are building for the class? What is the purpose of the application and how will it enha..

  Write a syntactically correct java program

Give an example from your daily life of some things that could be represented as an Array and how it could be used. Write a syntactically correct Java program to present your example: declarations, initializations and use

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd