Wednesday, August 3, 2011

Data structure interview question Series 3


18.What is the bucket size, when the overlapping and collision occur at same time?
Answer:One. If there is only one entry possible in the bucket, when the collision occurs, there is no way to accommodate the colliding value. This results in the overlapping of values.

19. Traverse the given tree using Inorder, Preorder and Postorder traversals.
Answer:
Ø Inorder : D H B E A F C I G J
Ø Preorder: A B D H E C F G I J
Ø Postorder: H D E B F I J G C A

20. There are 8, 15, 13, 14 nodes were there in 4 different trees. Which of them could have formed a full binary tree?
Answer:15.
In general:
There are 2n-1 nodes in a full binary tree.
By the method of elimination:
Full binary trees contain odd number of nodes. So there cannot be full binary trees with 8 or 14 nodes, so rejected. With 13 nodes you can form a complete binary tree but not a full binary tree. So the correct answer is 15.
Note:
Full and Complete binary trees are different. All full binary trees are complete binary trees but not vice versa.

21. In the given binary tree, using array you can store the node 4 at which location?
Answer:Left: 2i
Right:2i+1
i=location
At location 6











123--4--5











RootLC1RC1LC2RC2LC3RC3LC4RC4



where LCn means Left Child of node n and RCn means Right Child of node n.

Data structure interview question Series 2


7. What are the notations used in Evaluation of Arithmetic Expressions using prefix and postfix forms?
Answer:Polish and Reverse Polish notations.

8. Convert the expression ((A + B) * C – (D – E) ^ (F + G)) to equivalent Prefix and Postfix notations.
Answer:Prefix Notation: ^ - * +ABC - DE + FG
Postfix Notation: AB + C * DE - - FG + ^

9. Sorting is not possible by using which of the following methods?
Answer:(a) Insertion
(b) Selection
(c) Exchange (bubble sort)
(d) Deletion
(d) Deletion.
Using insertion we can perform insertion sort, using selection we can perform selection sort, using exchange we can perform the bubble sort (and other similar sorting methods). But no sorting method can be done just using deletion.

10. Draw a binary tree with 20 nodes has 21 null branches?
Answer:Let us take a tree with 5 nodes (n=5)



It will have only 6 (ie,5+1) null branches. In general, a binary tree with n nodes has exactly n+1 null nodes.

11. What are the methods available in storing sequential files ?
Answer:Ø Straight merging,
Ø Natural merging,
Ø Polyphase sort,
Ø Distribution of Initial runs.

12.How many different trees are possible with 10 nodes ?
Answer:1014
For example, consider a tree with 3 nodes(n=3), it will have the maximum combination of 5 different (ie, 23 - 3 = 5) trees.


i ii iii iv v

In general:
If there are n nodes, there exist 2n-n different trees.

13. List out few of the Application of tree data-structure?
Answer:
Ø The manipulation of Arithmetic expression,
Ø Symbol Table construction,
Ø Syntax analysis.

14. List out few of the applications that make use of Multilinked Structures?
Answer:Ø Sparse matrix,
Ø Index generation.

15. In tree construction which is the suitable efficient data structure?
Answer:(a) Array (b) Linked list (c) Stack (d) Queue (e) none
Answer:
(b) Linked list

16. What is the type of the algorithm used in solving the 8 Queens problem?
Answer:Backtracking

17. In an AVL tree, at what condition the balancing is to be done?
Answer:If the ‘pivotal value’ (or the ‘Height factor’) is greater than 1 or less than –1.

Data structure interview question Series 1

Data structure interview question
1.What is data structure?
Answer:A data structure is a way of organizing data that considers not only the items stored, but also their relationship to each other. Advance knowledge about the relationship between data items allows designing of efficient algorithms for the manipulation of data.

2. List out the areas in which data structures are applied extensively?
Answer: Ø Compiler Design,
Ø Operating System,
Ø Database Management System,
Ø Statistical analysis package,
Ø Numerical Analysis,
Ø Graphics,
Ø Artificial Intelligence,
Ø Simulation

3. What are the major data structures used in the following areas of RDBMS, Network data model & Hierarchical data model.
Answer: Ø RDBMS – Array (i.e. Array of structures)
Ø Network data model – Graph
Ø Hierarchical data model – Trees

4. If you are using C language to implement the heterogeneous linked list, what pointer type will you use?
Answer: The heterogeneous linked list contains different data types in its nodes and we need a link, pointer to connect them. It is not possible to use ordinary pointers for this. So we go for void pointer. Void pointer is capable of storing pointer to any type as it is a generic pointer type.

5. Minimum number of queues needed to implement the priority queue?
Answer: Two. One queue is used for actual storing of data and another for storing priorities.

6. What is the data structures used to perform recursion?
Answer: Stack. Because of its LIFO (Last In First Out) property it remembers its ‘caller’ so knows whom to return when the function has to return. Recursion makes use of system stack for storing the return addresses of the function calls. Every recursive function has its equivalent iterative (non-recursive) function. Even when such equivalent iterative procedures are written, explicit stack is to be used.

Sunday, May 30, 2010

Set up a SQL Server 2005 Login and Database Mapping

How to set up a SQL Server 2005 Login and Database Mapping

1. Launch SQL Server Management Studio.
2. At the top level, expand the “Security” tree node.
3. Next, right-click the “Logins” tree node.
4. Select New Login…
5. Under the “General” Tab in the left-hand explorer panel, type in the new login name in the left pane textbox such as “TestUser”.
6. For SQL Server Authentication, type in a password.
a. Note, if the “Enforce password policy” is checked, then you must provide a strong password value, such as “alen$123” (recommended). If you do not wish to provide a strong password, then uncheck the “Enforce password policy” checkbox.
b. Uncheck “Enforce Password Expiration” and “User must change password at next login” is unchecked.



7. Select the database as "SCORES" [YourDatabaseName].
8. Keep the default language as .

9. Next, while still in the “Login – New” window, click on the “User Mapping” node in the right-hand explorer panel.
10. Check the check box in the “Map” column of the database(s) that you want your login to map to. Check the “SCORES” database.
11. You may leave the “Default Schema” blank since it will default to “dbo”, however you can also type in “dbo” or click the ellipsis button to navigate and select the object schema you wish to use.




12. Click Ok.
13. To verify the set-up, go to the Northwind database node and expand it.
14. Expand that database and expand the “Security” node. There you will see the new Login “Test1” as a valid login for the Northwind database.

Note:
Under this node, you should see the newly created and mapped login. This login only gives access to the database, but does not give any select, update, or delete types of permissions, nor does it enable this login to execute or modify any stored procedures. To set this up, follow the next step.


How to set up logins with Schemas (SQL Server 2005)

Notice in SQL Server Mangement Studio that the tables and the stored procedures inside the database are referenced like so:
dbo.TableName
What this indicates is that the dbo is the schema name. A schema in SQL Server is a namespace or container that contains objects. Those objects are tables, stored procedures, etc. So, with our schema, we can ADD a user, and then give the appropriate permissions on that schema, which will trickle down to all the objects inside that schema. This really is, in essence, equivalent to a global permission setting for the user(s) of all objects inside the schema. To accomplish this follow these steps:
1. Expand the SCORES database.
2. Expand the Security node in the SCORES database
3. Expand the Schemas node
4. Find the “dbo” schema and right click it and select Properties
5. From the Schema Properties dialog, click the “Permissions” node.
6. Under the “Users or roles” area, click the “Add…” button.
7. Select the user or role objects (in this case, we’ll select the “TestUser” user object which is the mapped login we created in the previous section of step 5).
8. Click OK, then OK again.

9. From here, you will see in the “Explicit Permissions for user ”: with all the permissions you can grant on tables and stored procedures and others. For tables, we’ll select the “SELECT” permission. For stored procedures, we’ll select the execute permission.

10. Click OK.

What his accomplishes for this user set example is we granted all these permission for this user without having to go into each table/stored procedure and picking the permissions at that table/stored procedure level. We specified the permissions at the schema level and that cascades down to all the objects inside that schema container.
Enable basic permissions for tables (Optional)
1. To enable permissions on a table, go to the database and expand the “Tables” tree node.
2. Right-click the table you want to give the new login permissions to and select “Properties”.
3. Click the “Permissions” tab in the Table Properties Window.
4. Under the “Users or roles:” section, you may or may not see any objects listed, but will not see the new login user we created earlier. Under this section, click the “Add” button.
5. The “Select Users or Roles” window will appear. Click the “Browse” button.
6. A “Browse for Objects” window should appear with a listing of all objects that match for this database. You should see our new login user since we mapped it to this database. Check the check box by that new user and click OK.
7. Click Ok again and the “Explicit persmissions for ” will appear with a listing of permissions. For our table, check the following permissions you want to grant (I.e. Select, Update, Delete, Insert)
8. Click OK.

Wednesday, April 28, 2010

Prevent Page from being Cached in ASP.NET

In ASP.NET Page can be prevent from being cached by IIS. The following VB.NET code forces IIS to reprocess the page each time it's called.


Sub nocache_store()
'HttpContext.Current.Session.LCID = 2057
With HttpContext.Current
'.Session.LCID = 2057
.Response.AppendHeader("Pragma", "no-cache")
.Response.AppendHeader("Cache-Control", "no-cache")
.Response.AppendHeader("Cache-Control", "no-store")
.Response.AppendHeader("Cache-Control", "must-revalidate")
.Response.CacheControl = "no-cache"
.Response.Expires = -1
.Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache)
.Response.Cache.SetAllowResponseInBrowserHistory(False)
.Response.ExpiresAbsolute = New DateTime(1900, 1, 1)

End With
End Sub



click here to Convert Code from vb.net to c#.net

Copy table with data and structure in SQL


SELECT *
INTO new_table_name FROM old_tablename



above statement copy the table(existing table) data and structure into new table

Tuesday, April 20, 2010

Abstract Classes Vs Interface

Interface
An interface is a reference type containing only abstract members. These can be events, indexers, methods or properties, but only the member declarations. A class implementing an interface must provide the implementation of the interface members. An interface cannot contain constants, constructors, data fields, destructors, static members or other interfaces. Interface member declarations are implicitly public.


Abstract Class

Like an interface, you cannot implement an instance of an abstract class, however you can implement methods, fields, and properties in the abstract class that can be used by the child class.



* An Interface cannot implement methods.
* An abstract class can implement methods.


* An Interface can only inherit from another Interface.
* An abstract class can inherit from a class and one or more interfaces.


* An Interface cannot contain fields.
* An abstract class can contain fields.


* An Interface can contain property definitions.
* An abstract class can implement a property.


* An Interface cannot contain constructors or destructors.
* An abstract class can contain constructors or destructors.


* An Interface can be inherited from by structures.
* An abstract class cannot be inherited from by structures.


* An Interface can support multiple inheritance.
* An abstract class cannot support multiple inheritance.

For More help please follow...........

Monday, April 19, 2010

MD5 Password in Database(SQL Server 2005) itself

Some of us want some time to encrypt the password in database itself due to security reason.(i.e. At the time of user creation, forgot password or may be at the time of reset the password). So SQL Server also provide the utility for 'MD5 Algorithms' HashBytes() is the function used for encryption more on HashBytes()



select HashBytes('MD5','ABC123');


it will return the varbinary (maximum 8000 bytes)
the output will be '0xBBF2DEAD374654CBB32A917AFD236656'
but it will not equate the value with .NET hashing so to make it equal to .NET Hashing need to use another conversion function with triming the first to '0x'
characters from the returned value like:



select SUBSTRING(master.dbo.fn_varbintohexstr(HashBytes('MD5', 'ABC123')), 3, 32);



and the now the output is 'bbf2dead374654cbb32a917afd236656' that is equal to .NET Hashing techniques