Sunday, August 21, 2011

SORTING COMPLEXITIES

 

SORTING

BEST CASE

AVERAGE CASE

WORST CASE

Insertion Sort

O(n)

O(n2)

O(n2)

Bubble Sort

O(n)

O(n2)

O(n2)

Selection Sort

O(n2)

O(n2)

O(n2)

Quick Sort

O(n log n)

O(n log n)

O(n2)

Merge Sort

O(n log n) typically , O(n)

O(n log n)

O(n log n)

Heap Sort

O(n log n)

O(n log n)

O(n log n)

Radix Sort

O(kn)

O(kn)

O(kn)

Counting Sort

O(n+k)

O(n+k)

O(n+k)

PLACEMENT QUESTIONS–I

 

Here I post some of the placement questions. These are very simple..

Question 1 : Ugly numbers are numbers whose only prime factors are 2, 3 or 5. 
The sequence
1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ...
shows the first 11 ugly numbers.
By convention, 1 is included.

Write a program to find and print the 1500'th ugly number.
Question 2 : int main()
{
int i, n = 20;
for (i = 0; i < n; i--)
printf("*");
return 0;
}

Change/add only one character and print '*' exactly 20 times.
(there are atleast 3 solutions to this problem)
Question 3 : You are provided with two stacks, and pop() and push() 
functions for them.
You have to implement queue i.e. enqueue() and dequeue() using the
available operations.
Question 4 : How do you reverse the words in a string?

"My name is Ajit Agarwal"
to
"Agarwal Ajit is name My"

A O(n) and 'in space' solution is appreciable.
Question 5 : Given an array of numbers, except for one number all the others, 
occur twice. 
Give an algorithm to find that number which occurs only once in the
array.
Question 6 : There is a series of numbers in ascending order. All these numbers
have the same number of binary 1s in them. Given the number of 1 bits set in
the numbers, write an algorithm/C program to find the nth number in
the series.
Question 7 : Given a string s1 and a string s2, write  a snippet to say 
whether s2 is a rotation of s1 using only one 
call to strstr routine?

(eg given s1 = ABCD and s2 = CDAB, return  true,
given s1 = ABCD, and s2 = ACBD , return false)
Question 8 : 
What's the  "condition" so that the following code
snippet  prints both HelloWorld !

if  "condition"
printf ("Hello");
else
printf("World");

Wednesday, August 10, 2011

TREE PROBLEMS - II

1. Given two trees, return true if they are
structurally identical.

int sameTree(struct node* a, struct node* b) {
  // 1. both empty -> true
  if (a==NULL && b==NULL) return(true);

  // 2. both non-empty -> compare them
  else if (a!=NULL && b!=NULL) {
    return(
      a->data == b->data &&
      sameTree(a->left, b->left) &&
      sameTree(a->right, b->right)
    );
  }
  // 3. one empty, one not -> false
  else return(false);
}

2. code to count number of leaves in the tree

void count_leaf(mynode *root)
{
   if(root!=NULL)
   {
      count_leaf(root->left);
      if(root->left == NULL && root->right==NULL)
      {
        // This is a leaf!
        count++;
      }
      count_leaf(root->right);
   }
}

3. code to create copy of tree


mynode *copy(mynode *root)
{
  mynode *temp;
  if(root==NULL)return(NULL);
  temp = (mynode *) malloc(sizeof(mynode));
  temp->value = root->value;
  temp->left  = copy(root->left);
  temp->right = copy(root->right);
  return(temp);
}

4. code to create mirror copy of tree


mynode *copy(mynode *root)
{
  mynode *temp;
  if(root==NULL)return(NULL);
  temp = (mynode *) malloc(sizeof(mynode));
  temp->value = root->value;
  temp->left  = copy(root->right);
  temp->right = copy(root->left);
  return(temp);
}

5. Implementing level order traversal of a tree

If this is the tree,

        1
   2         3
5   6     7   8

its level order traversal would be

1 2 3 5 6 7 8

void levelOrderTraversal(mynode *root)
{
  mynode *queue[100] = {(mynode *)0}; // Important to initialize!
  int size = 0;
  int queue_pointer = 0;
  while(root)
  {
      printf("[%d] ", root->value);
      if(root->left)
      {
        queue[size++] = root->left;
      }
      if(root->right)
      {
        queue[size++] = root->right;
      }
      root = queue[queue_pointer++];   
  }
}

Friday, April 29, 2011

books for interviews

These are the 2 important books for computer science students who are
attending interview.
1. Programming interview exposed
2. Do the new - career cup



Monday, March 21, 2011

Top 7 Tips to Crack Telephone Interviews

By Sunder Ramachandran

Most organizations are saving time and effort by conducting an initial round of telephonic interview before calling you for a personal round to their office. Given this, your voice and the way you project yourself over the phone can make all the difference.

  1. Visit the employers' website
    Visit the employers' website and learn about the firm. Most companies upload the job specifications in the 'career' or 'work with us' section of the website. This will give you a fair idea about the key skills required for a certain role.
  2. Make notes
    Keep some notes ready about the job description and your key strengths and accomplishments. It's a good idea to keep your resume in front of you as well. Remember, they can't see if you have these documents for review.
  3. Mock calls
    Call a friend from your and ask them to listen to your voice on the phone. Maybe your voice shrills; you speak too softly or too fast to be understood. As for feedback and request them to critique your voice.
  4. Get to the point fast
    The employer is already expecting calls from candidates, so don't waste their time by giving them a reference of where you saw their advertisement or asking them, if there are any openings. Greet them, state your name and get to the point
  5. Keep a note pad and pen ready
    Write down their questions so that you can stay on purpose. Too often, people forget the original question and beat around the bush. Stay on target
  6. Sound energetic
    Your voice is your only sales tool. Don't allow yourself to sound tired or uninterested over the phone. Sound energetic and excited, even if they've asked you the same question again. Keep a glass of water ready next to you.
  7. Be courteous
    Be courteous and try not to speak over the interviewer or cut them off. If you do, say "I apologise for interrupting, please complete your question" and let the interviewer continue

Sunder Ramachandran is a Managing Partner at W.C.H (We Create Headstarts) Solutions - http://www.wchsolutions.com, a Training solutions organisation. He can be reached at sunder@wchsolutions.com

Source: http://Top7Business.com/?expert=Sunder_Ramachandran

link referred : http://top7business.com/?Top-7-Tips-to-Crack-Telephone-Interviews&id=2213

PLACEMENT GUIDE

Subjects need to be studied are:
Basic subject
1. C
2. DS
3. OOPS
4. BASIC CONCEPTS IN THE FOLLOWING CHAPTERS ALSO

Extra Subject
1. ALGORITHM
2. OS
3. DBMS
4. NETWORKS
5. DIGITAL
6. SYSTEM SOFTWARE
7. TOC
8. COMPILER
9. JAVA
10.MICROPROCESSOR
11.SOFT. ENGG
12.OOAD
 Subjects are given in the order of importance. To attend any kind of
company we have to study the all extra subjects also.
 Basic Subjects need to be covered by all, Other subjects are just like
electives (area of interest).
 If we studied all the stuffs no one can overtake us in any company
Stuffs need to be covered in each Subject
· C
 Dennis Ritchie book start to end.
 Aucse questions
 Test your C skills using ‘Yashwanth kanithkar’ book
 String.h (implement all functions in this header)
 Study about memory.h functions
· Data Structure
 Use “Robert kurse” or “Schaum’s series” book.
 Arrays to Hashing with hand code.
 Linked List, Tree will be given for onsite problem solving.
 Recursive algorithms.
 Mail will be sent to all you people for some material of this
section. (Who all want hard copy get it from me).
· Object Oriented Programming Concepts
 Study all oops concepts
(‘Balagurusamy’,’Ravichandran’,’Rajagoalan’ Use any of these
books).
 Static and Dynamic memory management.
 Similarities and Difference between Java and C++.
 See Concepts and FAQs in Net. (If we got good link, we’ll
intimate you later).
 No need to study STL in deep.
· Basic Concepts
 Those who are not interested in studying all chapters, at least
study basics concepts like what it is? and why it is?, in OS,
Algorithm, DBMS, Networks.
· Algorithm
 Cormen 15 Chapters.
 Searching, Sorting (Complexity, situation of use).
 Hand code for these.
· OS Concepts
 Process, Memory management (chap 4-10 in Silberschatz).
 I/O, File (If needed chapter 11).
· DBMS
 Thorough with Mam notes and assignments.
 ACID
 Locks, Serialization, Normalization, Keys, Terminologies.
 Problems involved.
 Know little bit various available DBMS.
· Networks
 OSI Model, TCP/IP Suite.
 Topology.
 Network Elements.
 Protocols.
 IP Addressing (A, B, C, D, E).
 Subnetting, Supernetting (CIDR).
 IPV4 Vs IPV6.
· Digital Design
 Combination and logics (First 5 Chapters in our text book).
· System Software
 Assembler, Loader, Linker (Basics).
· Toc
 Regular Expression, Grammar, Automata.
· Compiler
 Pre compiling Vs Post compiling.
 Phases of Compiler.
· Java
 Complete Reference first 5 Chapters.
· Microprocessor
 Notes.
 8085 and 8086 (memory segments and external devices).
· Soft. Engg
 Lifecycle Model and Delta testing.
· OOAD
 Phases of OO approach.
 Difference between Procedure and Object oriented approach.

compiled by MIT 2005 batch