Interview Questions.

C and Data Structure Interview Questions And Answers


C and Data Structure Interview Questions And Answers

Q1. What are different techniques for making hash feature?

Ans: Techniques for making hash feature.

• Truncation Method

This is the simplest approach for computing cope with from a key.In this approach we take simplest part of the important thing as address.

• Midsquare Method

In this approach the key is squared and a few digits from the center of this square are taken as deal with.

• Folding Method

In this technique, the secret is divided into distinct element wherein the duration of every part is equal as that of the specified address, except probably the final part.

• Division Method (Modulo-Division)

In Modulo-Division technique the secret's divided through the table length and the remainder is taken because the address of the hash desk.

–>Let the table length is n then

H (okay) =okay mod n

Master C and Data Structure, in this C and Data Structure certification education.

Q2. What are the troubles that impede the performance in sorting a document?

Ans: The problems are:

Length of time required by way of the programmer in coding a selected sorting application.

Amount of machine time vital for strolling the unique program.

The quantity of area vital for the specific application.

Q3. What is the usage of volatile keyword?

Ans: The modifier ‘risky’ tells the compiler that a variable’s price can be modified in methods no longer explicitly designated by this system. For instance, a international variable’s cope with may be exceeded to the operating gadget’s clock recurring and used to preserve the gadget time.

In this example, the contents of the variable are altered without any specific project statements within the application.

This is vital because maximum C compilers automatically optimize sure expressions with the aid of assuming that a variable’s content material is unchanging if it does no longer arise on the left facet of an challenge announcement. Thus, it can not be reexamined each time it's miles referenced. Also, a few compilers trade the order of assessment of an expression during the compilation process. The volatile modifier prevents those modifications.

Q4. Write a C software without the use of semicolon to print ‘Hello global’

Ans: void primary()

if(printf("Hello international"))

Q5. What are variations among sizeof operator and strlen characteristic?

Sizeof is key-word of C which could find size of a String constant together with null man or woman, however strlen is characteristic which has been defined string.H and may discover range of characters in a string apart from null person.


void fundamental()

int a,b;



printf("%d  %d",a,b);


Q6. What is the difference among

Ans: sprintf(…) writes records to the person array. The C library characteristic sprintf () is used to save formatted information as a string. You also can say the sprintf () characteristic is used to create strings as output using formatted facts. The syntax of the sprintf () function is as follows:

int sprintf (char *string, const char *shape, … );

Here, the *string will stand for the name of the array a good way to save the output received by means of working at the formatted statistics. The *form parameter will show the layout of the output.

Printf(…) writes statistics to the standard output tool. The printf characteristic is only a beneficial feature from the usual library of features which might be reachable via C applications.

The behavior of printf is defined inside the ANSI widespread. If the compiler that you’re using conforms to this standard then all of the capabilities and properties ought to be available to you.

Q7. When does the compiler not implicitly generate the deal with of the primary detail of an array?

Ans: The compiler does not implicitly generate the address of the first detail of an array each time an array call seems:

– as an operand of the sizeof operator

– as an operand of & operator

– as a string literal initialize for a individual array

Q8. Is using go out() similar to using return?

Ans: No, the go out() function is used to go out your application and go back() controls the working device.

The return statement is used to return from a feature and go back control to the calling characteristic. If you're making a return from the primary() characteristic, you are essentially returning manipulate(working gadget) to the calling feature. In this case, the return declaration and go out() characteristic are similar.

Q9. What is an lvalue?

Ans: An lvalue is an expression to which a value can be assigned. The lvalue expression is positioned on the left aspect of an challenge announcement whereas an rvalue is located on the proper side of an assignment declaration.

Each challenge assertion have to have an lvalue and an rvalue. The lvalue expression need to refer a storable variable in memory. It can not be a consistent.

Q10. What is the distinction among goto, longjmp() and setjmp()?


A goto declaration implements a local jump of software execution while the longjmp() and setjmp() features implement a nonlocal or a long way soar of this system execution.

Generally, a jump in any execution should be averted as it isn't taken into consideration precise programming exercise to apply such statements as goto and longjmp in your software.

A goto declaration without a doubt bypasses code in your program and jumps to a predefined role. To use the goto declaration, you provide it a categorized position to leap to. This predefined role should be inside the same function. You cannot put in force goto among capabilities.

However, whilst your application calls setjmp(), the cutting-edge state of your program is saved in a shape of kind jmp_buf. Later, your program can name the longjmp() characteristic to restore this system’s kingdom as it was whilst you called setjmp().Unlike the goto announcement, the longjmp() and setjmp() functions do now not want to be carried out within the identical characteristic.

There is a main disadvantage of the use of those functions: your software, whilst restored to its formerly saved nation, it'll lose its references to any dynamically allotted reminiscence among the longjmp() and the setjmp(). This manner you'll waste memory for each malloc() or calloc() you have applied among your longjmp() and setjmp(), and your software can be inefficient.

It is fantastically endorsed which you keep away from the use of capabilities which include longjmp() and setjmp() because they, just like the goto statement, are pretty regularly an illustration of bad programming practice.

HubSpot Video

Q11. What is XOR connected listing?

Ans: XOR related listing is a Memory Efficient Doubly Linked List. An normal Doubly Linked List requires area for 2 address fields to store the addresses of preceding and next nodes. A reminiscence efficient version of Doubly Linked List can be created using only one space for deal with subject with every node. This reminiscence green Doubly Linked List is called XOR Linked List or Memory Efficient because the list makes use of bitwise XOR operation to keep space for one deal with.

In the XOR connected list, instead of storing real reminiscence addresses, each node stores the XOR of addresses of previous and next nodes.

XOR List Representation:

Let us call the address variable in XOR illustration npx (XOR of subsequent and previous)

Node A:

npx = zero XOR add(B) // bitwise XOR of zero and address of B

Node B:

npx = add(A) XOR add(C) // bitwise XOR of deal with of A and cope with of C

Node C:

npx = upload(B) XOR upload(D) // bitwise XOR of address of B and address of D

Node D:

npx = upload(C) XOR 0 // bitwise XOR of deal with of C and 0

Q12. What is ‘trie’ in statistics structure?

Ans: Trie is green records retrieval records structure. Using trie, search complexities can be introduced to ideal restrict (key period). If we keep keys in binary search tree, a nicely balanced BST will need time proportional to M * log N, where M is most string period and N is wide variety of keys in tree.

• Using trie, we can search the important thing in O(M) time. However, the penalty is on trie garage requirements.

• Each node of trie includes multiple branches. Each department represents a possible man or woman of keys.

• We want to mark the final node of each key as leaf node.

• A trie node area fee might be used to distinguish the node as leaf node (there are different makes use of of the cost subject).

• A easy shape to symbolize nodes of English alphabet may be as follows:

struct trie_node

int fee; /* Used to mark leaf nodes */

trie_node_t *kids[ALPHABET_SIZE];


Become Master of C & Data Structure through going thru this online education route.

Q13. What do you apprehend by means of splay tree?

Ans: Splay tree is a self-balancing Binary Search Tree (BST). The major idea of splay tree is to convey the lately accessed object to root of the tree. This makes the currently searched object to be handy in O (1) time if accessed again. The idea is to use locality of reference (In an average software: 80% of the access are to 20% of the objects).

Imagine a situation, wherein we have thousands and thousands or billions of keys and most effective few of them are accessed often, which could be very probably in lots of practical packages.

All splay tree operations run in O(log n) time on average, in which n is the range of entries within the tree. Any unmarried operation can take Theta(n) time in the worst case.

Q14. What is Treap?

Ans: Treap is a Balanced Binary Search Tree, however not assured to have top as O(Log n). The idea is to apply Randomization and Binary Heap property to hold stability with high possibility. The predicted time complexity of seek, insert and delete is O(Log n).

Each node of Treap keeps  values.

Key follows popular BST ordering (left is smaller and right is more)

Priority Randomly assigned cost that follows Max-Heap property.

How to implement LRU caching scheme? What facts systems must be used?

We are given overall viable web page numbers that can be referred. We also are given cache (or reminiscence) length (Number of web page frames that cache can keep at a time). The LRU caching scheme is to eliminate the least lately used frame while the cache is complete and a brand new page is referenced which isn't always there in cache.

Q15. We use two facts systems to enforce an LRU Cache.


A Queue: which is applied the usage of a doubly linked listing. The most length of the queue could be equal to the entire number of frames to be had (cache length).

The most recently used pages might be near the front quit and least currently pages will be close to rear quit.

A Hash: with page variety as key and address of the corresponding queue node as value. When a web page is referenced, the desired page can be within the reminiscence. If it's far inside the reminiscence, we want to detach the node of the listing and bring it to the the front of the queue.

If the required web page isn't always inside the memory, we deliver that during reminiscence. In simple phrases, we upload a new node to the front of the queue and update the corresponding node cope with in the hash. If the queue is full, i.E. All of the frames are full, we get rid of a node from the rear of queue, and upload the new node to the front of queue.

 Suppose, there are  linked lists: L1 and L2 (of identical lengths) that intersect at a selected node N1, which is a common endpoint to all different nodes. What are the possibilities to find N1?

Linear solution is viable. Have two guidelines say P1 pointing to the first node of L1 and P2 to that of L2. Traverse thru each the lists. If P1 reaches L1’s remaining node, point it to the primary node of L2 and retain traversing.

Do the same element for P2 while it reaches L2’s closing node. (By doing this, we are balancing the difference in the duration among the linked lists. The shorter one will get over quickly and through redirecting to longer listing’s head, it'll traverse the more nodes also). Finally, they will meet at the Intersection node.

Q16 .Given two keys K1 & K2, write an set of rules to print all the elements among them with K1<=K2 in a BST.


Linear solution is possible with out the usage of any more area.

Perform an inorder traversal.

Once you discover K1, print it and maintain traversal now.

Print all other traversed factors until you reach K2.

Q17. How many stacks are required to enforce a Queue.


Two stacks are required to enforce a Queue.

For Enqueue:Take  stacks S1 and S2 and carry out push on S1.

For Dequeue:If S2 is empty, pop all of the elements from S1 and push it to S2. The final detail you popped from S1 is an element to be dequeued. If S2 isn't empty, then pop the pinnacle detail in it.