O SlideShare utiliza cookies para otimizar a funcionalidade e o desempenho do site, assim como para apresentar publicidade mais relevante aos nossos usuários. Se você continuar a navegar o site, você aceita o uso de cookies. Leia nosso Contrato do Usuário e nossa Política de Privacidade.
O SlideShare utiliza cookies para otimizar a funcionalidade e o desempenho do site, assim como para apresentar publicidade mais relevante aos nossos usuários. Se você continuar a utilizar o site, você aceita o uso de cookies. Leia nossa Política de Privacidade e nosso Contrato do Usuário para obter mais detalhes.
The first battle is to know “what problem to solve?”.
Formalize a problem: Stating the problem in a known model. Example: Graphs, flow diagrams, formal grammar etc.
Algorithm is a finite sequence of instructions, each of which has a clear meaning and performed in a finite amount of effort in a finite amount of time. Often pseudo language is used to represent algorithms, which is a combination of constructs of a programming language with informal natural language( like English, Tamil, French etc.) statements. The pseudo language depends on the environment, for example in an environment where C Prog. Language is used then pseudo will be more like C language.
A particular algorithm is selected for solving a problem based on its efficiency which can be found by analyzing the algorithm. If possible the algorithm can be modified to improve the efficiency. Representing the same in a formal model like Automaton, Turing machine, etc will help in doing so. Another advantage in using formal models is that the limits of computing can be found.
Solution: Tech (i): get the string and count the characters, returns 1 if the length_string % 2 = 0 else returns 0. How much memory this algorithm needs? Tech (ii): Consider an array of size 2. get the input character by character and store the characters in the array by overwriting the previous characters. Check at which position the input ends. If it is at position 2 then return 1 else return 0. Tech (iii): get the input character by character. Each time do “input=(input+1) mod 2”. if the input is 0 then return 0 else return 1.
Assume the road is broad enough to handle the peak traffic. There is space enough at the junction to handle the traffic.
Here the Kirchoff’s 1 st law is applicable.( at a junction, the incoming current = outgoing current). How comes there are 9 possible turns? Is there any generalised formula? Ans: . If there are n roads meeting at a point and all the roads are two way roads then there will be n *(n-1) possible turns. Let there are k one ways (k1 inways and k2 outways at the junction, k=k1 + k2). Then the number of two ways are (n-k). So the total possible turns will be = (n-k) * (n-k-1) + (n-k) * k2 + k1*(n-k+k2) = (n-k) * (n-k-1) + (n-k) * k2 + k1 * (n-k1)
G<v, e> is a graph where v is the set of vertices and e is the set of edges. Incompatible turns: The turns that cannot be done simultaneously are incompatible turns. The nodes (vertices) represent the possible turns. The edges represents that the turn connected to other turns cannot appear simultaneously (this is taken into consideration of Indian roads – left drive)
The graph coloring problem in NP Complete ( it is only having exponential algorithms and need to do exhaustive methods). We have to use as few colors as possible. Finding an optimal solution for this problem is computationally very expensive.
Here each color represents each phase of the controller( don’t confuse with the traffic signal colors Red, Green and Yellow). When there is a signal RED means all the turns in that color are only permitted.
To improve the performance, we can make some intelligent decisions like if the source is same then no need to check. Example: To check for AB there is no need to check for the turns starting with A like AC, AD etc.
In greedy technique we can get a good solution but not necessarily the optimal solution.