Search:

Type: Posts; User: drdre

Search: Search took 0.18 seconds.

  1. Replies
    17
    Views
    1,821

    Re: Java dictionary search algorithm

    if length is equal and less than ill change code to: if (s.length()<=t.length())
    so if they're ever equal and less than n output will be false as:
    //return false if first i characters match
    ...
  2. Replies
    17
    Views
    1,821

    Re: Java dictionary search algorithm

    code for find the shorter string:


    if (s.length()<n || t.length()<n){
    if (s.length()<t.length()){
    n=s.length();
    }else if(t.length()<s.length()){
    ...
  3. Replies
    17
    Views
    1,821

    Re: Java dictionary search algorithm

    Okay for the 4th Bulletpoint:
    lessThan("bin", "binary", 4) is true but my console outputs false.

    Lets say s="bin" and t="binary", we need to find the shortest length out of these two, S is the...
  4. Replies
    17
    Views
    1,821

    Re: Java dictionary search algorithm

    I know the problem with my code as for these:

    My console prints:
    lessThan("bin", "binary", 4) = false (which should be true)
    lessThan("bit", "bitary", 4) = false (which should be true)

    when...
  5. Replies
    17
    Views
    1,821

    Re: Java dictionary search algorithm

    Okay all the bullet points now work EXCEPT the 4th one:

    lessThan("bin", "binary", 4) gives false in my console which should be true as bin comes before binary
    and if I flip both strings to this:...
  6. Replies
    17
    Views
    1,821

    Re: Java dictionary search algorithm

    Does this solve the problem for this:


    public boolean lessThan(String s, String t, int n) {

    boolean lessThan = false;

    if (s.length()<n || t.length()<n){
    if...
  7. Replies
    17
    Views
    1,821

    Re: Java dictionary search algorithm

    Here my updated code:

    public boolean lessThan(String s, String t, int n) {

    boolean lessThan = false;

    if (s.length()<n){
    n = s.length();
    }
    for...
  8. Replies
    17
    Views
    1,821

    Re: Java dictionary search algorithm

    okay lets start with ("binary", "bind", 4) for n=4 if s.charAt(i) comes before t.charAt(i) it should return true if not then return false. but I'm not sure how to implement this.
    would it be...
  9. Replies
    17
    Views
    1,821

    Java dictionary search algorithm

    You should not use any other String methods apart from length() and charAt(), or the Java binarySearch method.

    boolean lessThan(String s, String t, int n)
    This method should return true if the...
Results 1 to 9 of 9