InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 251. |
The function `f : N->N` given by `f(n)=n-(-1)^n` isA. one-one and intoB. one-one and ontoC. many-one and intoD. many-one and onto |
|
Answer» Correct Answer - A We have, `f(n)=n(-1)^(n)={{:(,n-1,"if n is even"),(,n+1,"if n is odd"):}` Injectivity Let n, m be any two even natural number. Then, `f(n)=f(m) Rightarrow n-1=m-1Rightarrow m` If n, m are any two odd natural numbers. Then, `f(n)=f(m) Rightarrow n+1=m+1 Rightarrow n=m` Thus, in both the cases, we have `f(n)=f(m)Rightarrow n=m` If n is even and m is odd, then `n ne m`. Also, f(n) is odd f(m) is even. So, `f(n)nef(m)` `"Thus", n ne m Rightarrow f(n) ne f(m)` So, f is an injective map. Surjectivity Let n be an arbitary natural number. If n is odd natural number, then there exists an even natural number n+1 such that `f(n+1)=n+1-1=n` If n is an even natural number, then there exists an odd natural number (n-1) such that `f(n-1)=n-1+1=n` Thus, every `n in N` has its pre-image in N`. So, `f: N to N is a surjection`. Hence, `f:N to N` is a bijection. |
|
| 252. |
Let `f(x)=x^2`and `g(x)=2^x`. Then the solution setof the equation `fog(x)=gof(x)`is`R`(b) {0} (c) {0, 2} (d) none of theseA. RB. {0}C. {0,2}D. None of these |
|
Answer» Correct Answer - C We have `f(x)=x^(2) and g(x)=2^(x)` `therefore fog(x)=g of (x)` `Rightarrow f(g(x))=g(f(x))` `Rightarrow f(2^(x))=g(x^(2))` `Rightarrow (2^(x))^(2)=2^(x^(2))` `Rightarrow 2^(2x)=2^(x^(2))Rightarrow 2x=x^(2) Rightarrow x(2-x)=0Rightarrow x=0,2` |
|
| 253. |
Let `A={x: 0 le x lt pi//2} and f:R to A` be an onto function given by `f(x)=tan^(-1)(x^(2)+x+lambda)`, where `lambda` is a constant. Then,A. `lambda gt 0`B. `lambda ge 1//4`C. `lambda lt 1//4`D. `0 le lambda le 1` |
|
Answer» Correct Answer - B Since, `f:R to A ` is an onto functions. Therefore Range of f=A. `0 le f(x) le (pi)/(2)" " "for all "x in R` `Rightarrow 0 le tan^(-1) (x^(2)+x+lambda) le pi//2" " "for all "x in R` `Rightarrow 0 le x^(2)+x+lambda le oo " " "for all "x in R` `Rightarrow x^(2)+x+lambda ge 0" " "for all "x in R` `Rightarrow 1-4lambda le 0 Rightarrow lambda ge (1)/(4)" " "for all "x in R` |
|
| 254. |
Which of the following functions from Z to itself are bijections? aA. `f(x)=x^(3)`B. `f(x)=x+2`C. `f(x)=2x+1`D. `f(x)=x^(2)+x` |
| Answer» Correct Answer - B | |
| 255. |
Explain ceil(x) in python. |
|
Answer» ceil(x) Description : The method ceil( ) returns ceiling value of x-the smallest integer not less than x. Syntax: Following is the syntax for ceil() method import math math.ceil(x) Note: This function is not accessible directly so we need to import math module and then we need to call this function using math static object. Parameters : x—This is a numeric expression. Return Value : This method returns smallest integer not less than x. Example: # !/usr/bin/py thon import math # This will import math module print “math.ceil(-45.17):”, math.ceil(-45.17) print “math.ceil(100.12):”, math.ceil(100.12) print “math.ceil(100.72):”, math.ceil(100.72) print “math.ceil(119L):”, math.ceil(119L) print “math.ceil(math.pi):”, math.ceil(math.pi), This will produce the following result math.ceil(-45.17) :-45.0 math.ceil(100.12): 101.0 math.ceil(100.72): 101.0 math.ceil(119L): 119.0 math.ceil(math.pi): 4.0 |
|
| 256. |
Explain Namespaces and Scoping. |
|
Answer» Variables are names (identifiers) that map to objects. A namespace is a dictionary of variable names (keys) and their corres-ponding objects (values). A Python statement can access variables in a local namespace and in the global namespace. If a local and a global variable have the same name, the local variable shadows the global variable. Each function has its own local namespace. Class methods follow the same scoping rule as ordinary functions. Python makes educated guesses on whether variables are local or global. It assumes that any variable assigned a value in a function is local. Therefore, in order to assign a value to a global variable within a function, you must first use the global statement.The statement global VarName tells Python that VarName is a global variable. Python stops searching the local namespace for the variable. |
|
| 257. |
Describe Random numbers function in Python with example. |
|
Answer» Description : The method random( ) returns a random float r, such that 0 is less than or equal to r and r is less than 1. Syntax: Following is the syntax for random() method random() Note : This function is not accessible directly so we need to import random module and then we need to call this function using random static object. Parameters: NA Return Value : This method returns a random float r, such that 0 is less than or equal to r and r is less than 1. Example: The following example shows the usage of random() method. #!/usr/bin/python import random # First random number print “random(): “, random.random() # Second random number print “random(): “, random.random() This will produce the following result: random(): 0.281954791393 random(): 0.309090465205 |
|
| 258. |
Explain “The returnStatement” with example. |
|
Answer» The statement return [expression] exits a function, optionally passing back an expression to the caller. A return statement with no arguments is the same as return None. All the above examples are not returning any value, but if you like you can return a value from a function as follows : #!/usr/bin/py thon # Function definition is here def sum(arg1,arg2): # Add both the parameters and return them. ” total=arg1+arg2 print “Inside the function : “, total return total; # Now you can call sum function total=sum(10,20); print “Outside the function total This will produce the following result: Inside the function : 30 Outside the function : 30 |
|
| 259. |
When we can execute a function? |
|
Answer» Once the basic structure of a function is finalized, we can execute it |
|
| 260. |
Define functions calling with example. |
|
Answer» Defining a function only gives it a specific name, specifies the parameters that are to be included in the function, and structures the blocks of code. Once the basic structure of a function is finalized, you can execute it by calling it from another function or directly from the Python prompt. Following is the example to call printme( ) function: # !/usr/bin/py thon # Function definition def printme(str): “This prints a passed string into this function” print str; return; # Now you can call printme function printme (“I’m first call to user defined function!”); printme (“Again second call to the same function”); This will produce the following result: I’m first call to user defined function! Again second call to the same function |
|
| 261. |
How to generate random numbers in Python ? |
|
Answer» The standard module random implements a radom number generator. *’ There are also many other in this module, such as : uniform(a, b) returns a floating point number in the range [a, b]. randint(a, b) returns a random integer number in the range [a, bj. random() returns a floating point number in the range [0,1]. Following code snippet show usage of all the different functions, evertime it is executed. import random i = random.randint (1, 99) # i randomly initialized by integer between range 1 and 99. j = random randient (1,99) # j randomly initialized by float between range 1 and 99. k = random.random() # k randomly initialized by float between range 0 and 1 Print (“i.”, i) Print (“j.”,j) Print (“k.”, k) _______________ Output: (‘i:’, 64) (‘j:’ 701.85008797642115) (‘k:’: 0.18173593240301023) Output: (‘i:’,83) (‘j:’,56.817584548210945) (‘k:’; 0.9946957743038618 |
|
| 262. |
How can we pass optional or keyword parameters from one function to another in Python ? |
|
Answer» Gather the arguments using the * and ** specifiers in the function’s parameter list. It gives us positional arguments as a tuple and the keyword arguments as a dictionary. Then we can pass these arguments while calling another function by using # and ** def funl (a, *tup, ** keyword.Arg): keyword Argj’width’j = ‘23.3c’ fun2 (a, *tup, **keywordArg) |
|
| 263. |
The value passed at the time of calling a function is known as:(a) Variables(b) Constants(c) Arguments(d) None of these |
|
Answer» Correct option is (c) Arguments |
|
| 264. |
WAP to demonstrate a function declaration, function calling and function definition. |
|
Answer» Program: #include<stdio.h> Output: |
|
| 265. |
What is the use of lambda keyword in Python? |
|
Answer» You can use the lambda keyword to create small anonymous functions. |
|
| 266. |
Can First statement of a function be optional? |
|
Answer» Yes, The first statement of a function can be an optional statement. |
|
| 267. |
What is the use of EXP function? |
|
Answer» EXP function is used to return the exponential value of the argument. |
|
| 268. |
Write any Python expression which is a valid input argument to the following program? input = eval(raw_input(‘Value:’)) print ‘You typed’, value |
| Answer» This program valid input argument is 'one' | |
| 269. |
Give the usage of the mathematical function sqrt() |
|
Answer» sqrt() is a mathematical function that returns the square root of the given “num” value. Syntax to find the Square root: float sqrt( float num); |
|
| 270. |
What are character functions? Name the header file for character functions. |
|
Answer» Character functions are functions used for the process of a character enclosed in single quotes. The ctype.h is the header for character functions. |
|
| 271. |
Give the usage of the mathematical function exp(). |
|
Answer» exp() is a mathematical function that returns the natural logarithm base “e” raised to the argument’s power. Syntax to find exponential value: float exp( float num); |
|
| 272. |
Give the usage of the mathematical function pow(). |
|
Answer» pow() is a mathematical function that returns the “base” value raised to the “exp” power. Syntax to find power of a number: float pow (float base, float exp); |
|
| 273. |
What do you mean by function in ‘C’?OrWhat is the library function in ‘C’? Explain. |
|
Answer» Introduction: Sometimes, to perform a particular task in a program, you may have to write another program which may be a very cumbersome process. Functions are very useful to read, write, debug and modify complex programs. They can also be easily incorporated in the main program. In ‘C’ language, main() itself is a function that means the main function is invoking the other functions to perform various tasks. There are two types of functions:
1. Built-in Functions/Library Functions: These are the pre-defined routines that are included as an integral part of the language. Each function is accessed simply by stating its name, followed by whatever information must be supplied to the function, enclosed in parentheses (A numeric quantity or a string that is passed to a function in this manner is called an argument). Library functions are also called standard functions or elementary functions. These functions provide a quick and easy way to evaluate many mathematical functions and to carry out certain logical operations. There are several library functions in ‘C’ Language. Basic Library functions are of two types:
2. User-defined Functions: This feature allows you to define functions within a program, which you can call whenever you need them. While running the program (FUNC) statement can save space as well time, as a complex calculation can be defined with a short name and called up by its name where needed. |
|
| 274. |
What are user-defined functions? Explain with example. |
|
Answer» User-defined Functions: This feature allows you to define functions within a program, which you can call whenever you need them. While running the program (FUNC) statement can save space as well as time, as a complex calculation can be defined with a short name and called up by its name where needed. main() Output: |
|
| 275. |
What is the status of ‘C’ language? Why is ‘C’ language so popular in the software world? Explain.OrWhy is ‘C’ a very popular language? Explain with suitable example. |
|
Answer» Programming Language is a set of instructions and keywords which help a user to communicate with the computer. The ‘C’ programming language was developed by Dennis Ritchie in Bell Telephone Laboratories, in the early 1970s. Ken Thompson and his team supported him in developing this language. In the late seventies, ‘C’ began to replace the more familiar languages of that time like PL/I, ALGOL, etc. In less than a decade of its introduction, ‘C’ has become a language of choice for software professionals because it is reliable, simple and easy to use. The UNIX operating system was written in ‘C’ language. One of the most interesting things about the ‘C’ language is that its compiler is written in ‘C’. ‘C’ language is considered as a middle-level language since it was designed to have both a relatively good programming efficiency and a relatively good machine efficiency. It is a bridge between low level and high-level languages.
|
|
| 276. |
The default return type of a user-defined function is:(a) void(b) float(c) char(d) int |
|
Answer» Correct option is (a) void |
|
| 277. |
What is the other name of the pre-defined function? |
|
Answer» The pre-defined function is also known as built-in function. |
|
| 278. |
Which of the following is short-cut for ‘Save’ operation?(a) Control + P(b) Control + S(c) Control + N(d) Control + F |
|
Answer» Correct option is (b) Control + S |
|
| 279. |
A loop within a loop is known as …….. |
|
Answer» A loop within a loop is known as Nested loop. |
|
| 280. |
Language used to design web pages is:(a) C++(b) BASIC(c) HTML(d) JAVA |
|
Answer» Correct option is (c) HTML |
|
| 281. |
Who developed ‘C’ language? |
|
Answer» Dennis Ritchie and Ken Thompson. |
|
| 282. |
What do you mean by module ? |
|
Answer» A module allows you to logically organize your Python code. Grouping related code into a module makes the code easier to understand and use. A module is a Python object with arbitarily named attributes that you can bind and reference. Simply, a module is a file consisting of Python code. A module can define functions, classes, and variables. A module can also include runnable code. |
|
| 283. |
What are Generator Functions ? |
|
Answer» A generator function or generator method is one which contains a yield expression. When a generator function is called it returns an iterator. Values are extracted from the iterator one at a time by calling its_next_( ) method. At each call to_next_( ) the generator function’s yield expression’s value (None if none is specified) is returned. If the generator function finishes or executes return a Stop Iteration exception is raised. Generators provide an elegant way to write simple and efficient code for functions that return a list of elements. Based on the yield directive, they allow you to pause a function and return an intermediate result. The function saves its execution context and can be resumed later if necessary. |
|
| 284. |
What do you mean by globals() and locals () Functions |
|
Answer» The globals( ) and locals( ) functions can be used to return-the names in the global and local namespaces depending on the location from where they are called. If locals() is called from within a function, it will return all the names that can be accessed locally from that function. If globals() is called from within a function, it will return all the names that can be accessed globally from that function .The return type of both these functions is dictionary. Therefore, names can be extracted using the keys() function |
|
| 285. |
If the function,`f:[1,oo]to [1,oo]` is defined by `f(x)=3^(x(x-1))`, then `f^(-1)(x)` isA. `((1)/(3))^(x^((x-1)))`B. `(1)/(2){1-sqrt(1+4log_(3)x)}`C. `(1)/(2){1+sqrt(1+4log_(3)x)}`D. not defined |
|
Answer» Correct Answer - C It can be checked that f is a bijection and hence invertible. Now, `fof^(-1)=x` `Rightarrow f(f^(-1)(x))=x` `Rightarrow 3^(f^(-1)(x)(f^(-1)(x)-1))=x` `Rightarrow f^(-1)(x)(f^(-1)(x)-1)=log_(3)x` `Rightarrow (f^(-1)(x))^(2)-f^(-1)(x)-log_(3)x=0` `Rightarrow f^(-1)(x)=(1)/(2){1+sqrt(1+4 log _(3)x)}" "[therefore f^(-1)(x) ge 1]` |
|
| 286. |
The function `f:R->[-1/2,1/2]` defined as `f(x)=x/(1+x^2)` isA. surejective but not injectiveB. neither injective nor surjectiveC. invertibleD. injective but not surjective |
|
Answer» Correct Answer - A Injectivity: Let `x,y in R` be such that f(x)=f(y) `Rightarrow (x)/(1+x^(2))=(y)/(1+y^(2))` `Rightarrow x-y+xy(y-x)=0` `Rightarrow (x-y)(1-xy)=0` `Rightarrow x=y or xy=1` Putting x=2 in xy=1, we obtain y=1//2 `therefore f(2)=f((1)/(2))=(2)/(5)` So, f is not injective. Surjectivity: `"Let" y in [-1//2, 1//2]` such that `f(x)=y` `Rightarrow (x)/(1+x^(2))=y Rightarrowy+x^(2)y Rightarrow x^(2)y-x+y=0 Rightarrow x=(1+sqrt(1-4y^(2)))/(2y)` Clearly, `x in R` for all `y in [-1//2,1//2]` except y=0 We observe that f(0)-0. So, all `y in [-1//2,1//2]` has its pre-image in R. Hence, f is surjective. |
|
| 287. |
Statement-1: If A and B are two sets having 3 and 5 elements respectively, then the total number of functions that can be defined from A to B is `5^(3)`. Statement-2: A function from set A to set B relates elements of set A to elements of set B.A. 1B. 2C. 3D. 4 |
|
Answer» Correct Answer - C A function from set A to B relates every element of set A to a unique element in set B. So, each element of set A can be associated to any one of the five element in B. Conseuqently, statement-2: is not true. `therefore` Total number of functions from A to B=`5xx5xx5=5^(3)` So, statement-1 is true. |
|
| 288. |
Statement-1: If two sets X and Y contain 3 and 5 elements respectively, then `.^(5)C_(3)xx3!` one-one functions can be defined from X to Y. Statement:2: A one-one function from X to Y relates different element of set X to different elements of set Y.A. 1B. 2C. 3D. 4 |
|
Answer» Correct Answer - A A one-one functions from set X to set Y associates distinct element of X to distinct elements of Y. This can be done in `.^(5)C_(3) xx 3!` ways. Hence, `.^(5)C_(3) xx 3!` one-one functions can be defined from X to Y. So, statement-1 & 2 are true and statement-2 is a correct explanation for statement-1 |
|
| 289. |
Statement-1: Let A and B be two sets having m and n elements respectively such that `m lt n`. Then, Number of surjections from A to B `=sum_(r=1)^(n) ""^(n)C_(r) (-1)^(n-r) r^(m)` Statement-2: If `f:A to B` is a surjection, then every element in B has a pre-image in A.A. 1B. 2C. 3D. 4 |
|
Answer» Correct Answer - D Since B has more element than A. So, m elements in set A can be related to at most m elements in B. Consequently, remaining (n-m) elements in B will not have their pre-images in A. So, it is not possible to define an onto function from A to B. Hence, statement-1 is a false. However, statement-2 is true. |
|
| 290. |
What is Numeric function? |
|
Answer» The numeric function works on numeric values. |
|
| 291. |
What is argument? |
|
Answer» The value we pass in a function at the time of its calling is known as an argument. |
|
| 292. |
Define SQR function with example. |
|
Answer» SQR(X): function returns the square root of its argument which should never be negative. #include<stdio.h> Output: 2 |
|
| 293. |
Define ABS function with example. |
|
Answer» ABS(X): This function gives the absolute value of X. The absolute value of a constant is always independent of its sign le., it is always positive. #include<stdio.h> Output: 20 20.23 18.5 |
|
| 294. |
Range of the function `f(x)=sin^(-1)x+2tan^(-1)x+x^(2)+4x+3` isA. `[ pi , pi+8]`B. `[-pi-2 , pi+8]`C. `[-pi+2 , pi+8]`D. `[-p+4 , -pi+6]` |
|
Answer» Correct Answer - A |
|
| 295. |
What is the advantage of radians(x) ? |
|
Answer» It converts angle x from degrees to radians. |
|
| 296. |
What value will be return by random() ? |
|
Answer» Return the next random floating point number in the range (0.0,1.0). |
|
| 297. |
If log (5x – 9) – log (x + 3) = log 2, then x = ..... (A) 3(B) 5(C) 2(D) 7 |
|
Answer» (B) 5 log (5x – 9) – log (x + 3) = log 2 \(\therefore\frac{5x-9}{x+3}=2\) \(\therefore\) 3x = 9 + 6 \(\therefore\) 3x = 9 + 6 \(\therefore\) x = 5 |
|
| 298. |
If `f(x)=log_(e)((1-x)/(1+x)),|x| lt 1, " then " f((2x)/(1+x^(2)))` is equal toA. `2f(x)`B. `2f(x^(2))`C. `(f(x))^(2)`D. `-2f(x)` |
|
Answer» Correct Answer - A Given, `f(x)-log_(e)((1-x)/(1+x)),|x| lt 1,` then `f((2x)/(1+x^(2)))=log_(e)((1-(2x)/(1+x^(2)))/(1+(2x)/(1+x^(2)))) " "[ because |(2x)/(1+x^(2))| lt 1]` `=log_(e)(((1+x^(2)-2x)/(1+x^(2)))/((1+x^(2)+2x)/(1+x^(2))))=log_(e)(((1-x)^(2))/((1+x)^(2)))=log_(e)((1-x)/(1+x))^(2)` `=2 log_(e)((1-x)/(1+x)) " " [ because log_(e)|A|^(m)=m log_(e)|A|]` `=2f(x) " " [ because f(x)=log_(e)((1-x)/(1+x))]` |
|
| 299. |
Define functions with example. |
|
Answer» A function is a block of organized, reusable code that is used to perform a single, related action. Functions provides better modularity for your application and a high degree of code reusing.As you already know, Python gives you many built-in functions like print( ) etc. but you can also create your own functions. These functions are called user – defined functions. Syntax: def functionname(parameters): “function_docstring” function_suite return[expression] By default, parameters have a positional behavior, and you need to inform them in the same order that they were defined. Example: Here is the simplest form of a Python function. This function takes a string as input parameter and prints it on standard screen. def printme(str): “This prints a passed string into this function” print str return |
|
| 300. |
Give an example of “choice()” |
|
Answer» The following example shows the usage of choice( ) method. # !/usr/bin/py thon import random print “choice([l, 2, 3, 5, 9]): “, random.choice([l,2,3,5,9]) print “choice(‘A String*): “, random.choice(‘A String’) This will produce the following result choice ([l, 2, 3,5,9]): 2 choice(‘A String’) :n |
|