﻿<?phpxml version="1.0" encoding="utf-8"?>
<rss version="2.0" 
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
>
<channel>
<title>Common Interview Questions / aleksin / All</title>
<link>http://commoninterview.com</link>
<description>The source for Job Interview Questions and Job Search Networking</description>
<pubDate>Sat, 18 Jun 2011 15:46:45 -0600</pubDate>
<language>en</language>
<item>
<title><![CDATA[How to identify AJAX request with C# in MVC.NET?]]></title>
<link>http://commoninterview.com/Programming_Interview_Questions/how-to-identify-ajax-request-with-c-in-mvc-net-1/</link>
<comments>http://commoninterview.com/Programming_Interview_Questions/how-to-identify-ajax-request-with-c-in-mvc-net-1/</comments>
<pubDate>Sat, 18 Jun 2011 15:46:45 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Programming Interview Questions</category>
<guid>http://commoninterview.com/Programming_Interview_Questions/how-to-identify-ajax-request-with-c-in-mvc-net-1/</guid>
<description><![CDATA[<b> Answer </b><br /><br />The solution is in depended from MVC.NET framework and universal across server-side technologies. Most modern AJAX applications utilize XmlHTTPRequest to send async request to the server. Such requests will have distinct request header:<br /><br /><i>X-Requested-With =  XMLHTTPREQUEST</i><br /><br /><img title='Example of AJAX request header' src='http://commoninterview.com/images/AJAX_GET.png' alt='AJAX GET Request'><br /><br />MVC.NET provides helper function to check for ajax requests which internally inspects X-Requested-With request header to set IsAjax flag.<br /><br /><b><a href='http://msdn.microsoft.com/en-us/library/system.web.webpages.helperpage.isajax(v=vs.99).aspx'>HelperPage.IsAjax Property</a></b><br />Gets a value that indicates whether Ajax is being used during the request of the Web page.<br /><br /><b>Namespace:</b>  System.Web.WebPages<br /><b>Assembly:</b>   System.Web.WebPages.dll<br /><br />However, same can be achieved by checking requests header directly:<br /><br />Request["X-Requested-With"] == "XmlHttpRequest"  <br /><br/><br/>1 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[Prints odd numbers less than N]]></title>
<link>http://commoninterview.com/Programming_Interview_Questions/prints-odd-numbers-less-than-n/</link>
<comments>http://commoninterview.com/Programming_Interview_Questions/prints-odd-numbers-less-than-n/</comments>
<pubDate>Tue, 19 Apr 2011 23:06:28 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Programming Interview Questions</category>
<guid>http://commoninterview.com/Programming_Interview_Questions/prints-odd-numbers-less-than-n/</guid>
<description><![CDATA[Question:<br />Write recursive method that for a positive integer n prints odd numbers<br /><br />Answer:<br /><br />I usually use binary check to solve this type of questions:<br /><br />if ((N &amp 1) != 0)  then N is odd<br /><br />So the code would look like<br /><br /><code><br />for(int i=0;i&lt;=N;i++)<br />{<br /> if ((i &amp 1) != 0) <br />  {<br />   Console.WriteLine(i);<br />  }<br />} <br /></code><br /><br />Another, simplier option is to use increment by 2<br /><br /><code><br />for(int i=1;i&lt;=N;i+=2)<br />{<br />  Console.WriteLine(i);<br />} <br /></code><br /><br/><br/>1 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[What is user agent of Windows Phone 7 ?]]></title>
<link>http://commoninterview.com/technical_questions/what-is-user-agent-of-windows-phone-7-/</link>
<comments>http://commoninterview.com/technical_questions/what-is-user-agent-of-windows-phone-7-/</comments>
<pubDate>Tue, 05 Apr 2011 22:23:14 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Technical Questions</category>
<guid>http://commoninterview.com/technical_questions/what-is-user-agent-of-windows-phone-7-/</guid>
<description><![CDATA[<b>Answer:</b><br /><br />The question is targeting to test mobile device development experience as the most common server-side device detection practice is to examine the user agent. <br /><br />According to Wikipedia user agent is a client application implementing a network protocol used in communications within a client-server distributed computing system. <br /><br /><br />For example, the user agent string for Internet Explorer Mobile is the following:<br /><br /><b><br />Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0) &lt;DeviceManufacturer&gt;;&lt;DeviceModel&gt;<br /></b><br /><br />So, for example for Windows Phone 7, LG device the user agent would look like following:<br /><br /><b><br />Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0) LG;LG-E900h<br /></b><br /><br />Reference:<br /><a href='http://go.microsoft.com/?linkid=9713253'>Designing Web Sites for Phone Browsers</a><br /><a href='http://www.botsvsbrowsers.com/category/33/index.html'><br />List of User Agent Strings</a><br/><br/>2 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[What is dependency injection (DI) pattern?]]></title>
<link>http://commoninterview.com/Programming_Interview_Questions/what-is-dependency-injection-di-pattern/</link>
<comments>http://commoninterview.com/Programming_Interview_Questions/what-is-dependency-injection-di-pattern/</comments>
<pubDate>Tue, 05 Apr 2011 20:10:13 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Programming Interview Questions</category>
<guid>http://commoninterview.com/Programming_Interview_Questions/what-is-dependency-injection-di-pattern/</guid>
<description><![CDATA[The basic idea of the Dependency Injection is to have a separate object, an assembler, that populates a field in the lister class with an appropriate implementation for the finder interface. <br /><br />The core principal of the pattern is to <b>separate behavior from dependency resolution</b>.<br /><br />There are many frameworks to help implement Dependency Injection.<br /><br />In JAVA:<br /><br />a. <a href='http://www.springsource.org/'>Spring Framework</a><br />In Spring Framework, Dependency Injection (DI) design pattern exits in both major flavors: <br />Setter Injection and Constructor Injection<br /><br />b. <a href='http://code.google.com/p/google-guice/'>Google's guice</a><br />Guice (pronounced 'juice') is a lightweight dependency injection framework for Java 5 and above. It provides constructor injection.<br /><br />c. <a href='http://picocontainer.org/introduction.html'>PicoContainer</a>. The framework most important feature is its ability to instantiate arbitrary objects. This is done through its API, which is similar to a hash table. You can put java.lang.Class objects in and get object instances back<br /><br />In .NET<br /><br />a. <a href='http://msdn.microsoft.com/en-us/library/ff648512.aspx'>The Unity Application Block</a> aka Unity. Unity is a lightweight, extensible dependency injection container that supports constructor injection, property injection, and method call injection. You can use it with Enterprise Library to generate both Enterprise Library objects and your own custom business objects. <br /><br />b. <a href='http://structuremap.net/structuremap/index.html'>StructureMap</a> is a Dependency Injection / Inversion of Control tool for .Net that can be used to improve the architectural qualities of an object oriented system by reducing the mechanical costs of good design techniques. StructureMap can enable looser coupling between classes and their dependencies, improve the testability of a class structure, and provide generic flexibility mechanisms.<br /><br /><br />More information:<br /><br /><a href='http://martinfowler.com/articles/injection.html'>Inversion of Control Containers and the Dependency Injection pattern</a><br /><br/><br/>1 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[How to get DOM element for the input control by using JQuery]]></title>
<link>http://commoninterview.com/technical_questions/how-to-get-dom-element-for-the-input-control-by-using-jquery/</link>
<comments>http://commoninterview.com/technical_questions/how-to-get-dom-element-for-the-input-control-by-using-jquery/</comments>
<pubDate>Sat, 12 Feb 2011 13:24:16 -0700</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Technical Questions</category>
<guid>http://commoninterview.com/technical_questions/how-to-get-dom-element-for-the-input-control-by-using-jquery/</guid>
<description><![CDATA[Answer:<br /><br />This is one of the most popular JQuery interview questions, as it tests understanding of multiple areas such as JQuery JS objects, JQuery syntax, DOM objects and the difference between JQuery objects and DOM objects.<br /><br />Traditional approach of finding DOM elements:<br /><br />var myInput = document.getElementByID('myInputID');<br /><br />Same can be done with JQuery<br /><br />var myJqueryImput = $('#myInputID');  //using selector <br />var myInput = myJqueryImput[0]; // getting reference to DOM object<br /><br /><br/><br/>1 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[How many gas stations are there in the USA]]></title>
<link>http://commoninterview.com/Programming_Interview_Questions/how-many-gas-stations-are-there-in-the-usa/</link>
<comments>http://commoninterview.com/Programming_Interview_Questions/how-many-gas-stations-are-there-in-the-usa/</comments>
<pubDate>Thu, 12 Aug 2010 12:41:44 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Programming Interview Questions</category>
<guid>http://commoninterview.com/Programming_Interview_Questions/how-many-gas-stations-are-there-in-the-usa/</guid>
<description><![CDATA[This question is one of many variations of so called Fermi estimations or Fermi problems. <br /><br />The point of Fermi problems is in part to show how much use can be made of commonly available knowledge by the person willing to be resourceful and make approximate simple calculations, but it is more to illustrate the difference between estimation and guessing. <br /><br />The canonical Fermi problem is the question "<a href='http://www.ph.utexas.edu/~gleeson/httb/section1_3_3_5.html'>How many piano tuners are there in Chicago?</a>"<br /><br /><u>So, the estimations are simple:</u><br /><br />1. Population of USA is about 300M (<a HREF='http://www.bing.com/search?q=population+of+usa&form=QBLH&qs=n&sk=&sc=8-16&mkt=en-us'>Population of USA</a>)<br /><br />2. Let's say each household have 4 people in average, so we have about 75M households<br /><br />3. On average each house hold has 2 cars, so there are 150M cars in the US<br /><br />4. Each gas pump filled twice a day and holds about 2K-3K, considering each station has about 10 pumps, we can estimat that each station can hold about 60K galons of gas daily<br /><br />5. Approximate gas tank is about 80gal, so to fill all the cars in the *at once* USA we would need about 6B galons of gas<br /><br />6. Bases on estimations above, we would need gas from approximatly 100K gas station to fill all the cas in the USA at once<br /><br />7. Considering there are no lines on the gas stations and there is always gas available, I would add 50% to that number, so there are probably around 150K gas stations in the USA<br /><br /><i>Actually that estimate is not that far from actual number:<br /><a href='http://en.wikipedia.org/wiki/Filling_station'>Number of filling stations in the USA</a><br /></i><br /><br/><br/>1 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[Design an alogrithms and data structure to retrieve median of vector (array) in constant time.]]></title>
<link>http://commoninterview.com/Programming_Interview_Questions/design-an-alogrithms-and-data-structure-to-retrieve-median-of-vector-array-in-constant-time-/</link>
<comments>http://commoninterview.com/Programming_Interview_Questions/design-an-alogrithms-and-data-structure-to-retrieve-median-of-vector-array-in-constant-time-/</comments>
<pubDate>Fri, 06 Aug 2010 20:50:05 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Programming Interview Questions</category>
<guid>http://commoninterview.com/Programming_Interview_Questions/design-an-alogrithms-and-data-structure-to-retrieve-median-of-vector-array-in-constant-time-/</guid>
<description><![CDATA[<b>Full question:</b><br /><br /><i>You have a vector of signed integers and you need to support an API with two exposed methods, insert(int) and getmedian(). <br />Describe a data structure you would use to support this API and describe the running time of the two methods.</i><br /><br /><b>Sample Answer</b><br /><br />What is a median ?<br />Median is s the number separating the higher half of a sample, from the lower half.<br /><br />Thus, the question actually needs some clarification, as median might be treated differently in case of even number of elements in an array.<br /><br /><u>Two most common approaches are:</u><br /><br />1. Calculate average of the two middle numbers<br />2. Use largest(smallest) as median<br /><br />Then you agree on the definition, the answer is quite simple and very elegant. You should use min-max-median heap ADS (abstract data structure).<br /><br />Min-max-median heap abstract data structure consists of two heaps connected via root node. Such as, root is a median and right child of the root is min heap of all elements from the array bigger than median, while left node is a max heap of all elements less than a median.<br /><br /><u>Formal definition:</u><br /><br />An mmm-heap is a binary tree with the following properties:<br /><br />1) The median of all elements is located at the root.<br /><br />2) The left subtree of the root is a min-max heap H1 of size r((n - 1)/2)1, containing elements less than or equal to the median. <br /><br />3) The right subtree is a max-min heap H, of size L((n - 1)/2)J containing only elements greater than or equal to the median.<br /><br />Here is the research article on Min-Max heaps and the usage of such data structures:<a href='http://www.cs.otago.ac.nz/staffpriv/mike/Papers/MinMaxHeaps/MinMaxHeaps.pdf'>MinMaxHeaps.PDF</a><br /><br /><u>Runing times:</u><br /><br />GetMedian()  - constant time O(1), as we need just get the tree root<br /><br />Inset(int)  - log(n) by using standard heap insertion<br /><br /><br/><br/>2 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[How to get host name for a given URL in JavaScript]]></title>
<link>http://commoninterview.com/Programming_Interview_Questions/how-to-get-host-name-for-a-given-url-in-javascript/</link>
<comments>http://commoninterview.com/Programming_Interview_Questions/how-to-get-host-name-for-a-given-url-in-javascript/</comments>
<pubDate>Thu, 05 Aug 2010 16:12:06 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Programming Interview Questions</category>
<guid>http://commoninterview.com/Programming_Interview_Questions/how-to-get-host-name-for-a-given-url-in-javascript/</guid>
<description><![CDATA[Answer:<br /><br />The simplest way is to add prototype to string object and use regular expression inside prototype function as following:<br /><br /><br />String.prototype.getHostName = function() {<br />    var str = this;<br />    var re = new RegExp('^(?:f|ht)tp(?:s)?://([^/?]+)', 'im');<br />    return str.match(re)[0].toString();<br />}<br/><br/>2 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[JavaScript doesn't have string trim function how would you implement one?]]></title>
<link>http://commoninterview.com/Programming_Interview_Questions/javascript-doesnt-have-string-trim-function-how-would-you-implement-one/</link>
<comments>http://commoninterview.com/Programming_Interview_Questions/javascript-doesnt-have-string-trim-function-how-would-you-implement-one/</comments>
<pubDate>Thu, 05 Aug 2010 16:04:17 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Programming Interview Questions</category>
<guid>http://commoninterview.com/Programming_Interview_Questions/javascript-doesnt-have-string-trim-function-how-would-you-implement-one/</guid>
<description><![CDATA[There are  couple options and interviewer looking on multiple things in your answer.<br /><br />Sample Answer:<br /><br />JQuery provides string trimming function and if our project already uses JQuery we can use <b>jQuery.trim(string)</b> function. If not, the simples way would be to utlize regular expressions and extend string object by using prototypes as following:<br /><br /><br /> String.prototype.trim = function() {<br />       return this.replace(/^s+|s+$/g,"");<br />   }<br /><br />It worth mentioning that JS regular expressions are compatible with Javascript 1.2+ and all modern browsers will support this.<br/><br/>2 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[Fibonacci numbers interview questions]]></title>
<link>http://commoninterview.com/Programming_Interview_Questions/fibonacci-numbers-interview-questions-1/</link>
<comments>http://commoninterview.com/Programming_Interview_Questions/fibonacci-numbers-interview-questions-1/</comments>
<pubDate>Sat, 17 Jul 2010 02:41:29 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Programming Interview Questions</category>
<guid>http://commoninterview.com/Programming_Interview_Questions/fibonacci-numbers-interview-questions-1/</guid>
<description><![CDATA[<p>One of most common question from this area is to write a function which return Nth number of Fibonacci sequence.</p><br /><p>Fibonacci numbers are a sequence of numbers defined by following formula:</p><br /><br /><span style=\"text-align: center; font-size: 26px;\">ω<sub>n</sub>=ω<sub>n-1</sub>+ω<sub>n-2</sub></span><br /><br /><p>The first number of the sequence is 0, the second number is 1, and each subsequent number is equal to the sum of the previous two numbers of the sequence itself, yielding the sequence 0, 1, 1, 2, 3, 5, 8, etc. (<a href=\"http://en.wikipedia.org/wiki/Fibonacci_number\" target=\"_blank\">Wikipedia</a>). </p><br /><p>Being very simple from the one side and quite sophisticated from the other Fibonacci numbers are the perfect candidate for the technical coding interview.  During my last year job hunt, I actually end up answering questions about Fibonacci numbers on every other interview I had.</p><br /><p><strong> </strong></p><br /><br /><p><strong>Problem 1.</strong> <em>Write a function which return Nth number of Fibonacci sequence </em></p><br /><br /><p>The most simple and the most popular solution you would see during the interview employ recursive nature of the sequence.</p><br /><p><span style=\"text-decoration: underline;\">Possible solution #1 - Recursion</span></p><br /><br /><code><br />static int Fibonacci (int n) <br />{<br />  if(n < 0) <br />     throw new ArgumentException(\"Input parameter invalid\"); <br /><br />  int N;  <br /><br />  if (n == 0) N = 0; <br />     else<br />       if (n == 1 || n == 2) N = 1;<br />        else<br />          N = Fibonacci(n - 1) + Fibonacci(n - 2);  <br /><br />return N; <br />}<br /></code><br /><br /><p>While totally valid, this is probably the worst solution you can give during the interview. Recursion in this case is total overkill as it requires keeping all sequence in the memory. </p><br /><br /><p><u>Possible solution #2 - Iteration </u></p><br /><br /><code><br />static int Fibonacci (int n) <br />{ <br />            int index1 = 1, index2 = 1; <br />            if (n == 0) return 0; <br />            if (n == 1 || n == 2) return 1; <br />            int current; <br />            for (int i = 2;i&lt;= n;i++) <br />            { <br />             current = index1+index2; <br />             index1=index2; <br />             index2= current; <br /><br />             } <br />return current; <br />}<br /></code><br /><br /><p><u>Possible solution #3 - Computational (Closed form expression)</u></p><br /><br /><p>This is simple calculation of closed form expression for Fibonacci numbers</p><br /><br /><p><img src='http://commoninterview.com/images/fibonacci_Interview_Questions_C_Sharp.png' border=\"0\" alt='Fibonacci Closed Form Equation' title='Fibonacci Closed Form Solution to Interview Question' width='350' height='49' /></p><br /><br /><code><br />static double Fibonachi(int n) <br />{ <br />   double gr = ((double)1 + Math.Sqrt(5)) / 2; <br />   double grN = Math.Pow(gr, n); <br />   double gr_1 = Math.Pow(((double)1 - gr), n); <br />   return (grN-gr_1)/Math.Sqrt(5); <br /><br />} <br /></code><br /><br /><p><strong>Problem 2.</strong> <em>Write a function which would print Fibonacci numbers up to given maximum</em></p><br /><br /><p>While, all solutions above are very easy to modify to fit this scenario it is good if you can through something extra in your answer to stand out of the crowd. So in order to do so, I would use enumerator. Certainly be prepare to discuss how yield operator works and what might resulting code look like then compiled into MSIL.</p><br /><br /><code><br />static IEnumerable Fibonacci(double maxPosition) <br />{ <br />double current = 1; <br />double previous = 0; <br />for (double i = 0;i&lt;maxPosition;i++)<br />{ <br />if (i &gt; 1) <br />{ <br />var oldCurrent = current;<br />current = current + previous; <br />previous = oldCurrent; <br />yield return current; <br />} <br />else <br />{ <br />yield return i == 0 ? previous : current; <br />}}}<br /><br /></code><br /><br />Problem 3.</strong> <em>Write a function which would check if a given number belongs to Fibonacci sequence</em></p><br /><p>The easiest way is to generate Fibonacci numbers till this number and see if this number is one of them and again it probably the answer interviewer is looking for. However there is couple over ways which might impress interviewer.</p><br /><br /><p><u>Possible solution:</u></p><br /><br /><p>It turns out that a positive integer ω is a Fibonacci number if and only if one of 5ω<sup>2</sup> + 4 and 5ω<sup>2</sup> - 4 is a perfect square [The (Fabulous) FIBONACCI Numbers by Alfred Posamentier and Ingmar Lehmann]</p><br /><br /><code><br />bool isFibonacci(int w)     <br />{ <br />double X1 = 5 * Math.Pow(w, 2) + 4; <br />double X2 = 5 * Math.Pow(w, 2) - 4; <br />long X1_sqrt = (long)Math.Sqrt(X1); <br />long X2_sqrt = (long)Math.Sqrt(X2); <br />return (X1_sqrt*X1_sqrt == X1) || (X2_sqrt*X2_sqrt == X2) ? true : false; <br />} <br /></code><br /><br /><p>As I always iterate, try to direct interview into area you know well. As I already mentioned, one approach for this particular question is to provide iterator solution and demonstarte your advance knowledge. Another is to talk about strategy pattern as this is a really good demonstration for different strategies you might want to use in different curcumstances. If you want to learn more Mathworld provides very nice overview:<a href=\"http://mathworld.wolfram.com/FibonacciNumber.html\">http://mathworld.wolfram.com/FibonacciNumber.html</a></p><br /><p> </p><br /><p><img src=\"http://commoninterview.com/images/Fibonacci_Series_Question.jpg\" border=\"0\" alt=\"Fibonacci_Series_Question.jpg\" title=\"Fibonacci_Series_Question.jpg\" width=\"600\" height=\"190\" /></p><br /><p> </p><br/><br/>4 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[Can you explain methods of storing tree structure into the DB tables?]]></title>
<link>http://commoninterview.com/Programming_Interview_Questions/can-you-explain-methods-of-storing-tree-structure-into-the-db-tables/</link>
<comments>http://commoninterview.com/Programming_Interview_Questions/can-you-explain-methods-of-storing-tree-structure-into-the-db-tables/</comments>
<pubDate>Thu, 15 Jul 2010 23:13:36 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Programming Interview Questions</category>
<guid>http://commoninterview.com/Programming_Interview_Questions/can-you-explain-methods-of-storing-tree-structure-into-the-db-tables/</guid>
<description><![CDATA[<p>Another very common variation is how to store a tree data structure in a database.</p><br /><p>Be prepared to answer this question even if you are applying for UI ,API, MT or any other non-DB related positions. The question simply tests your ability to think about data structures in the abstract way. The interviewer will usually provide some sample tree as shown in image below and ask about storing this structure in the database.</p><br /><p style='align:center'><img src='http://commoninterview.com/images/tree_structure_in_data_base_Interview_Question.png' border='0' alt='Tree structure Interview Question' title='Sample Tree' width='295' height='356' /></p><br /><p></p><br /><p>Probably the simplest way to solve this problem is to utilize the fact that the tree is a case of graph data structure, so we can use an adjacency-list approach, discussed in more details later in previous post, and just store the entire tree as one table, along with the information about adjacent nodes:</p><br /><p></p><br /><p><img src='http://commoninterview.com/images/tree_structure_in_data_base_Table.png' border='0' alt='Tree structure in Data Base' title='Tree structure in Data Base' width='516' height='235' /></p><br /><p></p><br /><p>so the DB table would look something like:</p><br /><p></p> <br /><p style='align:center' ><img src='http://commoninterview.com/images/tree_structure_in_data_base_Emploee_Table.png' border='0' alt='DB view of tree data table' title='DB view of tree data table' width='437' height='241' /></p><br /><p></p><br /><p>Adjacency list is, while the most intuitive tree model, probably the least efficient representation of all available solutions. The solution proposes to store data in a table that is denormalized in several ways and requires a recursion calls to retrieve data. This is very inefficient in SQL. However, from my experience this answer is usually well accepted during the interview, especially if candidate can point on inefficiency.</p><br /><p></p><br /><p>Another more efficient way of representing trees is to show them as nested sets (<a href='http://www.intelligententerprise.com/001020/celko.jhtml?_requestid=1266295' target='blank'>Celko, 2000</a>). In order to do so let's number all nodes in the tree according to the Modified Preorder Tree Traversal algorithm. To show a tree as nested sets, replace the nodes with ovals, then nest subordinate ovals inside each other. The root will be the largest oval and will contain every other node. The leaf nodes will be the innermost ovals with nothing else inside them and the nesting will show the hierarchical relationship.</p><br /><p>If you are slightly confused, just imagine that you are walking through this tree counter-clockwise with a pile of numbered cards from 1 to 16. Every time you visit a node for the first time, you stick a topmost card with the number from your pile into this node. Let's call it the beginning number. After you have visited all children of a particular node and are ready to leave, you stick in one more card (the end number).</p><br /><p></p><br /><p style='align:center'><img src='http://commoninterview.com/images/tree_structure_in_data_base_Alorithm.png' border='0' alt='Algorithm of walking the tree to store it in data base' title='Algorithm of walking the tree to store it in data base' width='646' height='310' /></p><br /><p></p><br /><p>So in our example, we will go to the management node first and give it the number "1" because it is our first visit to this node.</p><br /><p></p><br /><p>Then following a counter-clockwise route, we visit the Engineering node and give it number "2" because it is fist time on this node. Engineering has three child nodes, so again we are choosing the left-most child and visit "Development" node, assigning it with the card number three. This node doesn't have any children so we are leaving the node assigning number "4" because it doesn't have any children we haven't already visited. So we are back at "Engineering" node.</p><br /><p></p><br /><p>It is our second visit and it has two more nodes we have not yet visited, so we go to the next child "Test," giving it number five. We continue the trip through the tree until all nodes are numbered:</p><br /><p></p><br /><p style='align:center'><img src='http://commoninterview.com/images/tree_structure_in_data_base_Final_Table.png' border='0' alt='Final table: tree data structure in DB' title='Final table: tree data structure in DB' width='440' height='237' /></p><br /><p>The follow up questions can be to implement operations insert, update and delete for such tree.</p><br/><br/>3 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[Compute the sum of all the values in the nodes of a single linked list]]></title>
<link>http://commoninterview.com/Programming_Interview_Questions/compute-the-sum-of-all-the-values-in-the-nodes-of-a-single-linked-list-1/</link>
<comments>http://commoninterview.com/Programming_Interview_Questions/compute-the-sum-of-all-the-values-in-the-nodes-of-a-single-linked-list-1/</comments>
<pubDate>Wed, 07 Jul 2010 00:02:30 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Programming Interview Questions</category>
<guid>http://commoninterview.com/Programming_Interview_Questions/compute-the-sum-of-all-the-values-in-the-nodes-of-a-single-linked-list-1/</guid>
<description><![CDATA[<p><strong>Task:"Compute the sum of all the values in the nodes of a single linked list"</strong></p><br /><p> </p><br /><br /><p>The only thing is needed to solve this problem is linked list traversal. So we can easily modify function getLenght into following solution:</p><br /><br /><code><br />public int getSum(Node head) <br />{ <br />if (head == null) <br />return 0; <br />else return getSum(head.next) + head.value; <br />} <br /></code><br /><br /><p>Think how would you modify this function to implement search for the value in linked list. </p><br/><br/>2 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[Calculate length of the linked list]]></title>
<link>http://commoninterview.com/Programming_Interview_Questions/calculate-length-of-the-linked-list/</link>
<comments>http://commoninterview.com/Programming_Interview_Questions/calculate-length-of-the-linked-list/</comments>
<pubDate>Tue, 06 Jul 2010 23:58:18 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Programming Interview Questions</category>
<guid>http://commoninterview.com/Programming_Interview_Questions/calculate-length-of-the-linked-list/</guid>
<description><![CDATA[This problem can be easily solved by using simple recursion and again creates a basis for solving subset of related coding problems.<br /><br /><br /><span style=\\"text-decoration: underline;\\">Possible solution:</span><br /><br /><code>public int getLength(Node head) <br />{<br /><br />if (head == null)<br />return 0;<br />else <br />return length(head.next) + 1;<br /><br />}</code><br/><br/>3 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[Reverse a Singly Linked List]]></title>
<link>http://commoninterview.com/Programming_Interview_Questions/reverse-a-singly-linked-list/</link>
<comments>http://commoninterview.com/Programming_Interview_Questions/reverse-a-singly-linked-list/</comments>
<pubDate>Tue, 06 Jul 2010 23:53:49 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Programming Interview Questions</category>
<guid>http://commoninterview.com/Programming_Interview_Questions/reverse-a-singly-linked-list/</guid>
<description><![CDATA[<p>You are asked to write a function Node Reverse(Node head) which has a pointer to the head element of the linked list as a parameter and need to reverse the list and return pointer to the new head element:</p><br /><p> </p><br /><img src='http://commoninterview.com/images/Reverse_Linked_List_Interview_Question.jpg' border='0' alt='Reverse_Linked_List_Interview_Question' title='Reverse_Linked_List_Interview_Question' width='448' height='162' /><br /><p> </p><br /><p>This is classical interview question which surprisingly is unexpected by many candidates . This is also a basis problem and understanding solution will help you to solve number of linked list problems.</p><br /><p>The key to understand in this problem is that the only thing needed just changing direction of a pointer as in opposing to an array data structure we don't need to worry about sequential location of elements in memory.</p><br /><p> </p><br /><p><span style=\\"text-decoration: underline;\\">Possible Solution:</span></p><br /><br /><code><br />public Node Reverse(Node head)    <br />{<br />        Node next;<br />        Node current;<br />        current = head;<br />        Node Result = null;<br />        while (current != null) <br />          {  <br />             next = current.next;  <br />              current.next = result; <br />              result = current; <br />              current = next; <br />          }        <br />               return (result);    <br />} <br /></code><br/><br/>5 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[What are the advantages and disadvantages of linked list structure vs. arrays?]]></title>
<link>http://commoninterview.com/Programming_Interview_Questions/what-are-the-advantages-and-disadvantages-of-linked-list-structure-vs-arrays/</link>
<comments>http://commoninterview.com/Programming_Interview_Questions/what-are-the-advantages-and-disadvantages-of-linked-list-structure-vs-arrays/</comments>
<pubDate>Tue, 06 Jul 2010 23:53:09 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Programming Interview Questions</category>
<guid>http://commoninterview.com/Programming_Interview_Questions/what-are-the-advantages-and-disadvantages-of-linked-list-structure-vs-arrays/</guid>
<description><![CDATA[<p>Linked lists allow only sequential access to elements O(n) while arrays allow random access O(1). Linked lists requires an extra storage for references, which often makes them impractical for lists of small data items such as characters or Boolean values.</p><br /><p>&nbsp;</p><br /><p>From the over side, size of array is restricted to declaration. Insertion/Deletion of values in arrays are very expensive comparing to linked list and requires memory reallocation. Elements can be inserted into linked lists indefinitely, while an array will eventually.</p><br/><br/>2 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[What is the difference between array and linked list ?]]></title>
<link>http://commoninterview.com/Programming_Interview_Questions/what-is-the-difference-between-array-and-linked-list-/</link>
<comments>http://commoninterview.com/Programming_Interview_Questions/what-is-the-difference-between-array-and-linked-list-/</comments>
<pubDate>Tue, 06 Jul 2010 23:50:56 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Programming Interview Questions</category>
<guid>http://commoninterview.com/Programming_Interview_Questions/what-is-the-difference-between-array-and-linked-list-/</guid>
<description><![CDATA[<p>The main difference between the linked list and the array is that while the array is a static data structure (with fix number of elements). On the other hand the linked list - dynamic data structure. <br /><br />In terms of complexity, the linked list is usually more efficient as to the space it uses, however, algorithms for linked lists are usually more complicated that those of the array. </p><br /><br /><br /><p>Array vs. Linked List representation in memory:</p><br /><p> </p><br /><p> </p><br/><br/>3 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[What is Linked List?]]></title>
<link>http://commoninterview.com/Programming_Interview_Questions/what-is-linked-list/</link>
<comments>http://commoninterview.com/Programming_Interview_Questions/what-is-linked-list/</comments>
<pubDate>Tue, 06 Jul 2010 23:42:22 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Programming Interview Questions</category>
<guid>http://commoninterview.com/Programming_Interview_Questions/what-is-linked-list/</guid>
<description><![CDATA[<p>Linked list is a linear collection of Self-Referential class objects, called nodes, connected by reference links. Many people tend to think of it as of dynamically sized array but you need to understand difference between these two data structures.</p><br /><p> </p><br /><p>Notice three things about the list:</p><br /><br />• The pointer at the end of the list is null. <br />• Each node's next pointer points to another unique node in the list or to Null, making the list a linear graph. <br />• The first node of the list is pointed to by a pointer called head.<br /><br /><p>The most common and the simplest kind of linked list is a singly-linked list. A singly-linked list containing two values: the value of the current node and a link to the next node.</p><br /><br /><p style='text-align: center;'><br /><img src='http://commoninterview.com/images/Single_Linked_List.jpg' border='0' alt='Double-Linked-List' title='Double-Linked-List' width='547' height='96'><br /></p><br /><br />A little more complex type of linked list is a doubly-linked list. In doubly-linked list each node has two links: one points to the previous node, (or a null value if it is the first node); and one points to the next (or a null value if it is the final node)<br /><br /><p style='text-align: center;'><br /><img src='http://commoninterview.com/images/Double-Linked-List.jpg' border='0' alt='Double-Linked-List' title='Double-Linked-List' width='547' height='96' /></p><br /><br /><p>Both single and double linked list can form a circularly-linked list. In a circularly-linked list, the first and final nodes are linked together. To traverse a circular linked list, you begin at any node and follow the list in either direction until you return to the original node. If instead of pointing to the first node or to null final node points to any other element in the list, the list called list with a loop.</p><br /><p> </p><br /><br/><br/>4 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[What is the difference between struct and class in .NET?]]></title>
<link>http://commoninterview.com/Programming_Interview_Questions/what-is-the-difference-between-struct-and-class-in-net-1/</link>
<comments>http://commoninterview.com/Programming_Interview_Questions/what-is-the-difference-between-struct-and-class-in-net-1/</comments>
<pubDate>Thu, 01 Jul 2010 00:22:35 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Programming Interview Questions</category>
<guid>http://commoninterview.com/Programming_Interview_Questions/what-is-the-difference-between-struct-and-class-in-net-1/</guid>
<description><![CDATA[This is one of the most common interview questions and the key difference is that <strong>struct is value type and class is reference type</strong>.  <br /><br />Also, there is no inheritance for structs as there is for classes. A struct cannot inherit from another struct or class, and it cannot be the base of a class. Struct itself, however, inherit from the base class <strong>Object</strong>. A struct can implement interfaces, and it does that exactly as classes do.</p><br /><br /><p>The general recommendation is to use structs for objects less than 64KB and classes for objects above that.</p><br /><br /><p>If you look deeper into .NET by using Reflector you can compare how struct and class are being compiled  into   MSIL.</p><br /><br /><p>Let's say we declared one class ClassTest and one struct StructTest</p><br /><br /><code><br />public class ClassTest<br />{<br />public object Data;<br />}<br /></code><br /><br />and<br /><br /><code><br />public struct StructTest<br />{<br />public object Data;<br />}<br /></code><br /><br /><p>Internally .NET would compile them into very similar code:</p><br /><br /><code><br />.class auto ansi nested public beforefieldinit ClassTest <br />        extends [mscorlib]System.Object <br />{ <br />  .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { } <br /><br />.field public object Data // data field<br /><br />}<br /></code><br /><br /><br />and for struct<br /><br /><code><br />.class sequential ansi sealed nested public beforefieldinit StructTest <br />extends [mscorlib]System.ValueType <br />{ <br />.field public object Data // data field<br /> <br />}<br /></code><br /><br /><br /><p>Looking on the difference you see that class is converted into MSIL .class which has default constructor and inherit directly from Object while struct get converted into .class which doesn't have a constructor and inherit from System.ValueType.<br /><br /></p><br /><p><span style='text-decoration: underline;'>There are also .class declaration difference:</span></p><br /><br /><p>'<strong>sealed</strong>'  - on the struct which prevent derivation from a struct.</p><br /><br /><p>'<strong>sequential</strong>' - means that the date  is represented in memory in the same order as you declared it i.e. is you have multiple field inside your struct they will be placed in memory in the same order you declared it.</p><br /><br /><p>'<strong>auto</strong>' - in opposite to the 'sequential' keyword 'auto' means that the layout of the class in memory will be decided by the runtime not your declaration.</p><br /><br/><br/>4 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[What is DSAT?]]></title>
<link>http://commoninterview.com/Testing_Interview_Questions/what-is-dsat/</link>
<comments>http://commoninterview.com/Testing_Interview_Questions/what-is-dsat/</comments>
<pubDate>Mon, 21 Jun 2010 02:40:15 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Testing and QA Interview Questions</category>
<guid>http://commoninterview.com/Testing_Interview_Questions/what-is-dsat/</guid>
<description><![CDATA[<p>As with many acronyms DSAT can mean multiple things depending on context. But in testing it offten stands for "DisSATisfaction".&nbsp;</p><br /><p>&nbsp;</p><br /><p>In that meaning DSATs are special types of bugs which are causing users dissatisfaction but not system malfunction.</p><br /><p>&nbsp;</p><br /><p>Examples include poor user experience, slow server responce, low quality of content, etc.</p><br/><br/>3 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[Self defining number]]></title>
<link>http://commoninterview.com/interview_puzzles/self-defining-number/</link>
<comments>http://commoninterview.com/interview_puzzles/self-defining-number/</comments>
<pubDate>Sun, 20 Jun 2010 02:45:44 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Interview Puzzles</category>
<guid>http://commoninterview.com/interview_puzzles/self-defining-number/</guid>
<description><![CDATA[<p>Write a function or find a logical way of finding a number X<sub>1</sub>X<sub>2</sub>X<sub>3</sub>... such that</p><br /><p>X<sub>1</sub> is the amount of zerror's in the number</p><br /><p>X<sub>2</sub> is the amount of one's</p><br /><p>X<sub>3</sub> is the amount of two's</p><br /><p>and so on</p><br /><br />Task is to:<br /><br />1. Finind smallest number<br />2. Find largest integer number<br />3. Find an algorithm and print all numbers...<br/><br/>7 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[Mixing drinks Interview puzzle]]></title>
<link>http://commoninterview.com/interview_puzzles/mixing-drinks-interview-puzzle/</link>
<comments>http://commoninterview.com/interview_puzzles/mixing-drinks-interview-puzzle/</comments>
<pubDate>Sun, 20 Jun 2010 02:39:17 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Interview Puzzles</category>
<guid>http://commoninterview.com/interview_puzzles/mixing-drinks-interview-puzzle/</guid>
<description><![CDATA[<p>Assume you have a cup of soda and a cup of water. You take one tablespoon of the soda and mix it in with the water. Then you one tablespoon of this mixture and mix it back in with the soda. <br /><br />You repeat the mixing k times.</p><br /><br /><p>Which of the two cups contains more of its original contents? Soda or water?<br/><br/>5 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[Rectangular array of people ]]></title>
<link>http://commoninterview.com/interview_puzzles/rectangular-array-of-people-/</link>
<comments>http://commoninterview.com/interview_puzzles/rectangular-array-of-people-/</comments>
<pubDate>Sun, 20 Jun 2010 02:35:24 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Interview Puzzles</category>
<guid>http://commoninterview.com/interview_puzzles/rectangular-array-of-people-/</guid>
<description><![CDATA[In a rectangular array of people, which will be taller, the tallest of the shortest people in each column, or the shortest of the tallest people in each row?<br /><br />Read more: <br /><br />http://www.faqs.org/faqs/puzzles/archive/logic/part1/#ixzz0rNeKrOox<br/><br/>4 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[Hotel room for three (logical puzzle)]]></title>
<link>http://commoninterview.com/interview_puzzles/hotel-room-for-three-logical-puzzle/</link>
<comments>http://commoninterview.com/interview_puzzles/hotel-room-for-three-logical-puzzle/</comments>
<pubDate>Sun, 20 Jun 2010 02:18:09 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Interview Puzzles</category>
<guid>http://commoninterview.com/interview_puzzles/hotel-room-for-three-logical-puzzle/</guid>
<description><![CDATA[<p>Three people check into a hotel. They pay $30 to the manager and go to their room. The manager finds out that the room rate is $25 and gives $5 to the bellboy to return.</p><br /><br /><p>On the way to the room the bellboy reasons that $5 would be difficult to share among three people so he pockets $2 and gives $1 to each person. Now each person paid $10 and got back $1. So they paid $9 each, totalling $27. The bellboy has $2, totalling $29. Where is the remaining dollar?<br /><br /><br />Read more: <br /><br />http://www.faqs.org/faqs/puzzles/archive/logic/part1/#ixzz0rNcRC5Ve<br/><br/>5 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[The Music Stops and Young Lady Dies]]></title>
<link>http://commoninterview.com/interview_puzzles/the-music-stops-and-young-lady-dies-1/</link>
<comments>http://commoninterview.com/interview_puzzles/the-music-stops-and-young-lady-dies-1/</comments>
<pubDate>Fri, 18 Jun 2010 09:01:26 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Interview Puzzles</category>
<guid>http://commoninterview.com/interview_puzzles/the-music-stops-and-young-lady-dies-1/</guid>
<description><![CDATA[<p>The music stops and woman dies, so what happend? This is latteral thinking puzzle, so there are many possivle answers.</p><br/><br/>1 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[Who is DRI?]]></title>
<link>http://commoninterview.com/technical_questions/who-is-dri/</link>
<comments>http://commoninterview.com/technical_questions/who-is-dri/</comments>
<pubDate>Thu, 10 Jun 2010 21:28:31 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Technical Questions</category>
<guid>http://commoninterview.com/technical_questions/who-is-dri/</guid>
<description><![CDATA[Supposely originated in Amazon in early 2000, D.R.I stands for Developer Responsible for Inverstigation. DRI is usualy member of software development team who is a contact point for member services or customer support escolations.<br /><br /><p>The team members usually rotates as daily/weekly/monthly DRIs.</p><br /><p> </p><br/><br/>1 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[Write the method void Clean(Node root) which would clean Nodes but don’t use the recursion ]]></title>
<link>http://commoninterview.com/Programming_Interview_Questions/write-the-method-void-cleannode-root-which-would-clean-nodes-but-don’t-use-the-recursion-/</link>
<comments>http://commoninterview.com/Programming_Interview_Questions/write-the-method-void-cleannode-root-which-would-clean-nodes-but-don’t-use-the-recursion-/</comments>
<pubDate>Thu, 03 Jun 2010 22:48:15 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Programming Interview Questions</category>
<guid>http://commoninterview.com/Programming_Interview_Questions/write-the-method-void-cleannode-root-which-would-clean-nodes-but-don’t-use-the-recursion-/</guid>
<description><![CDATA[<p>The solution is to use an additional data structure such as Stack to maintain a list of unprocessed nodes, keep adding children to the stack, and then the parent is processed. As you can see, any other collection can be used such as List or an Array, but you would need to do some additional work for adding and removing elements from the collection.</p><br /><code>void Clean(Node root) <br />{ <br />if (root != null) <br />{ <br />Stack stack = new Stack(); <br />stack.Push(root); <br />while (stack.Count > 0) <br />{<br /> Node current = stack.Pop(); <br /> current.Data = string.Empty; <br /> foreach (Node children in current.Children) <br />        stack.Push(children); <br />} <br />} <br />} <br /></code><br /><span style=\"text-decoration: underline;\">You might expect next follow up questions:</span></p><br /><p>What is Stack?How is Stack different from Queue?Would it make a difference if we use Queue in the example above?</p><br/><br/>2 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[Write the method void Clean (Node root), which will go through all of the nodes starting with passed node, and sets string member ‘Data’ to an empty string. ]]></title>
<link>http://commoninterview.com/Programming_Interview_Questions/write-the-method-void-clean-node-root-which-will-go-through-all-of-the-nodes-starting-with-passed-node-and-sets-string-member-‘data’-to-an-empty-string-/</link>
<comments>http://commoninterview.com/Programming_Interview_Questions/write-the-method-void-clean-node-root-which-will-go-through-all-of-the-nodes-starting-with-passed-node-and-sets-string-member-‘data’-to-an-empty-string-/</comments>
<pubDate>Thu, 03 Jun 2010 22:43:21 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Programming Interview Questions</category>
<guid>http://commoninterview.com/Programming_Interview_Questions/write-the-method-void-clean-node-root-which-will-go-through-all-of-the-nodes-starting-with-passed-node-and-sets-string-member-‘data’-to-an-empty-string-/</guid>
<description><![CDATA[<p>The solution uses recursion to clean data on the passed node first and then recursively walks through all children. There are a couple of important moments to note. First, don't forget to check for null on the passed parameter. Another approach would be throwing an ArgumentException if root is null.</p><br /><br /><p>Note that String.Empty is used instead of double quotes. Many people fail to discuss the difference between those two.  The main difference is that String.Empty will not create any objects, while "" will create a new instance of string object in memory. So, always use String.Empty for the ultimately in memory efficiency.</p><br /><br /><code><br />public void Clean(Node root) <br />{ <br />if (root != null) <br />   { <br />      root.Data = string.Empty; <br />      foreach (Node child in root.Children) Clean(child); <br />   } <br />} </code><br /><br /><u>Be prepare to answer following questions</u>:<br /><br />What is the execution time for this algorithm in bigO notation?How does recursion work internally?<br />Is this a BFS or DFS algorithm?</p><br/><br/>1 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[Please write the class definition for the n-tree data structure with each node containing string storage for data]]></title>
<link>http://commoninterview.com/Programming_Interview_Questions/please-write-the-class-definition-for-the-n-tree-data-structure-with-each-node-containing-string-storage-for-data/</link>
<comments>http://commoninterview.com/Programming_Interview_Questions/please-write-the-class-definition-for-the-n-tree-data-structure-with-each-node-containing-string-storage-for-data/</comments>
<pubDate>Thu, 03 Jun 2010 22:32:41 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Programming Interview Questions</category>
<guid>http://commoninterview.com/Programming_Interview_Questions/please-write-the-class-definition-for-the-n-tree-data-structure-with-each-node-containing-string-storage-for-data/</guid>
<description><![CDATA[<p>The idea is simple-we are using recursion declaration. The task specifies an unlimited number of children, so we are using collection of nodes along with string-to-store additional information about each node.</p><br /><br /><p>There are number of possible solutions:</p><br /><br /><p>By using class and array:</p><br /><br /><code><br />class Node <br />{ <br />public Node[] Children; <br />public string Data; <br />} <br /></code><br /><br /><p>By using struct and array:</p><br /><br /><code><br />struct Node <br />{ <br />Node[] Children; <br />string Data; <br />}<br /></code><br /><br /><p>By using class and generic List</p><br /><br /><code><br />class Node <br />{ <br />public List Children&lt;Node&gt;; <br />public string Data; <br />} <br /></code><br /><br /><strong>Hint:</strong> For C# if an access modifier is not specified for a member variable, it has a default access level of private in a class or public in a structure. Pointing this out during the interview process will underline your knowledge and your attention to details.<br /><br /><p><u>Think about this questions interviewer might ask:</u> </p><br /><br />What are the difference between class and struct ?<br />What is the difference between list and array [], and what would be your best choice?<br />How would you modify this code for a binary tree case?<br />How would you modify this code to use the generic type instead of string?<br/><br/>3 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[What is a tree data structure? What is binary tree?]]></title>
<link>http://commoninterview.com/technical_questions/what-is-a-tree-data-structure-what-is-binary-tree/</link>
<comments>http://commoninterview.com/technical_questions/what-is-a-tree-data-structure-what-is-binary-tree/</comments>
<pubDate>Thu, 03 Jun 2010 22:29:50 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Technical Questions</category>
<guid>http://commoninterview.com/technical_questions/what-is-a-tree-data-structure-what-is-binary-tree/</guid>
<description><![CDATA[<p>In general a tree data strucuture is a widely-used data structure that allows storing hierarchical data via a set of linked nodes. Each node in a tree has zero or more child nodes. A node that has a child is called the child's parent node (ancestor node). Nodes with no children are called leaf nodes. Siblings are nodes that share the same parent node.</p><br /><p>&nbsp;</p><br /><p>As&nbsp;the simple case of a graph&mdash;a tree data structure is a connected graph containing no cycles&mdash;the tree is very suited for an interview question, as it allows the creation of problems that are small and can be coded within less than 10-15 lines, but the solutions are not obvious and require good problem-solving&nbsp; abilities. Probably the most common questions are related to the binary tree.&nbsp; A binary tree is a special kind of tree, one in which all nodes have at most two children. For a given node in a binary tree, the first child is referred to as the left child, while the second child is referred to as the right child.</p><br/><br/>1 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[Write a function to reverse string in C#]]></title>
<link>http://commoninterview.com/Programming_Interview_Questions/write-a-function-to-reverse-string-in-c/</link>
<comments>http://commoninterview.com/Programming_Interview_Questions/write-a-function-to-reverse-string-in-c/</comments>
<pubDate>Fri, 07 May 2010 18:02:07 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Programming Interview Questions</category>
<guid>http://commoninterview.com/Programming_Interview_Questions/write-a-function-to-reverse-string-in-c/</guid>
<description><![CDATA[<b>Answer</b><br /><br />Simplest way to approach reverse string problems is to treat string as an array of characters and switch chars one by one. <br /><br />Solution in C# which yields O(n) execution time.<br /><br />static public string Reverse(string str)<br />{<br />char[] charArray = str.ToCharArray();<br />int len = str.Length - 1;<br /><br />for (int i = 0; i < len; i++, len--)<br />{<br />  charArray[i] ^= charArray[len];<br />  charArray[len] ^= charArray[i];<br />  charArray[i] ^= charArray[len];<br />}<br /><br />return new string(charArray);<br /><br />}<br /><br/><br/>3 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[What is Dynamic CSS?]]></title>
<link>http://commoninterview.com/Programming_Interview_Questions/what-is-dynamic-css-1/</link>
<comments>http://commoninterview.com/Programming_Interview_Questions/what-is-dynamic-css-1/</comments>
<pubDate>Mon, 19 Apr 2010 02:32:04 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Programming Interview Questions</category>
<guid>http://commoninterview.com/Programming_Interview_Questions/what-is-dynamic-css-1/</guid>
<description><![CDATA[Traditionally CSS (Cascading Style Sheets) are static files with .css extension linked to your web pages by using "link" meta tags inside header section of the page.<br /><br /><code><br />&lt;link rel="stylesheet" href="my.css" type="text/css"/&gt;<br /></code><br /><br />However, in many cases (especially for enterprise level applications) it makes sense to dynamically generate CSS code instead of producing huge amount of static files.<br /><br /><u>Just few benefits of dynamic or programmatic CSS (DCSS):</u><br /><br />-	CSS constants and conditional logic<br />-	On demand user based calculations<br />-	Encapsulated logic for styles<br />-	Easy to maintain and support<br />-	CSS size (don't need to load stuff you don't need)<br />-	UI flexibility (easy to style pages for multiple scenarios)<br />-	Scalability<br />-	And many more …<br /><br />CSS lives on the page and applied to the elements during rendering time on the client by the browser. Thus there are two options: server side and client side. You can write CSS generation logic by yourself of use one of hundreds available libraries. <br /><br />Depending on the technology of your choice such as PHP, ASP.NET, Java or others you can use server side code to generate CSS along with your dynamic page or part of the page in case of AJAX request.  Simple ASP.NET example would be using generic handler to serve CSS resources (note href value):<br /><br /><code><br />&lt;link rel="stylesheet" href="mydynamicCss.ashx?cssCode=mainPage" type="text/css"/&gt;<br /></code><br /><br />In this case, server side handler would generate css and serve it back to the client. Note: page rendering will be blocked.<br /><br />Another option is to use client side JavaScript to generate CSS classes for example on page load (see CSSJS library). <br /><br />Both approaches have benefits and drawbacks thus should be used according to particular application requirements. <br /><br />Dynamic CSS for PHP: http://www.coolphptools.com/dynamic_css <br />Dynamic CSS Styling in ASP.NET:  http://www.codeproject.com/KB/aspnet/ASPNET_Dynamic_Styling.aspx <br />CSSJS:  http://revnode.com/oss/css/<br />JQuery: http://jquery.com <br /><br/><br/>4 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[Can you write a code to make pure CSS slideshow out of list of images?]]></title>
<link>http://commoninterview.com/technical_questions/can-you-write-a-code-to-make-pure-css-slideshow-out-of-list-of-images/</link>
<comments>http://commoninterview.com/technical_questions/can-you-write-a-code-to-make-pure-css-slideshow-out-of-list-of-images/</comments>
<pubDate>Sun, 18 Apr 2010 21:14:13 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Technical Questions</category>
<guid>http://commoninterview.com/technical_questions/can-you-write-a-code-to-make-pure-css-slideshow-out-of-list-of-images/</guid>
<description><![CDATA[Interviewer testing client side basics. During the interview the main objective is to show your knowledge, creative thinking and expertise. <br /><br />This question is a great discussion point around CSS, cross-browser compatibility and proper UI design. <br /><br />In general Cascading Style Sheets (CSS) is a way of defining styles on the web elements (e.g. colors, fonts, sizes, margins, puddings, etc). CSS is not a programming language and cannot be used to write code such as event handlers, etc. However such feature as DHTML behaviors can be used inside CSS to encapsulate specific functionality or behavior on a page. <br /><br />According to MSDN Behaviors Provide a Means for Script Encapsulation and Code Reuse and can be used to add interactive functionality with a simple declarative syntax. This feature *can* be used to design and develop simple CSS slideshow. <br /><br /><u>General benefits of using behaviors:</u> <br /><br />1. Script Encapsulation and Code Reuse <br />2. Declarative Syntax <br />3. Script Isolation from Content <br />4. Easy-to-Create <br /><br /><u>Drawbacks of using behaviors:</u> <br /><br />1. Accessibility issues <br />2. Maintainability issues <br />3. Only supported by Internet Explorer <br />4. Non-standard (see above) <br /><br />While there is a possibility to design and code simple CSS slideshow with hardcoded images by using behaviors I would never recommend doing this. This is great point to elaborate on scalability, x-browser, maintainability, ect. <br /><br />What to use ? Use JavaScript and HTML instead. <br /><br />The right approach would be to use HTML + CSS to design look and feel of the elements and JavaScript to load images for slideshow and for scrolling between images. <br /><br />For example we can use JQuery JavaScript library to manipulate images and take benefits of the animation and effects components it provides. <br /><br />Here is step-by-step instructions on making slideshow with jQuery and CSS: <br />http://tutorialzine.com/2010/03/mosaic-slideshow-jquery-css/<br /><br/><br/>4 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[Tell us about your most difficult sales experience.]]></title>
<link>http://commoninterview.com/general_questions/tell-us-about-your-most-difficult-sales-experience-/</link>
<comments>http://commoninterview.com/general_questions/tell-us-about-your-most-difficult-sales-experience-/</comments>
<pubDate>Thu, 15 Apr 2010 22:04:21 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>General Questions</category>
<guid>http://commoninterview.com/general_questions/tell-us-about-your-most-difficult-sales-experience-/</guid>
<description><![CDATA[Tell us about your most difficult sales experience.<br /><br /><b>Strategy Statement: </b><br /><br />Whenever possible, turn these questions into ‘positives'. For this particular question, the work might have been difficult, but the results should be positive.<br /><br /><b>Sample Response:</b><br /><br />My most difficult experience was only made that way because of the amount of work I put into preparing for the experience. There was a new and innovative business that had established itself. <br /><br />I personally loved the products and services that the owners were bringing to our community, and I wanted to see their business take deep roots and succeed. I determined that there were two things working against the business... the fact that they were new and innovative and that the owners were from out-of-state. When I first approached the business owners, it was without a file in my hand. I introduced myself, first, as a resident who was genuinely interested in making sure their business succeeded (as they were offering a product/service that I saw as beneficial to our community). <br /><br />I then mentioned that I wanted to learn more about their vision (and what they saw as the big picture). After a solid half-hour conversation, I told the owners of my other motive/agenda, and that I might be able to assist them in coming up with a strategy that addressed both the community's understanding of what it was they were doing as well as that community's getting to know the owners better. As a result, the owners established a monthly workshop and presentation series where they were able to explain and teach about their service, and they also established a connection with the area's community foundation (to which they became very active as advocates and donors). <br /><br />I don't believe I made a dime from my work, but the business is still in existence (and thriving), and our community has benefitted greatly.<br /><br />Copyright  2010. North Pacific Technology Group LLC. All rights reserved.<br /><br/><br/>3 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[How would you create css tooltip in html document ?]]></title>
<link>http://commoninterview.com/technical_questions/how-would-you-create-css-tooltip-in-html-document--1/</link>
<comments>http://commoninterview.com/technical_questions/how-would-you-create-css-tooltip-in-html-document--1/</comments>
<pubDate>Wed, 14 Apr 2010 12:28:07 -0600</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Technical Questions</category>
<guid>http://commoninterview.com/technical_questions/how-would-you-create-css-tooltip-in-html-document--1/</guid>
<description><![CDATA[<b> Answer :</b><br /><br />The interviewer is testing your front-end skills with the simple task of developing CSS tooltip. <br /><br /><u>Key things to remember and mention:</u><br /><br />1. Cross-browser compatibility (issues with IE6, Text browsers, etc.)<br />2. CSS W3C compliant code<br />3. High level execution (don't go into the details).<br />4. Available libraries such as JQuery<br /><br /><u>Sample pure CSS tooltip code :</u><br /><br /><code class='background-color:#D1D1D1; border:1px solid;'><br />a:hover {text-decoration:none;background-color:white;} <br /><br />a.CSSToolTip div {display:none; width:180px; height:40px;  background-color:#DDDDDD; padding:5px; margin:5px; }<br /><br />a.CSSToolTip:hover div {display:inline; position:absolute; background:white; border:1px solid #1E1E1E; color:#1C1C1C;}<br /></code><br /><br /><b>Usage</b>(note div element inside an anchor tag):<br /><br />&lt;a class='CSSToolTip' href='javascript:void(0)'&gt;Hover me to see css tooltip&lt;div&gt;CommonInterview  sample tooltip.&lt;/div&gt;&lt;/a&gt;<br /><br /><br /><b> JQUERY </b><br /><br />It is worth mentioning during the interview that JQuery provide a powerful  tooltip plug-in which can be fully customized and attached to any DOM element:<br /><br />$(selector).tooltip();<br /><br />This would show your knowledge of a library and the ability to choose right solution depending on the situation.<br /><br />Plugin demo page: http://jquery.bassistance.de/tooltip/demo/<br /><br /><br/><br/>3 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[How to sort dictionary by value using LINQ?]]></title>
<link>http://commoninterview.com/Programming_Interview_Questions/how-to-sort-dictionary-by-value-using-linq-1/</link>
<comments>http://commoninterview.com/Programming_Interview_Questions/how-to-sort-dictionary-by-value-using-linq-1/</comments>
<pubDate>Tue, 02 Mar 2010 13:24:29 -0700</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Programming Interview Questions</category>
<guid>http://commoninterview.com/Programming_Interview_Questions/how-to-sort-dictionary-by-value-using-linq-1/</guid>
<description><![CDATA[This question is really popular one.<br /><br />Answer:<br /><br /><code><br />var _keysCollections = (from item in oldDictionary orderby item.Value descending select item.Key); <br /></code><br/><br/>2 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[Coins in the box]]></title>
<link>http://commoninterview.com/interview_puzzles/coins-in-the-box/</link>
<comments>http://commoninterview.com/interview_puzzles/coins-in-the-box/</comments>
<pubDate>Fri, 26 Feb 2010 21:38:14 -0700</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Interview Puzzles</category>
<guid>http://commoninterview.com/interview_puzzles/coins-in-the-box/</guid>
<description><![CDATA[You are given a box 2 inches by 1000 inches in size, and an unlimited supply of coins. Each coin is exactly one inch in diameter.<br /> <br />How many coins can you place flat in the bottom of the box without overlapping? <br /><br />Hint: answer is more than 2000<br /> <br /><br/><br/>6 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[Pair Programming Exercise: Write a command line calculator]]></title>
<link>http://commoninterview.com/Programming_Interview_Questions/pair-programming-exercise-write-a-command-line-calculator-1/</link>
<comments>http://commoninterview.com/Programming_Interview_Questions/pair-programming-exercise-write-a-command-line-calculator-1/</comments>
<pubDate>Wed, 24 Feb 2010 01:14:32 -0700</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Programming Interview Questions</category>
<guid>http://commoninterview.com/Programming_Interview_Questions/pair-programming-exercise-write-a-command-line-calculator-1/</guid>
<description><![CDATA[The task was to write a command line calculator using TDD and pairing with one of the junior team members while observer was waching the interaction and code development. The requirements to the task was to have calculator which can perform simple arithmetic operation such as +,-,*,/ parethises were optional if the time permits.<br /><br />Task wasn't hard, the key idea was to execute proper TDD and keep the interaction with pair going.<br/><br/>3 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[What are the advantages of ASP.NET MVC? ]]></title>
<link>http://commoninterview.com/Programming_Interview_Questions/what-are-the-advantages-of-asp-net-mvc-/</link>
<comments>http://commoninterview.com/Programming_Interview_Questions/what-are-the-advantages-of-asp-net-mvc-/</comments>
<pubDate>Wed, 24 Feb 2010 01:11:34 -0700</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Programming Interview Questions</category>
<guid>http://commoninterview.com/Programming_Interview_Questions/what-are-the-advantages-of-asp-net-mvc-/</guid>
<description><![CDATA[<b> Answer </b><br /><br />• Provides complete control over your HTML markup<br />• Enables rich AJAX integration<br />• Intuitive website URLs<br />• Clear separation of concerns which results in web applications that are easier to maintain and extend over time.<br />• Testability - including support for test-driven development. <br /><br/><br/>2 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[How would you sort a linked list? ]]></title>
<link>http://commoninterview.com/Programming_Interview_Questions/how-would-you-sort-a-linked-list-/</link>
<comments>http://commoninterview.com/Programming_Interview_Questions/how-would-you-sort-a-linked-list-/</comments>
<pubDate>Mon, 22 Feb 2010 20:07:31 -0700</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Programming Interview Questions</category>
<guid>http://commoninterview.com/Programming_Interview_Questions/how-would-you-sort-a-linked-list-/</guid>
<description><![CDATA[<b>Answer</b><br /><br />The idea is to choose sorting algorithm, as usually QuickSort and then think about swaping strategy.<br /><br />Consider following situation:<br /><br />1. The nodes being compared are not adjacent and one of them is the first node.<br />2. The nodes being compared are not adjacent and none of them is the first node<br />3. The nodes being compared are adjacent and one of them is the first node.<br />4. The nodes being compared are adjacent and none of them is the first node.<br /><br />Another good stratery is merge sort as it is easy to merge sorted linked lists.<br /><br /><code><br />void LinkedListMergeSort(struct node** headRef) <br />{<br />  struct node* head = *headRef;<br />  struct node* a;<br />  struct node* b;<br /><br />  if ((head == NULL) || (head->next == NULL))  return;<br />  <br />  splitLLInto2(head, &a, &b); <br /><br />  LinkedListMergeSort(&a); <br />  LinkedListMergeSort(&b);<br /><br />  *headRef = merge2SortedLLs(a, b); <br />}<br /></code><br /><br />Number of alternative solutions with C++ code<br /><a href='http://profile.iiita.ac.in/pkmallick_03/pages/0_2.html'>are here</a><br/><br/>4 Vote(s) ]]></description>
</item>

<item>
<title><![CDATA[knight's tour]]></title>
<link>http://commoninterview.com/interview_puzzles/knights-tour/</link>
<comments>http://commoninterview.com/interview_puzzles/knights-tour/</comments>
<pubDate>Sat, 20 Feb 2010 02:18:38 -0700</pubDate>
<dc:creator>aleksin</dc:creator>
<category>Interview Puzzles</category>
<guid>http://commoninterview.com/interview_puzzles/knights-tour/</guid>
<description><![CDATA[On an empty NxN chessboard, a knight starts from a point (say location x, y) and it starts moving randomly, but once it moves out of board, it can't come inside.<br /> <br />(1) What is the total probability that it stays within the board after N steps?<br /><br />(2) What is the expected number of steps before it steps out?<br/><br/>4 Vote(s) ]]></description>
</item>

</channel>
</rss>

