-->

Ebay Interview Solution Set -1

Posted by Admin on
Round 1 

Q1. Let us assume there are 3 baskets with different number of balls say p,q and r. Every ball has a number written on it. Now, you have to take all those balls and put them back in baskets in sorted way.?
Ans: Easy . Just apply merge sort or quick sort on all the buckets separately.


Q2. What is Mutual Exclusion?
Mutual Exclusion is the process in which we make sure that no two process enter in the critical section at the same time.
Mutual Exclusion is one of reason of deadlock.

Q3. What is multithreading and Difference between process and thread?
Multithreading is process in which more than one  threads runs at the same time . Thread is the smallest unit of a program . Thread are light weight process .A multithreading is a specialized form of multitasking. Multithreading requires less overhead than multitasking processing.

Processes Vs Threads
Similarities
Like processes threads share CPU and only one thread active (running) at a time.
•Like processes, threads within a processes execute sequentially.
•Like processes, thread can create children.
•And like process, if one thread is blocked, another thread can run.
Differences
Unlike processes, threads are not independent of one another.
•Unlike processes, all threads can access every address in the task .
•Unlike processes, thread are design to assist one other. Note that processes might or might not assist one another because processes may originate from different users.

Q4. What is Semaphore?
Real life Example:
Lets say we have four toilets with identical locks and keys. The semaphore count - the count of keys - is set to 4 at beginning (all four toilets are free), then the count value is decremented as people are coming in. If all toilets are full, ie. there are no free keys left, the semaphore count is 0. Now, when eq. one person leaves the toilet, semaphore is increased to 1 (one free key), and given to the next person in the queue.

Officially: "A semaphore restricts the number of simultaneous users of a shared resource up to a maximum number. Threads can request access to the resource (decrementing the semaphore), and can signal that they have finished using the resource (incrementing the semaphore)."
For more information see this post : Mutex vs Semaphore

Q5. There are three threads have been assigned different work. Say,
T1 takes 10 sec T2 takes 20sec t3 takes 15sec Now you have to make sure that all threads merge into one and continue as a single thread. How will you wait and all?
Answer : The above mechanism can be achieved by using join() method . Join() method cause currently running thread to  complete it task first . Once the currently running thread stop executing then the next thread with which it joins start executing .

Q6. Let’s say you have 100,000 records and you want to delete 95,000 at a time and keep only 5 thousand. But in local memory you don’t have enough space for 95,000 records. What do you do in this case? How do you delete without any problem with time and performance?
1)First create a table using select statement with 5000 records you want to keep and put it in memory. 
2)Then drop/truncate the entire table.. and then put this 5000 record table in place. 

Round 2

Q1. Function ‘sum’ which takes arguments, such that if both args are:
int : does integer addition
float : does float addition
string : concatenates them

Write a program in ‘C’ that does the same?

Solution in Java:
public class Arguments{

       public static void main(String[] args) {
             
                  add(2.1f,3.2f);
       }
       public static void add(Object a,Object b)
       {
              if(a instanceof java.lang.Integer && b instanceof java.lang.Integer)
              {
                     int num1 = (Integer) a;
                     int num2=(Integer) b;
                     System.out.println("Result :->"+(num1+num2));
              }
             
              else if(a instanceof java.lang.String && b instanceof java.lang.String)
              {
                     String num1 = (String) a;
                     String num2=(String) b;
                     System.out.println("Result:->"+(num1+num2));
              }
             
              else if(a instanceof java.lang.Float && b instanceof java.lang.Float)
              {
                     Float num1 = (Float)a;
                     Float num2 = (Float)b;
                     System.out.println("going in float");
                     System.out.println("Result:->"+(num1+num2));
              }
              else
              {
                     System.out.println("invalid inputs");
              }
       }
}

For the above question we don't think we can do it in C without using some extra variable except two arguments . Because even if we will be using void pointer then how do we get to know that we data types are contained in it.If anyone have solution for this please comment. 

Q2. Write SQL Query for creating tables?
create table table_name
{
Name varchar(20),
Roll_no int,
-----------
----------
}
Q3. What about NESTED TABLES?
A nested table is like a one-dimensional array with an arbitrary number of elements. However, a nested table differs from an array in the following aspects:
An array has a declared number of elements, but a nested table does not. The size of a nested table can increase dynamically.
An array is always dense i.e., it always has consecutive subscripts. A nested array is dense initially, but it can become sparse when elements are deleted from it.
A nested table can be stored in a database column and so it could be used for simplifying SQL operations where you join a single-column table with a larger table. An associative array cannot be stored in the database.
Reference: http://docs.oracle.com/cd/A97630_01/appdev.920/a96624/05_colls.htm

Q4:What are Views ?
See this Post : View in database 


Round 3 :

Q1. You have an embedded system device. Okay? So you are given some numbers from 1-100 and unique. Now, sort these numbers?
In this question you will have to use Quick Sort or Heap Sort only because embedded system mean very limited memory and only Heap Sort and Quick Sort sort the elements with O(nlogn) time complexity and O(1) space complexity.

Q2: Evaluate Postfix Expression ?
See this Post : Postfix Evaluation

Please comment if you find the above post or find any mistake .





2 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. Why so ? How it would help you .

    ReplyDelete