I just start learning automata. It seems easy to understand given DFA and not too difficult to design one. But I feel it's very hard to prove things...
Can anyone give a informal proof for this question or some hint? Thanks a lot!
PS: sorry I didn't phrase very clearly. What #Dan said is exactly what I mean:
why deciding the question "Given a string w. Does the automaton accept
or reject w?" can be done in linear time?
I guess you want to know why deciding the question "Given a string w. Does the automaton accept or reject w?" can be done in linear time?
Suppose w=a_1...a_n. Start in the initial state q_0 and apply the transition \delta(q_0, a_1) = q_1, which brings you to q_1. Now, repeat this n times untill you processed the last letter. That's a linear time algorithm ;)
Try thinking about it this way:
How many times is each character in the input string read by the DFA?
How much work does the DFA do when processing a single character from the input?
Hope this helps!
Related
I am trying to implement the algorithm of Fruchterman and Reingold and have a problem in understanding the types of the "t" (temperature) and "disp" (displacement) because on the last loop they calcualte the minimum of t and disp. Is t not a number and disp a vector? How can I calculate the minimum of a number and a vector?
Link: www.cs.brown.edu/people/rtamassi/gdhandbook/chapters/force-directed.pdf#page=5
As a disclaimer, I have no previous experience of this algorithm, but it seems to me as if you are right and that this is a typo, where actually min(|v.disp|, t) was meant.
I find some support for my claim looking at an implementation here, which recognises some typos in the original pseudo-code. Please verify yourself before taking my word for it.
I have looked for an answer for this question which seems trivial, but I didn't find any.
Can a Turing machine, given a word w, calculate the length of the word?
Yep, certainly! Here’s something to think about:
How would you design a TM to increment a binary number?
How could you use that other TM as a subroutine to count the input length?
Another perspective: remember that by the Church-Turing thesis anything you can do with any effective model of computation you can do with a TM, so since other models can measure input length, TMs can do it as well.
Currently learning about the A* search algorithm and using it to find the quickest solution to the N-Puzzle. For some random seed of the initial starting state, the puzzle may be unsolvable which would result in extremely long wait times until the algorithm has search the entire search-space and determined there is not solution to the give start state.
I was wondering if there is a method of precalculating whether the A* algorithm will fail to avoid such a scenario. I've read a bit about how it is possible but can't find a direct answer as to a method in which to do it.
Any guidance or options are appreciated.
I think A* does not offer you a mechanism to know whether or not a problem is solvable. Specifically for N-Puzzle, I think this could help you to check if it can be solved or not:
http://www.geeksforgeeks.org/check-instance-8-puzzle-solvable/
It seems that if you are in a state where you have an odd amount inversion, you know for sure the problem for that permutation is infeasible.
For the N-puzzle specifically, there are only two possible parities, so you just need to check which parity the current puzzle is.
There is an in-depth explanation on how to do this on the math stackexchange
For general A* problems, no, there is no way to pre-compute if the graph is solvable.
I have a few questions regarding the semantics of terminology used when describing algorithms.
Firstly, what is meant by a 'naive' algorithm? How does this differ from other solutions to a given problem? What other forms can solutions take?
Secondly, I have heard much reference to having a 'closed - form' solution. I have no idea what this means either - but often it appears when trying to solve recurrence relations...
Thanks for your time
A Naive algorithm is usually the most obvious solution when one is asked a problem. It may not be a smart algorithm but will probably get the job done (...eventually.)
Eg. Trying to search for an element in a sorted array.
A Naive algorithm would be to use a Linear Search.
A Not-So Naive Solution would be to use the Binary Search.
A better example, would be in case of substring search Naive Algorithm is far less efficient than Boyer–Moore or Knuth–Morris–Pratt Algorithm
A Closed Form Solution is a simple Solution that works instantly without any loops,functions etc..
Eg:
Iterative Algorithm for sum of integer from 1 to n
s= 0
for i in 1 to n
s = s + i
end for
print s
Closed Form (for the same problem)
s = n * (n + 1 ) /2
Naive algorithm is a very simple algorithm, one with very simple rules. Sometimes the first one that comes to mind. It may be stupid and very slow, it may not even solve the problem. It may sometimes be the best possible. Here's an example of a problem and "naive" algorithms:
Problem: You are in a (2-dimensional) maze. Find your way out. (meaning: to a spot with an "EXIT" sign :)
Naive algorithm 1: Start walking and choose the right one in every intersection you meet (until you find "EXIT").
Naive algorithm 2: Start walking and choose a random one in every intersection you meet (until you find "EXIT").
Algorithm 1 will not even get you out of some mazes!
Algorithm 2 will get you out of all mazes (although this is rather hard to prove).
Closed form means you can give the one expression as solution, that does solve it without recurrence/recursive. Here one should remark, that it is not always possible to find such a closed form.
Naive means just that what it says: A first, stupid solution to the problem, that solves it, but maybe not very time-/space efficient. What one really considers 'naive' depends on the speaker, the context, and the weather of the next day. Often it is used to distinguish a very sophisticated solution (that uses some kind of trick) from the obvious implementation.
I want to find the lexicographically smallest perfect matching in two partial graphs. I'm supposed to use Kuhn's algorithm, but I don't understand how to make matching lexicographically smallest. Is it at all possible in Kuhn's algorithm? I can provide my code, but it's classic enough.
As a hint, consider how you could determine where just the first node should be matched in the lex-min matching.
In most cases like this it is usually easier to make a reduction instead of modifying the algorithm:
Find a way to change the input in your problem so that lexicographical order breaks any ties (but in a manner that perfect matchings still have a higher score than imperfect ones)
Run the modified graph through Kuhn's algorithm.
If needed, translate the answer back to the original problem.
I haven't tried to actually solve this myself or read the problem in detail. But this seems to be a textbook exercise and I feel this answer is enough :-)
Think about how you can create assignment prices that encourage lexicographically early matchings.