Finding Longest Palindrome Given a File

Hello Everyone,
I am tackling an algorithmic problem trying to find the longest palindrome inside of a text file. As of right now, I know how to determine if a word is or is not a palindrome. However, the issue that I am having at the moment is trying to come up with an efficient algorithm that can solve this in the fastest way possible. Please help give ideas/suggestions on an algorithm that I should follow to achieve this.
So for example, lets say we have a text file that has 10,000 characters. One of the things that I have concluded is that in order to determine if a word is a palindrome, you must be able to know the first and last characters. Right now, the only thing that I can think of is to:
for( start with the first character x,  until the last character 10,0000)
          int Y = index 10,000
          while( X < Y )
                if(the substring from X to the last character Y is not a palindrome)
                Y = Y - 1;
                else
                         currentLongestPalindrome = substring from X to Y;
                         BREAK;
}Sorry everyone for the incorrect Java syntax, but that is the basic idea that I have come up with. This looks terrible as it is taking over an hour to be able to run this solution. Do you guys have any suggestions?
Thanks in advance.

Hi,
I don't think you got the point of my main suggestion.
Just check each three letter sequence until you find what may be the centre of a palindrome then and only then expand your check
For your example
"DSAFJKLSAFDJDASFLJASDFLASJFKSJHCNXVABCDDCBAMXBCXBZNZQOEIQEWOUWQOUWQEPQWUE"
DSA
SAF
AFJ
etc
e.g.
DSA = FALSE
SAF = FALSE
FDJ = FALSE
DJD = TRUE -> F*DJD*A = FALSE - Current longest = 3
JDA = FALSE
DAS = FALSE
CDD = POSSIBLE -> CDDC = TRUE -> BCDDCB = TRUE -> ABCDDCBA = TRUE -> VABCDDCBAM = FALSE - Current longest = 8
DDC = POSSIBLE (no need to check less than 8) -> ABC*DDC*BA = TRUE -> VABCDDCBAM = FALSE - Current longest still 8
DCB = FALSE
etc
That sequence consists of 40 checks of three letter sequences and only needs to expand on 3 of them.
So on a 10,000 char file you would perform a max of 9,998 initial checks and then only expand on those that require it.
In an amendment to my initial suggestion sequence 'aaa' could also be the centre of a palindrome.
Hope this is clearer
Eric

Similar Messages

  • I am trying to find out how to assign files with particular extensions to the appropriate software. At the moment when I create a file using Word it is apparently given the extension .docx but Word doesn't recognise its own files. How do I alocate th

    I am trying to find out how to assign files with particular extensions to the appropriate software. At the moment when I create a file using Word it is apparently given the extension .docx but Word doesn't recognise its own files. How do I allocate the extension .docx to Word? There used to be a way of doing it, I think under "Preferences" but I can't seem to find it.

    Still in the same location:
    File > Get Info > Open with (select) > Change All (button)

  • Web-Disk on OSX 10.9 Give me this error: "Finder got an error: Network file permission error."

    Previously I was using OSX 10.8 and Web Disk was working great.
    Since I upgraded to OSX 10.9 Web Disk Dont Attach to my compputer and give me this ERROR:
    FInder got an error: Network file permission error.
    When I got this ERROR first time I searched GOOGLE and found this link: http://cammodude.blogspot.no/
    And I did:
    To force all connections to be SMB1:
    Open A terminal window
    paste in the following line followed by the return key(should be all on one line): 
    echo "[default]" >> ~/Library/Preferences/nsmb.conf; echo "smb_neg=smb1_only" >> ~/Library/Preferences/nsmb.conf
    What the command does:
    Creates a file called nsmb.conf  in your  home directory at the path ~/Library/Preferences/nsmb.conf.
    Adds directives to force SMB connections to use the SMB1 protocol.  This is slower but stable.
    Then I could use Web Disk on OSX 10.9 after executing this command in Terminal.
    But now I restarted my Macbook and now Im NOT able to connect to Web Disk and get the same ERROR.
    FInder got an error: Network file permission error
    After trying 100 times it attaches 1 time but then show this ERROR:
    Can't get <<class cdis>> "my.server.com/2078" of application "Finder".
    If this happen then I can see the files in Finder and see the Contents and Size of files but if I open a PHP file in BBEdit then it shows BLANK.. But actually it is NOT blank.
    Now Im stuck How can I solve this? All help is highly appericated..
    Thank you so much...

    Hi,
    Make sure to chmod the app, something like this :
    chmod -Rf 777  secure_site_WebDisk.app
    (in my case the CPanel provided the app for my OSx version.)

  • Hi when i open my application folder, all the application is shown in trash folder. when i click the application it says this app is in trash first move it out. and when i try to open through finder go it says this file doesn't exist. can some1 plz help?

    hi when i open my application folder, all the application is shown in trash folder. when i click the application it says this app is in trash first move it out. and when i try to open through finder> go it says this file doesn't exist. can some1 plz help? how can i put all my application through application folder?

    Something really odd is going on. In your first screen shot, I noticed that the Applications folder does not have the proper icon displayed in the side bar. Also, in the title bar it lists it as Applications 08-59-29-909.
    Not sure where it's picking up that odd name, unless it's because it's still truly within the Trash folder.
    Try this. In the Finder > Preferences > General > turn on "Always open folders in a new window". (I have a feeling you have the default setting with this off).
    Now, in Finder > Go > move down and open the Applications Folder from there. Now open the folder where you see all your applications that you show in your screen shot, select all, and move them to this true appliactions folder.
    This is what you should properly seeing (but with different apps listed):
    See how the Applications folder has the icon of the letter A shaped with a pencil, ruler & pen.

  • Snow Leopard finder doesn't list all files on Windows 7 volumes

    From my Macbook Pro (10.6.8), I can connect to my Mac Pro, while it is running Windows 7 in Boot Camp, in order to access the Mac Pro's 6 volumes (1 Boot Camp, 5 Mac volumes). This is using SMB via Finder's 'Connect to server…' on an Airport network.
    However, Finder never displays all the files and folders on any of the Mac volumes it connects to through Windows 7. It seems to show approximately the first 18-9 files and folders, and then nothing. The same applies when I open a nested folder — it doesn't list all of its contents.
    Any ideas as to what's causing this and how I can fix it? I have searched all over but can't find any answers yet, so I'm hoping someone here has seen this before.

    Thanks for the reply, but I do have the Restore Windows box checked (see below). And the Resume features info (cnet link) only addresses how to turn the feature off, either selectively or globally. I'm simply looking for the functionality that I had with Snow Leopard and now seems to be absent. Maybe it's a bug in my Finder.

  • Find exact word in text file tht is present in an excel sheet

    Hi all,
    i want to find words in an text file.
    but the criteria is i want to search words which r already listed in another excel sheet and change the color of these word.
    i used FileInputStream
    and also BufferedInputStream
    cany anyone help me with this

    hi kajbj,
    can u plz tell me how to do in VBA then
    will find out the way to do in java
    Thanx

  • Find & Replace text in html files

    This is my first real attempt at using Automator, and it has become increasingly frustrating for me. I love the idea of Automator, nice interface, and it appears to be so easy to use. But, I can't get it to actually DO anything and I don't understand why.
    Here is my goal:
    to batch process multiple html files to remove certain characters and words (or replace them with empty space).
    I currently open these files in Pages and do 6 separate Find & Replace commands for each file before I continue with my other processing tasks. This is very tedious and I believe the computer should be able to find & replace multiple items at one time. (I have used other utilities to do batch renaming and trimming file names before.)
    All I want to do is select a group of files (usually 25 at a time) and have Automator get rid of all the unwanted words and characters before I open each file for final processing in Pages. I found a set of Automator actions for TextEdit which includes a Find & Replace action, but I've wasted over an hour so far trying to get it to work.
    When I run the workflow, it acts like it's doing something, but the files remain unchanged. I have tried using actions such as Read Text File, Get Contents of TextEdit Document, Set Contents of TextEdit Document, along with 6 instances of Find & Replace, but I cannot get it to work.
    I'm at a point today where I cannot afford to mess around with this anymore. I have to do it the long way in Pages or else I'll never get it done, but I want to get these Automator workflows to work before I have to repeat this task. (I do this at least once a week right now.)
    Any ideas or suggestions? I've tried reading in the help menus and support pages, but perhaps I'm just not understanding something here.

    Any ideas or suggestions?
    You might be interested in using TextWrangler. It can perform batch find-and-replace changes across multiple selected files.
    Good luck!
    Andrew99

  • How can I find the name of a file I downloaded four months ago?

    I downloaded a file on either February 15th or 16th. Embarrassingly, I've lost the file, simply by forgetting its name. I need to be able to search my download history, by date. Does anyone know of a way to do this? I know that the history is kept that long, and that I haven't erased the history. Finding the date that I visited the website was easy using history and an approximate date, but download history is less intuitive.
    And, no, revisiting the website doesn't help; the only way to find the name of the file there (it's an ebook) is to buy it again, which is NOT what I wish to do.
    This was in Windows 7 Home Premium Edition, with FireFox v. 28.0 (yes, I know it's outdated; I haven't been using that computer much lately). I don't know what version of FireFox was installed at the time of the download -- whatever was most current at the time, as I usually make a practice of installing updates.

    The downloads folder in the history manager? I'm not sure what you mean.
    When I click on History, I see what I've put in the screenshot. Then it starts telling me where I've been today. Nothing about downloads, per se. I've been getting at those through Tools/Downloads.
    I have FireFox set up to ask me where downloads should go, rather than automatically sending them to my Downloads folder in Windows, and even if it had automatically saved to Downloads, it wouldn't still be there now.
    In a pinch, I suppose I could skip the first few in the downloads list, and then start right-clicking on individual downloads and selecting Go To Download Page, but I was hoping there might be some way to narrow it down, by getting at the date on downloads. That's fairly easy in History, but I don't see any way to do it in Tools/Downloads.

  • When I connect my iphone to my itunes it says loads of space is being taken up by documents , however i have no documents saved on my phone to my knowledge. how do I find and delete these hidden files ?

    when I connect my iphone to my itunes it says loads of space is being taken up by documents , however i have no documents saved on my phone to my knowledge. how do I find and delete these hidden files ?

    I restored the phone so had no apps on it at all and there was still this certain amount of space used up by documents ! I've already had it in to the apple store and they didn't seem to have a clue either ! Ugh ! Wouldn't mind so much if the phone was free with a contract but I actually spent 450 quid buying this phone and it's always full of "nothing" so virtually unusable

  • Could not find application that created this file error in Acrobat

    What is going on? I have an InDesign file that I want to convert by opening Acrobat and then converting to PDF. I am getting the error "Could not find application that created this file. [file name] Please select a file created by an application that resides on your computer."
    I most often use this functionality when I have multiple files of different origins and need to combine them into one document. Now I'm reading the forums and some are saying this functionality is no longer supported by Acrobat. Pardon my language, but WTF?!?! This is functionality that is commonly used by me and I can only assume other users. Now you have two Adobe products that won't communicate? If so, then all the hoopla stating how great the Adobe suite is should be edited. I have never seen these products take such a step backward!
    Sorry for the rant, but I find this to be ridiculous. What is the workaround, besides converting every document to PDF inside its own software and then combing the PDFs?

    InDesign uses a different method of making PDF files when you use the File->Export option in InDesign (even with Acrobat installed, it uses an internal copy of the PDF Library engine). As such, the two applications do not communicate directly with each other.
    Support for driving the PDF conversion process from within Acrobat has been removed from Acrobat X, beacuse with the new features in InDesign CS4+, Acrobat doesn't have access to the settings it needs to control things such as multimedia, spreads and transitions. ID CS5 divides PDFs into two concepts - "print" and "interactive", neither of which match the presets used by Distiller. Creating PDFs from InDesign files must therefore take place from within InDesign itself.

  • How to find out the source program file in Proposal in Sales Online in CRM

    How to find out the source program file in Proposal in Sales Online in CRM

    You can find it in the oracle->apps->prp directory.
    It is the $JAVA_HOME

  • Function Module to find the Path of the file in the Application Server

    Hi All,
            Any function module available to find the path of the file stored in the application server. Please let me know.
    Thanks.

    Check this code:
      DATA: dl_file TYPE ibipparms-path.    " File name
      CONSTANTS: c_dir       TYPE  rlgrap-filename.
    * F4 filename for Application server
        CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
          EXPORTING
            directory        = c_dir
            filemask         = ' '
          IMPORTING
            serverfile       = dl_file
          EXCEPTIONS
            canceled_by_user = 1
            OTHERS           = 2.
        IF sy-subrc <> 0.
          MESSAGE e000 WITH 'Error while getting the file name'(006).
          EXIT.
        ELSE.
          p_file =  dl_file.
        ENDIF.
    Thanks & Regards,
    Siri.
    Message was edited by:
            Srilatha T

  • XML parser not able to find encoding format of xml file with jre1.4.2

    Hi
    I am using jre1.4.2_05 and Weblogic 8.1 version and i have a problem with finding encoding format of xml file.
    I need to parse a xml file and need to find which encoding format that xml is based on that i need to change logic.
    Need to know after parsing each xml file what encoding format the xml is? Here the problem is we are using jre1.4.2_05 by default DOM \ SAX parser is not supported and i looked at few third party parser which are also don't have facility.
    But in latest jre 1.5 or jdk1.5 has this feature. Its difficult to the project to upgrade to jre1.5 or more.
    Please let me know if you have any idea about the issue.

    I had a quick look around and I think you might be able to find them in the support portal...
    SAP Support Portal > Software Downloads > SAP Software Download Centre > Support Packages and Patches > Archive for Support Packages and Patches > Archive - Browse our Download Catalog > SAP Connectors.
    Let me know if you find them.
    Regards,
    Stephen.

  • Lync 2013 "Setup can't find or validate an installation file...."

    Enterprise client installation.
    We're running Windows 7 32bit SP2, Office 2010 32bit SP2.
    Attempting to run the install for Lync 2013 (32-bit) on a test system and get the following warning immediately:
    "Setup can't find or validate an installation file.  Please try installing Office from your installation source, or if you installed from a downloaded package, please re-download and re-install....."
    The source Lync 2013 file is direct from MVLS.
    Any reason why this install from MVLS refuses to run from the source?  Obviously, Lync 2013 wasn't included with Office 2010, so re-installing Office won't resolve this issue.
    Any help is appreciated.

    Hi,
    It may also cause by the issue of the conflict with other software, please use clean boot to test the issue. In this mode install Lync 2013 file again.
    You can refer to the link of “How to perform a clean boot in Windows”:
    http://support.microsoft.com/kb/929135
    If the issue persists, please also try to download Lync 2013 file and install again.
    Best Regards,
    Eason Huang
    Eason Huang
    TechNet Community Support

  • 10.5.8 Finder resets to default, desktop files gone!

    The Finder on my 2008 Mac pro is really acting up at the moment an I have no idea what's going on.
    My desktop has been wiped clean. Nothing there, except the drive icons. I don't keep much on the desktop but there should be a few folders and files that I always keep there for convenience. Also, Finder has reset to default settings - lost my custom Places from the sidebar and opens in icon view, which I never use.
    I looked at the actual folder in Finder as well and the files are definitely not there.
    What I have been doing:
    I ran iDefrag on my files disk (INT HD 1TB) a few days ago (first time). I forgot to turn off Time Machine so they have probably been running at the same time.
    Today Time Machine decided to backup everything from scratch, which I attribute to iDefrag switching everything around on my Files disk. Also filled the backup disk so I only have two backups at the moment, both from today.
    Other than that, I have mostly been using Adobe Bridge, Photoshop and InDesign CS4 for editing quite big files. Also Firefox for normal web browsing.
    Hard drives are reported to be ok. Profile is still the same name. The files are not in the Trash. Everything else is where it should be. System disk is 1/3 full. Files HD (which hasn't been affected AFAICS) 1 TB 1/2 full.
    Does anyone know what could be happening to my machine?

    I had the same problem and finally discovered that somehow my Desktop folder had become a Package. I could not do anything on the desktop but the apps and the dock etc. were working fine. I went to Go/Home Folder/Desktop/Show Package Contents and everything was there. But nothing appeared on the desktop. I could not open a new folder and anything I tried to drag to the desktop resulted in a permissions error. I tried all of the above fixes and more. The solution? Trash the desktop folder from your Home folder, empty the trash, reboot and start all over again. If you're lucky like I was you will have a Time Machine backup and you can restore a previous Desktop easily. Worked for me!

Maybe you are looking for