Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 22251

An algorithm is a sequence of well-defined steps that define an abstract solution to a problem. Use this tag when your issue is related to algorithm design.

2 votes

Checking if a number is a perfect square (without Math)

There are significant improvements that can be made by choosing a more optimal algorithm. Better algorithms for finding the root of x² - n = 0 are : Halving intervals to search for the root. …
bowmore's user avatar
  • 5,359
5 votes

Calculate different speeds between min and max speed with a stepsize

First off, you should capture this functionality in a dedicated method, rather than in the class' main method. Secondly, I'm not sure why you want an array of String. I don't know the context, but as …
bowmore's user avatar
  • 5,359
6 votes
Accepted

Algorithm that tells the user what current "status" they fall under based on their current t...

What you have done right: Seperate methods to check each case. Makes the main method easier to read. Make the dateTime to test against a parameter of the method. (easier to test) What can be impro …
bowmore's user avatar
  • 5,359
1 vote

Attempt at method to draw diamond (recursive or not ?)

The trick to getting this simple is expressing the start index of the stars and the number of stars as a mathematical function of the line they are on. Math.abs() is your friend for creating that turn …
bowmore's user avatar
  • 5,359
1 vote

A character array of arbitary length with 'R', 'B', 'W' is needed to be sorted in that order

I would simply suggest renaming of index variables to clarify their function adding a comment that clarifies the algorithm use a switch as it yield a clearer structure in this instance. …
bowmore's user avatar
  • 5,359
0 votes

Stack with 'getMinimum' operation

As others have noted, Stack extends Vector. As such Stack is a List. The easiest and most readable way to add getMinimum() would be to do this : import java.util.Collections; import java.util.Stack; …
bowmore's user avatar
  • 5,359
12 votes
Accepted

Collection of exact string matching algorithms in Java

For well documented algorithms it could be permissable if the published algorithm defines these variables. …
bowmore's user avatar
  • 5,359
7 votes

Program to check if strings are rotations of each other or not

The code can greatly be simplified by using a different algorithm. Note : two string are rotationally equal if the concatenation of one and itself contains the other. …
bowmore's user avatar
  • 5,359
4 votes
Accepted

Return the largest product of 2 numbers that is a multiple of 9 in O(n)

This algorithm results in \$O(n)\$ complexity. …
bowmore's user avatar
  • 5,359
5 votes

Check for balanced parentheses

I've only one addition to the other answers For the stack you use java.util.Stack, this seems like an obvious choice, yet it is a remnant from pre-collection times, and is a subclass of java.util.Vec …
bowmore's user avatar
  • 5,359
1 vote

Is there a better version for verbosing the output of the euclidean method?

Ironically, a property of Euclid's algorithm is that it automatically performs this switch by itself. … = 0) { r = a % b; a = b; b = r; } return a; } } Checking whether b is a divisor if a explicitly is also superfluous (again the algorithm handles …
bowmore's user avatar
  • 5,359
2 votes
Accepted

Mergesorting a stack in Java

Not too many things to remark. I'll review regarding this assumption : Stack is to be viewed as a Stack datastructure, only peek, pop, push, size and isEmpty are to be used. The fact that java.util.S …
bowmore's user avatar
  • 5,359
1 vote

Forming sets from pairs of numbers

standard naming conventions. seperate concerns : parsing the string into a pair should be done in a separate method, this will improve readability. it's unclear from just looking at your code what the algorithm … If that's insufficient, some documentation can also help. probably this is an exercise, as your algorithm simply prints its result, rather than return it. …
bowmore's user avatar
  • 5,359