IR
Author: vamsipavan
Complete binary tree and Full binary tree
Full and Complete binary trees are different. All full binary trees are complete binary trees but not vice versa. Full binary tree needs 2^n-1 nodes
Heterogenious linked list
If you are using C language to implement the heterogeneous linked list, what pointer type will you use? The heterogeneous linked list contains different data types in its nodes and we need a link, pointer to connect them. It isContinue reading… Heterogenious linked list
Sort linked list
Node *MoveMinToStart(Node *aHead) { if(aHead == NULL or aHead->next == NULL) return aHead; Node *PrevMin = NULL,*Cur=aHead,*Prev=NULL,*Min=NULL; while(Cur){ if(Min == NULL or Min->Value > Cur->Value){ Min = Cur; PrevMin = Prev; } Prev = Cur; Cur = Cur->next; } if(PrevMinContinue reading… Sort linked list
Redefining inbuilt data types
#include typedef int INTEGER /* will work */ But #define INTEGER int /* will also work*/ INTEGER SomeFunction() { …… code return 0; } This will work But Rule of thumb is #defines are used for textual replacement whereas typedefsContinue reading… Redefining inbuilt data types
Repeating characters
Write a funtion that finds repeating characters in a string. Sort the string
Draw circle, using integer operations
Q: Write a routine to draw a circle given a center coordiante (x,y) and a radius (r) without making use of any floating point computations. Refer to graphics algorithms
Give a fast way to multiply a number by 7
Represent 7 in binary format. Now shifting and adding by appropriate times will give the solution or Multiply it by 8 (shift by 3 bits) and subtract the original number.
Check whether a number is power of 2
Q. Give one line C expression to check whether a given number is an exponential power of 2 Ans: if ( x & (x-1) == 0){ printf(“Yes”) }else{ printf(“No”) } What about zero ?? Set the LSB to zero xContinue reading… Check whether a number is power of 2
In array of n numbers one numer repeating, detect it in one pass
Repeated Number = Sigma(n) – Sigma(n-1) Q. The integers from 1 to n are stored in an array in a random fashion. but one integer is missing. Write a program to find the missing integer. Follow the same technique