Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: URGENT HELP NEEDED WITH ALGORITHM PLEASE! PLEASE! .... THANKS

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default URGENT HELP NEEDED WITH ALGORITHM PLEASE! PLEASE! .... THANKS

    Consider the problem description below:
    John proposed an algorithm balancedBracketsByCounting(String s), as follows, that takes a string
    as an input and checks whether the brackets \[" and \]" in the string are matched correctly. He
    claimed that his algorithm is correct. For example, balancedBracketsByCounting("[x][[xy]]")
    would return true but balancedBracketsByCounting("[[x[y]]") would return false.

    This is John's algorithm:
    boolean balancedBracesByCounting(String s) {
    numOfLeftBracketRound = 0; numOfRightBracketRound = 0
    numOfLeftBracketSquare = 0; numOfRightBracketSquare = 0
    balanced = true
    while (not at the end of the s) {
    if (the next character is an open bracket '(' {
    numOfLeftBracketRound++
    }
    else if (the next character is an open bracket '[') {
    numOfLeftBracketSquare++
    else if (the next character is a close bracket ')' {
    numOfRightBracketRound- -
    } else if (the next character is a close bracket ']') {
    numOfRightBracketSquare- -
    }
    }
    return {(noOfLeftBracketRound==noOfRightBracketRound)
    and (noOfLeftBracketSquare==noOfRightBracketSquare)}
    }
    Study carefully John's algorithm and
    1. Explain why the algorithm balancedBracketsByCounting(String s) is
    awed.
    2. Demonstrate one
    awed case in which, with the aid of an example of input, the algorithm may
    return a true for a wrong match.
    3. Identify as many errors or weaknesses as possible in John's algorithm, and correct or improve
    them. Summarise your results in a table
    4. Derive an alternative algorithm that would return correct answers. Show all your work.
    5. Implement your algorithm, referring to the submission requirements.
    Last edited by helloworld922; March 11th, 2011 at 01:28 AM.


  2. #2
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,225
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: URGENT HELP NEEDED WITH ALGORITHM PLEASE! PLEASE! .... THANKS

    And what exactly is the problem and/or question? I hope you aren't relying on us to answer the bottom 5 points for you, as this is your job. If you have a specific question about the work, by all means ask and we can try to help

  3. #3
    Junior Member
    Join Date
    Mar 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: URGENT HELP NEEDED WITH ALGORITHM PLEASE! PLEASE! .... THANKS

    No, i am not. I am new to java and this algorithm thing. I just need someone to answer the first and second questions for me with some details why the algorithm is flawed. i need to understand what is wrong with it. Rightnow i don't understand it.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,156
    My Mood
    Hungover
    Thanks
    141
    Thanked 595 Times in 510 Posts

    Default Re: URGENT HELP NEEDED WITH ALGORITHM PLEASE! PLEASE! .... THANKS

    You've pretty much just described your homework assignment. That's not how this works. What do you think is the answer? What have you done to try to figure it out? Have you tried running the code and trying it yourself?

    Also, posts with titles like yours tend to be ignored. Everybody here needs help. Yelling "please" won't help you- in fact, it will hurt your chances of getting help.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member
    Join Date
    Mar 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: URGENT HELP NEEDED WITH ALGORITHM PLEASE! PLEASE! .... THANKS

    Thanks. I got it done already.

  6. #6
    Junior Member
    Join Date
    Mar 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: URGENT HELP NEEDED WITH ALGORITHM PLEASE! PLEASE! .... THANKS

    Hi, I'm doing the same assignment and is getting the same problem with understanding it especially with question 2 as I am not sure what is needed here. Any pointers on this? It'll be much appreciated. Thanks!

  7. #7
    Junior Member
    Join Date
    Mar 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: URGENT HELP NEEDED WITH ALGORITHM PLEASE! PLEASE! .... THANKS

    Quote Originally Posted by copeg View Post
    And what exactly is the problem and/or question? I hope you aren't relying on us to answer the bottom 5 points for you, as this is your job. If you have a specific question about the work, by all means ask and we can try to help
    Hi I have the same assignment as well and I'm getting a problem with question 2, any help/pointers on this will be much appreciated, thanks!

Similar Threads

  1. urgent help needed
    By nono in forum Member Introductions
    Replies: 2
    Last Post: March 10th, 2011, 10:18 AM
  2. Urgent help needed
    By mohit1007 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: June 23rd, 2010, 09:34 PM
  3. Urgent Help needed with java codes
    By makarov in forum Java Theory & Questions
    Replies: 0
    Last Post: November 13th, 2009, 06:23 AM
  4. Urgent code needed
    By subhvi in forum AWT / Java Swing
    Replies: 4
    Last Post: August 27th, 2009, 12:55 AM