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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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