I am looking to convert a PDA to a DFA. Where the stack of the PDA will never contain more then n number of symbols.
Any help will be appreciated.
Thank you
I have no complete solution but just an idea: For each transition which pushes a symbol s on the stack you must copy the subgraph to the next pop transitions. The new subgraph must accept the same substring as the corresponding subgraph in the PDA for s. When you search for such transitions you must go from inside out, such that there no inner pushes and pops in the subgraph. Thus the first replacements will consist of two transistions, and the further subgraphs become larger and larger.
Related
Given the Truth Table, Characteristic Table and Excitation table for a JK Flip Flop. I am doing a K-Map to find Qn+1 (next state) given J, K and current State. The K-Map from a tutorial explaining this is shown below:
Why isn't JK' (not K) not included in the equation for Qn+1 ? Why is Qn+1 = QnK'+JQn when there is a grouping of two 1's in the right most corner which equals JK'
There should be atleast one non-overlapping cell in every group we are considering.
In your situation, JK' cannot be considered as both the cells is already present in 2 other groups and there is no non-overlapping cells.
Hence there is no point in considering JK'
I am working with linked lists in MIPS, and have one example that I am not sure about. It says:
write function rotate(head, a, b) that rotates elements of linked lists from position a to position b, such that if element was on position i(that belongs segment a,b) its new position is b+a-i. Numbers a,b are choosen such that a<b. Now, I don't get point of this example, because after we change elements for every position i, list will stay the same because of the formula(also it is considered that position of elements in list starts with 1 and goes to length of list).
Also, for every node in list, I think it is enough to replace only value field for corresponding indexes right(next field is not neccessary). Last sentence I am considering only if I had example where elements of list would really change(if my assumption above is correct).
On google spreadsheet, how to identify all cells containing a word whom first cell is capitalized ?
Terrible Q (no research shown, unclear, inconsistent, poor capitalisation, no sample data, bad grammar) but, perhaps, a very easy solution. Select all cells and apply a CF formula rule of:
=regexmatch(A1,"\b[A-Z]")
I have a tiff file and the text on it, which has been OCR'd at an earlier stage. The words have their exact positions as information (upper left, lower right). I now need to read the text within a user-drawn rectangle.
Normal paragraphs are no problem, but I don't know how I should handle text columns. If there are two paragraphs next to each other, simply taking the row as a single line would make the result unusable.
Are there algorithms to help me put the words in the right order? I'm guessing that I have to examine the spaces between words to detect patterns that identify columns. I would like to avoid processing the image directly, although it should be possible (but no OCR).
I am also unsure about the influence of lists/tables, e.g. in orders & bills. A line-orientated approach would probably be better here.
I am developing in Delphi, but adaptable algorithms in other languages would also be appreciated.
edit: I will try to post sample data tomorrow, but basically I have an Array of Words, with their respective coordinates on the image (I could easily draw a rectangle around them, for example).
Suppose your original text is in two columns like this:
Aaaa bb ccc ddddd mmmm nn oooo pp
eee fff ggggg hh qqq rrrrrrrrr
i jjjj kkk lll sss tttt uu.
From your description, it sounds like your OCR has given you the individual words and their bounding rectangles. If the original page is scanned orthogonally, then all of the words on a given line should have the same (or very close) y values. If they're not exactly the same, you can do an integer division on the vertical positions with some fraction of a typical box height. That should cluster the y values. You can do similar processing on the x coordinates to ensure that words at the edge of a column also have identical x values.
To detect the separate columns, I'd try making a histogram of all the "left" values of all the words (or right edges if your text runs right-to-left). You should see a peak at the beginning of each column.
You can probably rule out any false positives by ensuring that, on every line, there is a gap between the right coordinate of the last box before the candidate start of a column. The gap should probably be at least as large as the smallest width of any word.
You can then partition your words up into column groups by checking which horizontal range their left and right coordinates fall in to. In our example, the words from Aaaa through lll would end up in the first partition and the words from mmmm through uu. would end up in the second partition.
Within each partition, you can then partition on line by sorting on the y coordinates. Finally, for each line, you sort on the x coordinate. (Whether you sort on ascending or descending depends on your coordinate system and the direction your text flows.)
The same basic idea could be applied to tables as well as columns of text, but you might need some tweaks to deal with things like right-justified cells.
Using a temp variable to store max value does not work for pop operations.
If you don't care about O(n) in the push operation:
My personal approach would be to keep a linked list of sorted items.
Whenever you pop an item, compare it to the highest item in the sorted list. If it is the same, remove the highest item from the list, in addition to popping the item. If it is not, just pop the item.
This way, you should always have the highest item at the last element of the linked list, and the time for popping is O(1).
If you also need O(1) for pushing, then I'll have to pass.
You can't. A stack is unsorted, which means that you have to inspect all N values to find the highest. That alone means it is at least O(N) while "constant time " means O(1)
You can do this by managing an additional stack that holds maximums.
The algorithm would be like this:
Upon push, compare the new element to the top of the maximums stack. If not less, push it there as well. Upon pop, compare the element to the top of maximums stack. If equal, pop it from there as well.
At any given time, top of maximums stack is the maximum element.