Iterative DFS vs Recursive DFS and different elements order

I have written a recursive DFS algorithm to traverse a graph: void Graph<E, N>::DFS(Node n) { std::cout << ReadNode(n) << ” “; MarkVisited(n); NodeList adjnodes = Adjacent(n); NodeList::position pos = adjnodes.FirstPosition(); while(!adjnodes.End(pos)) { Node adj = adjnodes.ReadList(pos); if(!IsMarked(adj)) DFS(adj); pos = adjnodes.NextPosition(pos); } } Then I have written an iterative DFS algorithm using a stack: … Read more

How does a sentinel node offer benefits over NULL?

On the Sentinel Node wikipedia page it says that the benefits of a sentinel node over NULL are : Increased speed of operations Reduced algorithmic code size Increased data structure robustness (arguably). I don’t really understand how the checks against a sentinel node would be faster (or how to properly implement them in a linked … Read more

How do I convert an Int to a String in C# without using ToString()?

Convert the following int argument into a string without using any native toString functionality. public string integerToString(int integerPassedIn){ //Your code here } Since everything inherits from Object and Object has a ToString() method how would you convert an int to a string without using the native ToString() method? The problem with string concatenation is that … Read more

How much do two rectangles overlap?

I have two rectangles a and b with their sides parallel to the axes of the coordinate system. I have their co-ordinates as x1,y1,x2,y2. I’m trying to determine, not only do they overlap, but HOW MUCH do they overlap? I’m trying to figure out if they’re really the same rectangle give or take a bit … Read more

Good algorithm and data structure for looking up words with missing letters?

I need to write an efficient algorithm for looking up words with missing letters in a dictionary and I want the set of possible words. For example, if I have th??e, I might get back “these”, “those”, “theme:, “there”, etc. There will be up to TWO question marks and when two question marks do occur, … Read more