Skip to main content

Posts

AVL Tree

AVL Tree is often asked in interviews or coding rounds by some companies like Oracle and SAP.Though some people leave AVL trees thinking its not important,but you can never know what they might ask you in interview.So Its good to know about it.If not completely then at least some basic concepts. AVL Trees are Height Balanced binary search tree datastructure such that for every internal nodes the heights of the two child node differ by at most one.If the balanced is disturbed at any time re-balancing is to be done to again make it balanced.In AVL Tree searching,Insertion and Deletion takes O(logn) time.Insertion and Deletion may require to re-balance the tree using Tree rotation  . Let the height of last nodes be 1 the node above it be 2 and finally the root node be 4.You can see that the tree is balanced as the height of child nodes of internal nodes differ by the value of 1 or 0.Next we will discuss the Insertion of AVL Tree. Insertion : It is necessary to check ...

Find the prime numbers between a range of numbers

Often this question is asked in interviews by companies and most of them apply the same old traditional method of finding prime numbers resulting in large complexity of the program. The proper solution for finding the prime numbers is the Sieve of Eratosthenes. Well, the algorithm is not so difficult, unlike its name. The basic principle here is to iteratively mark the multiples of unmarked numbers starting from 2 till the limit and then the numbers left out unmarked are primes numbers. Let's take a series of numbers starting from 2. 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25.............. Now lets mark multiples of 2 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25.............. Now mark multiples of 3 (Next unmarked) 2 3  4  5  6  7  8   9   10  11  12  13  14   15   16  17  18  19  20   21   22  23  24  25..............

Program to reverse a doubly linked list

In doubly linked list we are not restricted to move in one direction unlike in singly linked list because in doubly linked list we have two pointers in one node that is next pointer and previous pointer.so that we can move in both directions.Taking the advantage of this property of doubly linked list it is more easier to reverse doubly linked list as compared to singly linked list.The logic of the program is simple.We are going upto middle of doubly linked list and swap the first node and last node and so on until the linked list is reversed. struct node { node *next; node *previous; int data; } void reverse(struct node *head) { node *firstnode; node *secondnode; int l; int length=0; struct node *tail=head; while(tail!=NULL) { tail=tail->next; length++; } firstnode=head; secondnode=tail; l=length/2; node *temp; for(int i=0;i<l;i++) { temp=firstnode->data; firstnode->data=secondnode->data; secondnode->data=temp; firstnode=firstnode->nex...

Resistive vs Capacitive touchscreens

We all know that there are two types of touchscreens in mobile phones but we dont know what actually they are and what are the difference between them.Many of us encountered the difference while using mobile phones such as some touchscreen response is faster and its easy to touch while in some response is little longer and have to apply more pressure.The two types of touchscreen are resistive and capacitive. Which one is better then the other.Well today we will see what are the difference between them. Resistive : This is the most common touchscreen type in mobile phones except some smartphones and tablets. Talking about resistive touch,from the name we can get that this touchscreen depends on resistance.The resisitive touchscreen consist of several layers stacked upon each other.But there are two important transparent thin layer seperated by thin gap.The screen we touch has a coating on its other side and beneath it there is other layer also have coating on it one side.Both the s...

Program to reverse the words of string

This program is little bit modification to the previous post program.After reversing the letters of each words in a string when we call again the reverse function the words get reversed of the string. #include<stdio.h> #include<conio.h> void reverse(char *start, char *end); void reversethewords(char *s) {   char *wordbegin = s;      //wordbegin and t are two pointer to the first character of string s   char *t = s;               while( *t)   {     t++;     if (*t == '\0')            // if reached at the end of the string reverse(swap) the first character and last and     {                                                                             ...

Program to reverse the letters of each words of the string

#include<stdio.h> #include<conio.h> void reverse(char *start, char *end); void reversethewords(char *s) {   char *wordbegin = s;      //wordbegin and temp are two pointer to the first character of string s   char *t = s;                 while( *t)   {     t++;     if (*t == '\0')            // if reached at the end of the string reverse(swap) the first character and last and     {                                                                                                                            so on.       ...

extern keyword in C

For extern keyword to understand let us first discuss the difference between declaring a variable and defining a variable.The declaration of variable is simply declaring variable in the program that is it just exist somewhere in the program with no memory allocated to that variable.When the variable is declared program know the datatype of the variable.On the other hand when we say we defined a variable it means that a variable is declared and also section of memory is allocated to that variable in the program.The variable in a program can be declared various times but can only defined once.Now moving onto the "extern" keyword when we declare a variable with extern keyword the variable is only declared and not defined. Let's understand this using some sample programs : int a; int main() { a=10; printf("%d",a); } The above program is compiled successfully without any error because the variable "a" is declared and defined globally.So the varia...