Hirschberg algorithm

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abz89
    New Member
    • Mar 2010
    • 21

    Hirschberg algorithm

    somebody have a tried/implemented Hirschberg Algorithm to c#?
    i need it :(

    to make the program compare the two string and tell where the array index that the different,

    thx u
  • Christian Binder
    Recognized Expert New Member
    • Jan 2008
    • 218

    #2
    Originally posted by abz89
    somebody have a tried/implemented Hirschberg Algorithm to c#?
    i need it :(

    to make the program compare the two string and tell where the array index that the different,

    thx u
    Google brought me to this pages:


    Comment

    • jkmyoung
      Recognized Expert Top Contributor
      • Mar 2006
      • 2057

      #3
      To be honest, based on your earlier posts I would try to understand recursion and tree searches first.


      1. One way to look at it: The algorithm is like a tree search except that many of the branches are shared.

      2. The algorthim provided is also like filling in a grid, and then finding the best path to the goal.

      Figure out how to fill a single cell.
      Then figure out how to fill the cell next to it.
      Then do that over and over in for loops.

      Comment

      • abz89
        New Member
        • Mar 2010
        • 21

        #4
        @ChBinder
        it can't be downloaded >.<

        @jkmyoung
        oh dear i've create the programs with needleman-wutsch but it takes so much memory :(

        and i've found the hirschberg algo. but i didn't understand the algo :(

        Comment

        • Christian Binder
          Recognized Expert New Member
          • Jan 2008
          • 218

          #5
          Originally posted by abz89
          @ChBinder
          it can't be downloaded >.<

          @jkmyoung
          oh dear i've create the programs with needleman-wutsch but it takes so much memory :(

          and i've found the hirschberg algo. but i didn't understand the algo :(
          It can be downloaded!
          You've to choose "Source Code"-Menu, not "Download" then click on "3546"-Link and there you'll find the files and a complete download :-)

          Comment

          • abz89
            New Member
            • Mar 2010
            • 21

            #6
            owh yes.. :D
            but the source cannot be tested (run) :(

            i'm using vc# 2008 express,, hwa

            Comment

            • Christian Binder
              Recognized Expert New Member
              • Jan 2008
              • 218

              #7
              What happens when you want to run it? Any messages?
              Does even compiling doesn't work?

              The program expects to be started with command-line-parameters and any file given. I didn't try this program, I just looked a bit through the There are some test-methods inside it which you can maybe use.

              Comment

              • jkmyoung
                Recognized Expert Top Contributor
                • Mar 2006
                • 2057

                #8
                You can simplify the space requirements by only storing 2 columns at a time.
                Calculate the last column, starting from the bottom. ArrayA

                loop{
                based on ArrayA calculate the column before, starting from the bottom. ArrayB.
                Set ArrayA = ArrayB.
                }

                Comment

                • abz89
                  New Member
                  • Mar 2010
                  • 21

                  #9
                  @chbinder
                  yupz, it said some missing object etc...bla bla bla

                  @jkmyoung
                  i couldn't understand what you mean, (cause i'm so dumb --_--)

                  after i've googling, i found the more nice and faster algorithm,
                  "lazy DPA"

                  i think,
                  - needleman or other standard dpa is taking memory and times too much
                  - hirchberg is fine, but it ate so much time, cause it does double checking

                  i've been ported the hirchberg to c#, but it cannot processing arrays too long (in my case up to 16k), it said boundary issue or not enough memory resources :(

                  so i prefer to "lazy dpa",

                  have somebody tried on c sharp? some source tell that c sharp is slowest when benchmarked with the other languages, such as python, perl, even c++..

                  i wanna porting the applet (lazy dpa) like this site.


                  any help or suggest is so appreciated :)

                  Comment

                  • jkmyoung
                    Recognized Expert Top Contributor
                    • Mar 2006
                    • 2057

                    #10
                    Regarding space:
                    Notice how the demo only calculates one row at a time?
                    Each row is only dependent on itself and the row above.
                    Eg, once you've calculated row 4, you can throw away the results from row 3. You don't need row 3 to get the results for row 5.

                    A lazy Hirschberg algorithm is the same except it goes backwards, from the bottom to the top, then right to left.

                    Comment

                    • abz89
                      New Member
                      • Mar 2010
                      • 21

                      #11
                      @jkmyoung

                      yupz, hirschberg is only calculated the single row and above ones then immedietly flushing the memory with throw the other unnecessary datas..
                      but it taking two times longer, cause the traceback check will missed the data (which trown before)

                      sorry that i mistaked, i've been ported the needleman into c sharp..
                      but it takes error when i use it cause my array data is 16thousand char long,

                      it said array outbound of index and sometime memory resources issue.

                      so i need the optimization on needleman, maybe add a pause time?? how can i do that?

                      if the optimization on needleman not succesed, i'll try hirschberg :)

                      thx a lot

                      Comment

                      • jkmyoung
                        Recognized Expert Top Contributor
                        • Mar 2006
                        • 2057

                        #12
                        If you're getting an out of bounds errors, there's probably a small mistake in how you've implemented it. It's hard to tell without seeing the relevant code.

                        Make sure you're aligning the two strings so that you only need to store only as many cells equal to the shortest string's length..

                        Comment

                        • abz89
                          New Member
                          • Mar 2010
                          • 21

                          #13
                          hmm, here is my codes..

                          hope u could notify me the error :D
                          thx a lot

                          Comment

                          • jkmyoung
                            Recognized Expert Top Contributor
                            • Mar 2006
                            • 2057

                            #14
                            1. Optimization: convertStringTo Arr
                            You create a list, and then you copy the list into a int[] array. Why not create the int[] array to begin with?

                            l.Count equals str.Length
                            ====
                            2. Error
                            for(int y=0;y<source.Le ngth;y++)
                            for(int x=0;x<dest.Leng th;x++)

                            These should both be <=
                            =====
                            3. Optimization.
                            You call NeedlemanWunsch .convertStringT oArr(s1) twice for each string. Call it once each string, and store the variable.

                            Comment

                            • abz89
                              New Member
                              • Mar 2010
                              • 21

                              #15
                              <quote>
                              1. Optimization: convertStringTo Arr
                              You create a list, and then you copy the list into a int[] array. Why not create the int[] array to begin with?
                              </quote>

                              hmm, i will make the GUI for this program with string1 and string2 input fron text box, so i designed it is like this...

                              <quote>2. Error
                              for(int y=0;y<source.Le ngth;y++)
                              for(int x=0;x<dest.Leng th;x++)

                              These should both be <=
                              <quote>

                              did you mean:

                              for(int y=0;y<=source.L ength;y++)
                              for(int x=0;x<=dest.Len gth;x++)

                              ok..


                              hi bos, could you fix my codes directly :)
                              so i can make sure that codes is more efficient and i can learn it

                              i'm so appreciated with your help :D
                              thx a lot

                              Comment

                              Working...