Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/gpl4you/public_html/_config-rating.php on line 26
Given a stack S, write a C program to sort the stack (in ascending order).
You are not allowed to make any assumptions about how the stack is implemented; the only
functions allowed to be used are: Push, Pop, Top, IsEmpty, IsFull.
There is a sequence of increasing numbers that have the same number of binary 1s in them. Given n, the number of 1 bits set in each number, write an algorithm
or C program to find the nth number in the series
Let n=3 ,then number series will be like:
0000111,0001011,0001101,0001110
the whole bunch of 1's will slowly shift towards right and every nth number will be having all 1s together.
Pusedo code:: to find kth no of series.(index from 0)
base=0
shift=k/n;
remain=k%n;// a 0 will be there between remain and (n-remain) no of 1s.
You are given have a datatype, say X in C. Determine the size of the datatype,
without declaring a variable or a pointer variable of that type, and, of course without using the sizeof operator
Create two hash,
- start hashing first set, put each element as output if collision doesn't occurs.
- start hashing each element of this set, if no collision occurs put that in hash as well as as output.
*Check out for better algorithms
Q. No. :
5
Question :
You have m nuts and n bolts, Every unique nut is fit in every unique bolt, Suggest an effective algorithm for placing each nut in each bolt in less no. of passes?
Suppose that there are n nuts and bolts. A simple modification of Quicksort shows that there are randomized algorithms whose expected number of comparisons (and running time) are O(n log n): pick a random bolt, compare it to all the nuts, find its matching nut and compare it to all the bolts, thus splitting the problem into two problems, one consisting of the nuts and bolts smaller than the matched pair and one consisting of the larger ones. Repeating in this manner yields an algorithm whose expected running time can be analyzed by imitating the known analysis for Quicksort
Q. No. :
6
Question :
Write a program in C to store details of 100 books of a library where
each record contains booknumber, book name, bookauthor, publisher,
number of copies,unit cost.
Read the data from an external file.
Implement insertion of new record
Deletion of existing record
modification of existing record
Find the total worth of the library.
There are four dogs, each at the counter of a large square. Each of the dogs begins chasing the dog clockwise from it. All of the dogs run at the same speed. All continuously adjust their direction so that they are always heading straight towards their clockwise neighbor. How long does it take for the dogs to catch each other? Where does this happen? (Hint: Dog’s are moving in a symmetrical fashion, not along the edges of the square).
This problem can be solved by sorting the array in non increasing order. so array A = { 4,2,1,3,6,9}
becomes = { 9,6,4,3,2,1}
Start processing this array from the beginning and keep the sum of the elements in each of the sets upto that point. now consider next two elements at each step. assign the larger of these to the set with the smaller sum. update the sum and continue this procedure.
so here
9 | 9 3 | 9 3 1
6 | 6 4 | 6 4 2
Q. No. :
9
Question :
How to call a C++ function which is compiled with C++ compiler in C code?
The C++ compiler must know that f(int,char,float) is to be called by a C compiler using the extern "C"construct:
The extern "C" line tells the compiler that the external information sent to the linker should use C calling conventions and name mangling (e.g., preceded by a single underscore). Since name overloading isn't supported by C, you can't make several overloaded functions simultaneously callable by a C program.
// This is C++ code
// Declare f(int,char,float) using extern "C":
extern "C" void f(int i, char c, float x);
...
// Define f(int,char,float) in some C++ module:
void f(int i, char c, float x)
{
.....
}
Q. No. :
10
Question :
How do you initialize a static member of a class with return value of some function?
Static data members are shared by all object instances of that class. Each class instance sees and has access to the same static data. The static data is not part of the class object but is made available by the compiler whenever an object of that class comes into scope. Static data members, therefore, behave as global variables for a class. One of the trickiest ramifications of using a static data member in a class is that it must be initialized, just once, outside the class definition, in the source file. This is due to the fact a header file is typically seen multiple times by the compiler. If the compiler encountered the initialization of a variable multiple times it would be very difficult to ensure that variables were properly initialized. Hence, exactly one initialization of a static is allowed in the entire program.
Consider the following class, A, with a static data member, _id:
//File: a.h
class A
{
public:
A();
int _id;
};
The initialization of a static member is done similarly to the way global variables are initialized at file scope, except that the class scope operator must be used. Typically, the definition is placed at the top of the class source file:
// File: a.cc
int A::_id;
Because no explicit initial value was specified, the compiler will implicitly initialize _id to zero. An explicit initialization can also be specified:
// File: a.cc
int A::_id = 999;
In fact, C++ even allows arbitrary expressions to be used in initializers:
// File: a.cc
int A::_id = GetId(
Q. No. :
11
Question :
If you are given the name of the function at run time how will you invoke the function?
* Compile your program with --export-dynamic on the gcc command line
* Link with -ldl (dynamic library handling, needed for dlopen and dlsym
* Call dlopen() with a null parameter, meaning you aren't loading symbols from a file but from the current executable
* Call dlsym() with the name of the function you'll be calling. Note that C++ modifies function names, so If you're trying this with C++, you'd have to either declare this function as extern "C", or figure out what name the function has after compiling. (On unix, you could run nm -s on the object file for this).
* If dlsym() returns non-null, use the returned value as a function pointer to invoke your function.
For example, a Web browser initiates a request to a server, typically by opening a TCP/IP connection. The request itself comprises o a request line, o a set of request headers, and o an entity. The server sends a response that comprises o a status line, o a set of response headers, and o an entity. The entity in the request or response can be thought of simply as the payload, which may be binary data. The other items are readable ASCII characters. When the response has been completed, either the browser or the server may terminate the TCP/IP connection, or the browser can send another request.
COM is linked to Microsoft and CORBA to UNIX,Moreover, COM objects require installation on the machine from where it is being used .CORBA is ORB (Object request broker) , and also its a specification owned by OMG, which is open. Not owned by a company. So we cannot say that it only belongs to Unix. Corba servers can run on windows NT, and CORBA clients can run on Unix.
Web Service is defined as "a software system designed to support interoperable Machine to Machine interaction over a network." Web services are frequently just Web APIs that can be accessed over a network, such as the Internet, and executed on a remote system hosting the requested services.
Q. No. :
15
Question :
Explain the Traveling Salesman problem? What is an NP-complete problem? What is the Hamiltonian cycle problem?
node_type *create_link_list(int n);
void print_link_list(node_type *root);
node_type *kReverse(node_type *head , int n);
node_type *reverse(node_type *head , int n);
node_type *get_k_th_node(node_type *head , int k);
main()
{
node_type *head;
int n , k;
printf("Give the number of element\n");
scanf("%d",&n);
head=create_link_list(n);
print_link_list(head);
printf("Give the value of k\n");
scanf("%d",&k);
head=kReverse(head , k);
print_link_list(head);
}
#include
int find_smallest_element_position(int *a, int first , int last);
main()
{
int a[10]={4,5,6,7,8,9,1,2,3};
int pos;
pos=find_smallest_element_position(a,0,8);
printf("The smallest element's position is %d\n",pos);
}
int find_smallest_element_position(int *a, int first , int last)
{
int mid;
while(first
{
mid=(first+last)/2;
if(a[mid]>a[last])
{
first=mid+1;
}
else
{
last=mid;
}
}
return first;
}
Q. No. :
20
Question :
You have been given a linked list of numbers.
The size is not know. You need to find out if the number stored
in the list is a palindrome in the best possible optimized manner.
main()
{
int n;
int ret_val=FALSE;
node_type *head;
printf("Give the number of node\n");
scanf("%d",&n);
head=create_link_list(n);;
print_link_list(head);
hroot=head;
ret_val=check_palindrome(head);
printf("ret_val=%d\n",ret_val);
How to find an element in rotated sorted array?
Input 1: array[]={4,5,6,7,8,9,1,2,3}; element=5
Output : position of the element(=5) is 1 (array starts from zero).
Input 2: array[]={1,2,3,4,5,6,7,8,9}; element=7
Output : position of the element(=7) is 6 (array starts from zero).
#include
int find_element_position(int *a, int first , int last , int element);
main()
{
int a[10]={3,4,5,6,7,8,9,1,2};
int pos;
int element;
printf("Give the element\n");
scanf("%d",&element);
pos=find_element_position(a,0,8 ,element);
printf("The smallest element=%d position is %d\n",element , pos);
}
int find_element_position(int *a, int first , int last , int element)
{
int mid;
int pos = -1;
while(first
{
mid=(first+last)/2;
if(a[mid]>element && a[first]<=element)
{
last=mid-1;
}
else
{
first=mid;
}
}
if(a[first]==element)
pos=first;
if(a[last]==element)
pos=last;
return pos;
}
GROUP BY is a way by which we tell the DBMS, to group the retrieved records based on one or more columns so that an aggregate function can be performed on every group of rows.
Q. No. :
23
Question :
Swap two numbers without using a temporarily variable.
use fork() or vfork() to create process on unix.
to terminate process send a kill signal , kill(pid, sigID)
Q. No. :
25
Question :
write a program that accepts two mandatory arguments without using any built in date or time functions . The first argument is a string "[HH:MM {AM|PM}" and the second argument is an integer Which denotes minutes. The minutes get added to the string. The return value or output of the program should be a string of the same format as the first argument. For example AddMinutes("10:23 AM", 13) would return "10:36 AM
Easy question But keep boundary condition in mind.
let from first argument we get hh, mm and meridian = {AM = 0, PM = 1}. from second argument we get x the minutes to be added.
1. mm = (mm+x)%60;
2. hh = ((mm+x)/60+hh)%24
3. if (hh > 12) { meridian = 1-meridian; hh %= 12;}