Posts

Solve the Maze by DFS (Depth First Search)

Image
In maze traversal, we must have to traverse deeper as soon as possible through the selected particular path until we reach the dead end. When we are on the way in that path, if it closed then we must have to back track to previous state to select another path. For this reasons, this traversal very similar to the DFS algorithm. Strategy for exploring Maze:  To convert given maze to a graph mark each intersection, corner and dead end (vertex) visited.  We mark each corridor (edge) as traversed.  We keep track of the path back to the entrance (start vertex) by means of a rope. (recursion stack) According to above all reasons, DFS (Depth First Search) algorithm very similar to a classic strategy for exploring a maze. Implementation in C# Graph.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Maze_traversal {     class Graph     {        ...

Stable Married Couple Problem

There are two groups of men and women who desire to get married. Participants of each group indicate who among the opposite sex would be acceptable as a potential spouse. Every woman can be married to at most one man, and every man to at most one woman. To solve this problem, we used set of input data for equal number of men and women, where each person has an ordered list of preferences for whom that person would like to marry. Task is to pair up the man with the woman in such a way that no one is unsatisfied with their partner.  There we used bipartite graph implementation through the adjacency matrix and BFS algorithm to pair up (married couple) men and women and repeatedly improve the pairings as necessary until every person is satisfied. Consider an engagement (m, w) between man m and woman w. It says that (m, w) is unstable if either m or w has another person they would rather marry. It means unstable engagement meets one or more of the following condition. (Following ...

Rabin Karp Algorithm

A military group is monitoring messages from terrorists which are transmitted as binary coded data streams. (a) The military is looking for an efficient way to search an identified pattern in the serial stream, in the data so far monitored, at a given time. In this setting, suppose the message T[1 ...n] is being transferred serially, in the order T[1],T[2],.... the military is interested in checking if the text seen so far contains a pattern P, where P has length m. Every time when the next letter of the text T is transmitted, it is necessary to check if the text seen so far contains P. (b) Now the terrorists are broadcasting reversed messages of the original message. So that although the same pattern P is used, the text T[1 ...n] is being transferred in reverse. That is, in the order T[n],T[n−1],... .Modify your algorithm so that it still detects the occurrence of P in the text T[i...n] immediately (i.e., in constant time) after the letter T[i] is seen. Implementation in C# ...

Integration by Parts

Image
When find the solution through the Simpson rule for " I" we must have to choose the step size neither small nor large to get the accurate answer. It means we have to limit the number of sub segments for the higher accuracy. If we select large number of sub segments it should affect to increase the round off error, and if we choose small number of sub segments we can’t get exact solution. There I used multiple segments Simpson 1/3 rule and Simpson 3/8 rule to solve above equation. Because Simpson 1/3 only works for even number of segments and Simpson 3/8 works for multiplication of 3 segments. Multiple segments Simpson 1/3 rule Multiple segments Simpson 3/8 rule According to my program user can select the number of segments (n) as they want. When we apply a = 0, b = 1, assume n = 50 segments, h = (1-0 )/50 we can do the calculation in below progress. Here is the result from Simpson 1/3 rule.    When above constant values apply to Simpson 3/8 rule we c...

Integration of cos(x)

Image
We can find analytical value as below, The solution from the " I"  in above range through the Simpson rule we can get 0.00000 as an approximation value. There we can’t calculate the absolute relative true error. Because the actual value of the integration of cos(x) from 0 to 180 degrees it gets zero. If we will find absolute relative approximation error there should be happened division by zero. The most optimum value of the “h” should be an average value such as “0.01”. It means we should select average number of segments as 48 or 54. Because if we select very large h it decreases the number of segments. As a result we can’t get accurate value. And if we select very small “h” it increases the number of segments. But it should affect to increase the round-off error. That is the reason for we must have to select average value of number of segments to get “h”. Implementation in FORTRAN 1.)Do the compilation as below.     gfortran -ffree-form s...

Text-to-Speech converter

Image
A speech recognition application will typically perform the following basic operations:  Initialize the speech recognizer.  Create a speech recognition grammar.  Load the grammar into the speech recognizer. Register for speech recognition event notification. Create a handler for the speech recognition event. Create a new project in Visual Studio 2010 via select the  File Menu  > New Project Browse to other languagues Select visual basic and windows application enter Name as TextToSpeechVB. when the project is created you have to add a reference to the System.Speech.dll under .NET Tab. Now design the form in following manner. 1. ComboBox control(cmbInstalled) - to list all available installed voices 2. Button Control(btnStart) - To starting the Text-to-Speech 3. Button Control(btnEnd) - To stop the Text-to-Speech 4. Track Bar control(btnRate) - to control the Text-to-Speech speed rate. 5. Trach Bar Control( btnVolume)- to ...

Memory allocation/deallocation routines malloc() and free()

Image
According to my declaration, allocate the 50000 block of array. If memory block is available on the array, the program allocates a block from the array according to specify size.    Here I used the array data structure to implement the heap. In this code taken large contiguous buffer which used to allocate all the spaces associate with the NewMalloc() function. There doesn't allocate the same region of memory to two different NewMalloc() . Initially all 50000 bytes are free in this array. NewMalloc()              It takes one integer argument which represents the size and return a pointer to a contiguous region of that many bytes.              Now call to NewMalloc(60) . There we expect to allocate the first 60 bytes and return a pointer to the caller. Actually in the array allocates 68-bytes for that region. Because I maintain a meta data that k...