JavaScript MCQ

JavaScript MCQ

 

 1. What are objects?

a. Set of data(number, string,etc), elements can be accessed using index(0-based)
b. Set of key-value pair, where value can be accessed using corresponding keys
c. Both a and b
d. None of these

 

 

 2. How to declare arrays in JavaScript?

 
a. let arr = [];
b. let arr = new Array();
c. Both a and b
d. None of these

 

3. Which of the following is a valid way to write condition statements?

 
a. if(condition) { do something }

b. if(condition1) { do something }
else if(condition2) { do something else }
else { do something }

c. if(condition) { do something }
else { do something else }

d. All of the above 

 

4. Which of the following is the correct loop statement?

 
a. for(initialization; conditions; increment/decrement){ do something } (correct)

b. for(initialisation; increment/decrement; conditions){ do something }

c. for(conditions; initialisation; increment/decrement){ do something }

d. None of the above

 

 

5. Which of the following data types can be used to represent large integers with arbitrary precision like 9891389374829462479629469? (Medium)

a. number
b. object
c. symbol
d. bigint

 

6. What will be the output of the below code snippet? (Medium)

let variable1 = [];
console.log(typeof variable1);

a. array
b. object
c. undefined
d. null

 

7. What is the observation made in the following JavaScript code? (Medium)
var count = [1,,3];

a. The omitted value takes “undefined”
b. This results in an error
c. This results in an exception
d. The omitted value takes an integer value 

 

8. Which of the following is not a looping statement? (Easy)

 
a. do-while
b. if-else
c. for-of
d. While


9. Which of the following is considered a first class citizen in JavaScript?(Medium)

a. Functions
b. Class
c. Array
d. Object

 

10. What will be the output of the following JavaScript code? (Medium)

 
let a=0;
for(a;a<5;a++);
console.log(a);

 
a. 4
b. 5
c. 01234
d. 012345

 

 11. What will be the output of the below code snippet? (Easy)


function add(num1, num2)[
return num1 + num2;
]
console.log(add(1,2));

 
a. 3
b. throws error
c. undefined
d. Null

 

12. Which statement cannot be used to declare a variable in JavaScript? (Easy)

a. let
b. var
c. int
d. const

 

 

13. What will be the output of the below code snippet? (Difficult)

console.log(parseInt("123Hello"));

a. error
b. 123
c. Hello
d. NaN

 

 

14. What are loops? (Medium)

a. Repeatedly run a set of statements until a specified condition evaluates to false/ or can even run it
infi
nite times.

b. It does the condition check and runs the specified block of code based on the satisfied condition.

c. Both a and b

d. None of them

 

 

15. Which of the following is the valid data type in JavaScript? (Medium)

a. number
b. boolean
c. string
d. All of the above

 

16. Which of the following is a valid function declaration syntax? (Difficult)

a. function abc() {}

b. var abc = () => {}

c.
Both a and b

d.
None of these

 

17. Guess the output of the below snippet? (Difficult)

console.log(1, 2);

a.
1 2
b. 1
2
c. error
d. None of the above

 

18. How do we add a single line comment in JavaScript? (Easy)

a. $$ This is comment
b. # This is comment
c. / This is comment
d. // This is comment (correct)\

 

19. Which of the following is the right way to declare a boolean variable in JavaScript? (Medium)

 
a. bool variable = true
b. bool variable = True
c. let variable = true
d. let variable = True

 

 

20. What is the right syntax to accept an indefinite number of parameters? (Difficult)

a. function sum(...theArgs) {
}

b. function sum(theArgs...) {
}

c. function sum(theArgs) {
}

d. function sum([theArgs]) {
}

  

21. What will be the output of the following JavaScript code? (Medium)

console.log(2=='2')
console.log(2==='2')

a. true false
b. false true
c. false false
d. true true

 

 

22. What will be the output of the following code snippet? (Difficult)

var a = true + true + true * 3;
console.log(a)

a. true
b. 0
c. 5
d. error

 

 

23. What will be the value of the variable if it is just declared? (Difficult)

var variable;
console.log(variable)

a. NaN
b. none
c. undefined (correct)
d. null 

 

 

24. How do we add multiline comments in JavaScript? (Easy)

a. ## This is the syntax to add multiline comment ##
b. /$ This is the syntax to add multiline comment $/
c. **This is the syntax to add multiline comment **
d. /* This is the syntax to add multiline comment */ 

 

 

25. What will be the output of the below code snippet?
for(let i = 1; i <= 10; i=i+2) { 

console.log(i)
}

a. 1 2 3 4 5 6 7 8 9 10
b. 2 4 6 8 10
c. 1 3 5 7 9
d. 10 




26. What are block scoped variables in JavaScript? (Medium) (crs-be-javascript)

a. The variables cannot be accessed outside the function in which they are declared.

b. The variables can be used globally.

c. The variable is only accessible inside the block(if-else/for block) inside which it is declared.

d. Both a and c



27.  JWT stands for ? and it consists of? (Easy) (crs-be-nodejs)


a. JSON Web Token, It consists of header, payload, signature.
b. JSON Web Token, It consists of header and payload
c. JSON Web Tech, It consists of header, payload, signature
d. JSON Web Tech, It consists of header and payload



28.Which of the following is the right way to add a single line comment in JavaScript?
(Medium)(crs-be-javascript)

 
a. #This is a comment

b. ##This is a comment

c. /This is a comment

d. //This is a comment.

 

 

29. Which of the following is the right way to add a multi line comment in JavaScript?
(Medium)(crs-be-javascript)

 
a. #This is a comment#

b. ##This is a comment##

c.
/*This is a comment*/

d. //This is a comment//

 

 

30. How to create a Date object in JavaScript? (easy) 

 
a. dateObj = new Date([parameters])

b. dateObj = new DateTime([parameters])

c. dateObj = new Date({parameters obj})

d. dateObj = Date([parameters])



31. Which of the following is considered a first class citizen in JavaScript?(Medium)

 
a. Functions

b. Class
c. Array
d. Object



32.

What will be the output of the following JavaScript code? (Medium) 

let a='0';
for(a;a<5;++a)
console.log(a);

 
a. 0 1 2 3 4
b. 0 1 2 3 4 5
c. 5
d. error

 

 


33.

What is destructuring in JavaScript? (Medium)

a. Through destructuring, we can unpack values from arrays or object properties into separate
variables.

b. Destructuring allows us to restructure object properties

c. Destructuring allows us to restructure array elements.

d. All of these




34.

Which statement cannot be used to declare a variable in JavaScript?
a. let
b. var
c. int
d. const

 

 

 35.

What will be the output of the below code snippet? (Difficult)

let {name, age} = {name: “abc”, age: 1, id: 1}
console.log(name, age);

a. abc 1

b. throws error

c. null null

d. undefined undefined




36.

 What will be the output of the below code snippet? (Difficult

 
console.log(parseInt("Hello123"), parseInt("123"), parseInt("Hello"), parseInt("123Hello"));

 
a. error

b. NaN 123 NaN 123

c. 123 123 NaN 123

d. NaN 123 NaN NaN




37.

What are loops? (Medium)

 
a. Repeatedly run a set of statements until a specified condition evaluates to false/ or can even run it infinite times.

b. It does the condition check and runs the specified block of code based on the satisfied condition.

c. Both a and b

d. None of them




38. What is the worst case time complexity of searching an element in an array using linear search? (easy)

 a. O(logn)
b. O(n)
c. O(1)
d. O(n2)

 

39. What is the correct syntax for destructuring arrays in JavaScript? (Medium)

 
a.
const [a, b, ...rest] = [1, 2, 3, 4, 5]
b. const {a, b, ...rest} = [1, 2, 3, 4, 5]
c. const a, b, ...rest = [1, 2, 3, 4, 5]
d. None of these.

 

 

 40. Which array method is used to iterate on all the array elements and perform some task/transformation

 
on them and return the new array? (Medium)(crs-be-javascript)
a. map
b. reduce
c. foreach
d. filter

 

41. Which of the following sorting algorithms would give the best time complexity if the given array is already sorted? (Medium)

a.
Insertion Sort
b. Quick Sort
c. Merge Sort
d. All of these

 

42.

What will be the output of the below code snippet? (Medium)

let numbers = [1,2,3,4,5,6,7,8]; 

numbers.splice(2, 4, 4)

console.log(numbers.filter(x => x%2 == 0));

a. [2, 4, 6]
b. [2, 4, 8]
c. [1, 3, 5, 7]
d. [2, 4, 6, 8]

 

 

43.

 JavaScript is a ________ language?

Assembly level
Machine level
client side scripting    (correct)
High level

Explanation
JavaScript source code is processed by the client's web browser rather than the web server




44.
avaScript is a ________ language?



Assembly level
Machine level
client side scripting    (correct)
High level

Explanation
JavaScript source code is processed by the client's web browser rather than the web server








45.
What is the correct tag used to add javascript code in an HTML Document?



<javascript>
<script>    (correct)
<js>
None of these

Explanation
The <script> tag is used to embed a client-side script. Hence it is used to define the JavaScript code.





46.
Which company developed JavaScript?


NetScape (correct)
Sun MicroSystems
IBM
Oracle

Explanation
JavaScript was written by Brenden Eich, an engineer at NetScape in 1995.









47.
let var = ["a", "b", "c","d"]; var.push("e"); console.log(var); What is the output of the above code?


e, a,b,c,d
a,b,c,d,e     (correct)
a,b,e,c,d
Error

Explanation
The Push() method pushes a new value to the end of the array







48.


Which of the following is not true about the Unshift() method?


A) Increments the length of the array by 1
B) Adds new element to the beginning of the array
C) Prints value from the 2nd element (correct)
D) All the above

Explanation
This method is used to add elements to the front of the array, and increases the index of every element by one.








49.


Consider the code snippet var a = [ 1,2,3,4,5,6] slice(0,3) returns which of the following?


[1,2,3] (correct)
[1,2,3,4]
[5,6]
[4,5,6]

Explanation
The array is sliced from the begin index till the end index (end index excluded)






50
Consider the following code : total = 1 let num1 = [1, 2, 3,]; let num2 = num1.reduce(output); function output(total, value) { return total * value; } console.log(num2) What is the output of the above code?


1
6 (correct)
[1,2,3]
Error


Explanation
The reduce function is run on each element of the array to get the single output value.




51.
Which of the following is the correct syntax for a while loop in Javascript?



while ( i < 10 , i++)
while ( i = 1 to 10 )
while ( i =1, i<10, i++)
while ( i<=10)         (correct)

Explanation
The while loop iterates over and executes the piece of code, as long as the condition is true








52.
Which of the following is not an entry controlled loop?


For loop
While loop
Do-while loop    (correct)
For- in loop

Explanation
This do-while loop is an exit controlled loop that checks the condition at the end of the code.




53.
What is the output of the code snippet? function range(int length) { int a=5; for(int i=0;i


5
555 (correct)
3
Error

Explanation
The for loop is executed three times and displays the value of "a" thrice.



54.
Wh
ich of the following loops is used to loop through the properties of an object?

for loop
for-in loop (correct)
for-of loop
All of these

Explanation
The for-in in JavaScript loop is used to iterate over the properties of an object.



55.
What is output of the following code? var car = { fuel_type: "Diesel", get fuel(){ return this.fuel_type }, }; fuel_type = "Petrol" document.getElementById("demo").innerHTML = car.fuel;


Diesel (correct)
Petrol
Error

Explanation
Since the method refers to the fuel_type defined within the class, it returns the value Diesel



56.
What is output pf the following code? var car = { fuel_type: "Diesel", get fuel(){ return this.fuel_type }, fuel_type: "Petrol" }; document.getElementById("demo").innerHTML = car.fuel;



Diesel
Petrol (correct)
Error

Explanation
The property fuel_type is overwriiten with the new value "Petrol"





57.
What's the output of the following? var student = { x: "Hi", y: "Hello" }; x = "y" y = "x" document.getElementById("demo").innerHTML = student[x] + " " + student[y];



Hello
Hi
Hello Hi (correct)
Hi Hello

Explanation
Variable x is assigned the property y and variable y is assigned the property x.



58.
What is the output of the following? var person = { firstName: "Johny", lastName : "Depp", fullName : function() { return this.firstName + " " + this.lastName; } }; document.getElementById("demo").innerHTML = person.fullName();


Johny
Depp
Johny Depp (correct)
Error

Explanation
The function fullName concats the firstName and the lastName properties.




59.
What is the output of the following? var square = (function(x) {return x*x;}(5));


25
5
Warning
Error

Explanation
The code works perfectly and the function returns the square of the number







60.
What does the following code result in when executed? var total=eval("10*5+5"); console.log(total)


10*5+5
55 as a string
55 as an integer (correct)
Error

Explanation
The eval() function evaluates the expression and returns the value




61.
Which of the following is not a predefined function?


eval()
map()
parseInt()
func() (correct)

Explanation
There is no such function with a predefined action to perform. However it can be a user-defined function.




62.
What is the output of the following? function area(radius) { function square(x){ return x*x } return Math.PI*(square(radius)) } x = area(5) document.write(x)



78.5 (correct)
25
5
Error

Explanation
The inner function returns the square of the radius and the outer function returns the area
by multiplying it with the value of PI




63.
Which of the following variables takes precedence over the others if the names are the same?

SELECT THE CORRECT ANSWER
Global variable
The local variable(correct)
None

Explanation
If the global and the local variables have the same name,
the global variable becomes inaccessible to the function giving precedence to the local variable.




64.
What is the output of the following? var b = 10 function function_Name(){ var b = 20; document.write(b+b) } function_Name()


20
30
40 (correct)
Error

Explanation
Since the function accesses the local variable b, the sum is 40.



65.

Which of the following is not true about closures?

SELECT THE CORRECT ANSWER
It has access to the variables of its scope.
It has access to the variables of the outer functions.
Has access to the global variables.
Defines the end of the function (correct)

Explanation
Closure doesn't define the end of a function. It only defines how the variables are accessed within functions




66.
What is the output of the following code? var a = 100 function Func1() { var b = 200; function Func2() { var c = 200+a+b return c } return Func2(); } var total= Func1() document.write(total)



500 (correct)
200
300
400

Explanation
The inner function can access all the variables a,b and c. Hence, the sum of the values is returned





67.

What is the output of the following code? var p = new Promise((resolve, reject) => { reject(Error('The Fails!')) }) p.catch(error => console.log(error.message)) p.catch(error => console.log(error.message))



Prints the message twice (correct)
Prints the message once
No output
Error message

Explanation
Multiple handler callbacks are added and each will be called with the same arguments.



68.
Which of the following is not an asynchronous programming concept?


Async-Await
Callbacks
Objects (correct)
Promises

Explanation
Objects are a collection of properties. Callbacks,
Promises and Async--Await are asynchronous programming concepts that make execution more efficient




69.
Which of the following is not a state governing promises?



Fulfilled
Rejected
Pending
Returned (correct)

Explanation
A Promise is pending when created and if a promise is fulfilled, then some piece of code must be executed. And if it's rejected,
then error handling must be performed. There is no such state as returned



70.
Which of the following is NOT TRUE about the then() callback method?



Then() method is called when the promise is fulfilled
Then() method is called when the promise is invoked
Then() method is called when the promise is rejected
Both B and C (correct)

Explanation
The Then() method only executes when the promise is fulfilled or resolved.



71.
Which of the following is true about synchronous programming?


SELECT THE CORRECT ANSWER
Ensures sequential execution of code
Execution halts if a function is waiting for data or resources
Could be time consuming
All the above (correct)

Explanation
Synchronous programming executes code one after the other and waits for
the execution of a piece of code before moving to the next.
As a result, it can be time consuming.







72.
What is the output of the following code? function My_function(){ var value = 100; alert(this.value) } My_function()


100
Undefined (correct)
Error

Explanation
Since the function is called from the global scope, the this keyword will access the global variable.
Since there's no global variable named value, it is undefined






73.
What is the ouput of the following? var value = 50 function My_function(){ var value = 100; alert(this.value) }


100
50 (correct)
Undefined
Error

Explanation
Since the function is called from the global scope, the this keyword will access the global variable.
Since there's no global variable named value, it is undefined
 


74.
What is the output of the following? var x = 50 function My_function(){ var x = 100; x+=10 alert(x) alert(this.x) }



100 and 110
110 and 50 (correct)
110 and 100
50, 110

Explanation
The value of x is 110. However, the this keyword accesses the global variable x and displays 50



75.
What is the output of the following? message = "Hello" const random = { message: ["JavaScript", "is", "awesome"], info(){ this.message.forEach(function(tag){ document.write(tag + " ") },this) } } random.info()


Hello
JavaScript
JavaScript is awesome (correct)
Error

Explanation
Since the forEach function takes "this" as a parameter, it references the current object random.
Hence all the values of the message property within the object are displayed.




76.
What is the purpose of the basic validation?


Data correctness
Data existence (correct)
Both Data correctness and existence
Data modification


Explanation
Basic Validation warrants that all the mandatory fields are filled




77.
Which of the following is used to focus on an element?



focus() (correct)
focusOn()
focusAt()
focusFrom()

Explanation
focus() method focuses on a particular html element





78.
Which of the following is not a form attribute?



action
method
data     (correct)
id

Explanation
Action, methos and id are valid form attributes



79.
What is the purpose of data format validation?



Data correctness (correct)
Data existence
Both Data correctness and existence
Data modification

Explanation
Data validation checks the data for its correctness.
Your code must include appropriate logic to test the accuracy of data





80.
Which of the following patterns matches the regular expression "a*b?"



aaab
aaa
aaabbb
OptionA and OptionB (correct)

Explanation
The "?" indicates either one or no occurance of the character and the * indicates zero or
more occurances of a character



81.
What is the output of the following? System.out.println(Pattern.matches("[^a-z]", "abcd"));



TRUE
FALSE (correct)
Undefined

Explanation
The expression matches with strings that do not contain the lowercase alphabet




82.
Which of the following is not a quantifier



*
?
+
()    (correct)

Explanation
Parantheses are not quantifiers






83.
Which of the following is not a valid match to the regular expression "\d*\.\d\d"


1.23
123.44
11.23
1.234 (correct)

Explanation
The string can have any number of digits before the decimal point but only digits after the deciman point




84.
Which of the following is not a valid email ID?



my_websiteskyhi@com         (correct)
my_website@skyhi.co.in
my_website@skyhi.co.net


Explanation
The ID does not contain a domain name






85.
How is data treated in the HTML DOM?


SELECT THE CORRECT ANSWER
Attributes
Nodes     (correct)
Elements
Arrays

Explanation
The HTML DOM is a tree structure with objects stored in the form on nodes



86.
Which of the following is defined by the HTML DOM?



Objects
Properties
Methods
All of the above (correct)

Explanation
HTML DOM is programming interface which define the objects, properties, methods and events




87.
Which of the following window objects is used to open a new browser window with a specified URL?


createWindow()
open()
Window.open()    (correct)
All of the above

Explanation
Window.open() loads a specified URL into a new or existing window and
returns the Window object that represents that window.



88.
Cookies are used to store user data in small text format so that the page "remembers" it for later use


TRUE (correct)
FALSE

Explanation
Cookies are used to store information about the use





89.
Which of the following APIs is used to get resources?



fetch    (correct)
map
retrieve

Explanation
The Fetch API provides an interface for fetching resources








90.
Which of the following is not a JavaScript framework or a library?



Electron
Vue
React Native
Django    (correct)

Explanation
Django is a python framework used for web app development.






91.
What does the getDay() method return?



Current day of the week
Day of the week for the specified date (correct)
Default day
Returns an error


Explanation
The getDay() method returns the day of the week for the specified date








92.
Which of the following is not used for front-end development?



React Native
Flutter
HTML
Flask (correct)

Explanation
Flask is used for backend development






93.
Git is a version control system used to keep track of a project


TRUE  (correct)
FALSE

Explanation
Git is a version control system used to keep track of a project.






94.
Which of the following is a responsibility of a Full Stack developer?



Developing front-end architectures
Design the backend of an application
Creating servers and databases
All the above        (correct)


Explanation
A Full Stack developer must develop front-end architectures,
design the backend of an application and create databases for the developed app.





95.
jQuery is JavaScript library that helps with things like Ajax calls and DOM manipulation



TRUE (correct)
FALSE


Explanation
jQuery simplifies a lot of the complicated things from JavaScript, like AJAX calls and DOM manipulation.




96.

If we have to update our password, what HTTP method should we use ?

    1. GET

    2. PUT

    3. POST

    4. UPDATE

       

       

       






  1.  Express is flexible ______ web application framework .

    1. Node.js

    2. React.js

    3. Angular.js

    4. Golang

       

  2. Which of the following express.js features .

    1. Allows to create middlewares

    2. AllDefines routing tables

    3. None of these

    4. Both a and b

       

  3. What function arguments are available to Express Route handlers .

    1. Request Object

    2. Response Object

    3. Next()

    4. All of these

       

  4. What middleware do we use for custom logging in express.js .

    1. Morgan

    2. Cors

    3. Logger

    4. Log4j

       

       

  5. What does [^abc]  regex represent .

    1. Any character without a, b and c

    2. Any character without a, but has b and c

    3. Any character with a, b and c

    4. List of characters without a, b and c





 

 

 

 

 

 

MCQ(10 mins)


1)Which approach is used in merge sort?


Options:


a)Divide and conquer

b)Backtrack

c)Greedy approach

d)Heuristic approach


Ans:a


2)What is the number of comparisons required for merging two sorted lists of size m and n into a new list


O(m)

O(m+n)

O(n)

O(log(m+n))

 

 

 


Ans:b




3)When is a sorting technique called stable?


Takes O(N) space complexity

Use greedy approach

Takes O(N) time complexity

Maintains the relative order of occurrence of non distinct elements





Ans:d




4)Which approach of selecting a pivot element is the worst?

Options:


a) mid element
b) last element
c) median-of-three partitioning
d)  first element 

 

 


Ansr: d 









5)Which one of the below is the best method to choose a pivot element?

Options:

a) choosing a random element as pivot
b) choosing the first element as pivot
c) choosing the last element as pivot
d) median-of-three partitioning method

 

 

 

 

 


Ans: d

 

 

 

 

 

 

 

 

 

 

 

MCQ 


  1. Which of the below sorting algorithms is fastest?
    a) Merge sort
    b) Quick sort
    c) Insertion sort
    d) Shell sort

Answer: b

  1. Which one of the below is the best method to choose a pivot element?
    a) choosing a random element as pivot
    b) choosing the first element as pivot
    c) choosing the last element as pivot
    d) median-of-three partitioning method

Answer: d

  1. Which approach of selecting a pivot element is the worst?
    a) mid element
    b) last element
    c) median-of-three partitioning
    d)  first element 

Answer: d


    4) What is the average time of a quick sort algorithm?
           O(N2)
           O(N)
             O(N log N)
             O(log N)

Answer: c



5. How many sub-arrays can the quick sort algorithm split the entire array into?
a) one
b) two
c) three
d) four

Answer: b.

 

 

 

 

 

MCQs 

1. Which class does Binary Search belong to? 

A Greedy Algorithms 

 Dynamic Programming 

 Divide and Conquer [Answer] 

All of the above. 

Answer: C 

 

2. For which of the following inputs binary search can be applied in the entire array? A. [3,4,5,1,2] 

B. [5,6,7,8,1] 

C. [4,2,1,8,9] 

D. [2,4,5,6,8] 

Answer: D 

 

3. Time Complexity of Binary Search can be best represented by [logKn represents log of n to the base K] A. O(log2n)  

B. O(log3n) 

C. O(n) 

D. O(log5n) 

Answer: A 

 

4. Binary Search can be applied on any kind of array? 

A. Depends on size of Input. 

B. True 

C. False 

D. None of the above 

Answer: C (Binary Search can be applied only on monotonic sequences) 

 

5. Time Complexity of Linear Search can be best represented as 

A. O(1) 

B. O(n^2)  

C. O(n) 

D. O(n^3) 

Answer: C

 





MCQ’s


1.What is the best time complexity of bubble sort?

  1. n^2

  2. Nlogn

  3. n

  4. n(logn)^2

 Answer - c

2.  What is the best time complexity of insertion sort?

  1. n^2

  2. Nlogn

  3. N

  4. n(logn)^2

Answer-c

3. What is the best time complexity of selection sort?

  1. n^2

  2. Nlogn

  3. N

  4. n(logn)^2

Answer-a 

4. Which of the following is an inplace algorithm?

  1. Selection Sort

  2. Bubble Sort

  3. Insertion Sort

  4. All of the above

Answer-d

5. Which of the following sorting algorithms is not stable?

  1. Selection Sort

  2. Bubble Sort

  3. Insertion Sort

  4. All of the above

Answer-a

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Question 1.The aggregate number of external nodes in a full binary tree with n internal nodes is equivalent to?

a) 2n - 1

b) n+1 

c) 2n + n

d) 2n + 1


Question 2: Which amongst the following master theorem fails to execute

a.    T(n) is not monotone. eg. T(n) = sin n

b..    f(n) is not a polynomial. eg. f(n) = 2n

c..    a is not a constant. eg. a = 2n and a < 1

d.     All of the above


Question 3: what is the time complexity of func()?

 int  func(int a){

        int counter = 0;

        for (int i = 0; i < a; i++){

            for (int j = i ;  j >0 ; j--){

                counter = counter + 1;

            }

        }

        Return counter;

}

  1. Theta(a)

  2. Theta(a2 )

  3. Theta (a log a)

  4. None of these


Question 4: What is time complexity of timeComplexity()?

int timeComplexity(int num)

{

  int count = 0;

  for (int iterator = num; iterator > 0; iterator /= 2)

     for (int second_iterator = 0; second_iterator < iterator; second_iterator++)

        count += 1;

  return count;

}


  1. O(n ^3)

  2. O(n log n)

  3. 3. O(log n^2)

  4. 4. O(n)



Question 5: 

What is the recurrence relation for 1, 7, 31, 127?

a) bn+1=5bn-1+3

b) bn=4bn+7!

c) bn=4bn-1+3

d) bn=bn-1+1





Practice Questions:


  1. How will you check if 2 binary trees are equal or not ?

  2. Solve : T(n) = 2T(n/2) + nlogn using master theorem


Upcoming Class teaser 


What is Sorting

Bubble Sort

Selection Sort

Insertion Sort

Stability, Inplace property, applications and trade offs of sorting algorithms

Analysis of the above algorithms

 

 

 







1.Recursion is a method in which solution of a problem depends on ______________
    a.Larger instances of different problem
    b.Larger instances of same problem
    c.Smaller instances of different problem
    d.Smaller instances of same problem
Ans -d Smaller instances of same problem

2.Which of the following we can’t solve using recursion?
    a.Factorial of a number
    b.Length of a string
    c.Nth fibonacci number
    d.Problems without base case.
Ans - d. Problems without base case.

3.In recursion, the condition for which the function will stop calling itself __________?
    a.Base case
    b.Worst case
    c.Best case
    d.There is no such condition
Ans - a.Base Case

4.Consider the recursive function recur(n, k). You need to find the value of recur(4,3).
Pseudocode:-


    a.13
    b.8
    c.10
    d.12  

Ans -  b.8

5.The data structure used to implement recursive function calls ____________
a.Array
b.Binary tree
c.Linked list
d.Stacks

 

 

Ans - d.Stacks








MCQ Questions

  • Which of the following is FALSE about nodejs?

  • It is asynchronous.

  • npm is a must for executing nodejs codes. (CORRECT)

  • We cannot access DOM elements using nodejs

  • Nodejs has a non-blocking I/O.

  • Which of the following is the correct command to create a new nodejs project using npm?

    • npm new

    • npm create

    • node create

    • npm init (CORRECT)

  • Express is a commonly used nodejs module. Which of the following commands will install the Node.js express module?

    • npm install express (CORRECT)

    • node install express

    • install express

    • None of the above

  • Asynchronous and multithreading are the same thing.

    • True

    • False (CORRECT)

  • What is the main feature behind nodejs having non-blocking I/O?

    • Single-threaded nature.

    • Event Loop. (CORRECT)

    • V8 Engine.

    • None of the above.


 

 

 

 

 

 

MCQs:


1. _________ keyword is used to refer to an object through which they were invoked.

  1. new

  2. bind

  3. constructor

  4. this

Ans: this


2. Predict the output of below code:

    const fruit = {

  name: 'Apple',

  colourl: 'Red'

    };


console.log(fruit.colour]); 

console.log(fruit[name]);


  1. Red undefined

  2. Red Apple

  3. Red Error

  4. Error

Ans:    Red

Error


3. Which of these are used to make a method private in Js.

  1. Private keyword

  2. $

  3. _

  4. #

    Ans: #

   

    4. __proto__ is used for

  1. access the prototype property of its constructor function.

  2. instantiate the parent constructor in child class.

  3. initialise private fields in parent class.

  4. To block access to prototype properties.

    Ans: access the prototype property of its constructor function.

    5. Can we overload a static method in Js?

  1. Yes

  2. No

    Ans: Yes

 

 

 

 

 

 

 

 

 

 



MCQs:


1. Output of the code:

var p = new Promise((resolve, reject) => {

   reject(Error('The Fails!'))

 })

 p.catch(error => console.log(error.message))

 p.catch(error => console.log(error.message))


  1. Print once

  2. Print twice

  3. Exit with error

  4. No warning

Ans: Print twice



2. Output of the code:

Promise.resolve('A')

 .then(() => {

   throw Error('OMG')

 })

 .catch(error => {

   return 'Works'

 })

 .then(data => {

   throw Error('Not worked')

 })

 .catch(error => console.log(error.message))


  1. Print “OMG” and “Not worked”

  2. Print “Works”

  3. Print “OMG”

  4. Print “Not Worked”

Ans. Print “Not Worked”


3. Which of the following method is used to get value from generator-iterator objects in JavaScript?

  1. next

  2. yield

  3. done

  4. stop

Ans: next


4. Promise.all is rejected if any of the elements are rejected.

  1. True

  2. False

Ans. False


5. What will be state and value of promise p in the code.

var p = new Promise(function(resolve, reject) {

   throw "Sorry";

}).

then((data) => console.log(data), (data) => data);


  1. State: fulfilled, value: "Sorry"

  2. State: rejected, value: "Sorry"

  3. State: fulfilled, value: undefined

  4. State: rejected, value: undefined

Ans. State: fulfilled, value: "Sorry"













MCQ’s

  1. If we have to update our password, what HTTP method should we use ?

    1. GET

    2. PUT

    3. POST

    4. UPDATE

  2. If there is a Null pointer exception in server code, what response should it return?

    1. 404

    2. 302

    3. 500

    4. 201

  3. Which of the following methods has no message body?

    1. POST

    2. GET

    3. PUT

    4. DELETE

  4. Find incorrect mapping.

    1. 200 OK

    2. 400 Bad Request

    3. 402 Not Found

    4. 301 Moved Permanently

  5. If we have to configure a RESTFull url, for searching a book given its id, what will the request look like.

    1. GET /{id}/books/

    2. GET /{Id}

    3. GET /Books/{id}

    4. GET /Books?id={id1}







MCQ’s


  1.  Express is flexible ______ web application framework .

    1. Node.js

    2. React.js

    3. Angular.js

    4. Golang

  2. Which of the following express.js features .

    1. Allows to create middlewares

    2. AllDefines routing tables

    3. None of these

    4. Both a and b

  3. What function arguments are available to Express Route handlers .

    1. Request Object

    2. Response Object

    3. Next()

    4. All of these

  4. What middleware do we use for custom logging in express.js .

    1. Morgan

    2. Cors

    3. Logger

    4. Log4j

  5. What does [^abc]  regex represent .

    1. Any character without a, b and c

    2. Any character without a, but has b and c

    3. Any character with a, b and c

    4. List of characters without a, b and c





MCQ’s


  1. Which of the following is a valid data type of the data that can be stored in the database.


  1. Text Data   

  1. Image Data

  1. Audio Data

  1. All of the above


Answer: d) All of the above



  1. How data is stored in DBMS.


  1. Graph

  1. Images

  1. Tables

  1. None of these


Answer: c) Tables



  1. Which database should be preferred while using Object Oriented Programming Language?

  1. Centralized database

  2. Distributed Database

  3. Object Oriented Database

  4. Cloud database


Answer: c) Object Oriented Database


  1. RollBack and Commit comes under which language.


  1. Data Control Language (DCL)

  2. Transaction Control Language (TCL)

  3. Data Query Language (DQL)

  4. Data Definition Language (DDL)


Answer: b) Transaction Control Language (TCL)


  1. What type of strings are selected when using LIKE with ‘%A_’;


  1. String with first character as A

  2. String with second character as A

  3. String with last character as A

  4. String with second last character as A



Answer: d) String with second last character as A










MCQ (10 Mins)

1) Select the syntax of Single Line Comment.

  1. .

  2. !

  3. --

  4. #

Answer: C) –


2) Select the Aggregate function(s) among the following.

  1. AVG()

  2. FIRST()

  3. LAST()

  4. All of the above

Answer: D) All of the above


3) Which function returns the largest value of the column?

  1. MIN()

  2. MAX()

  3. LARGE()

  4. AVG()

Answer: B) MAX()


4) Which of the following is not a valid SQL type?

  1. DECIMAL

  2. NUMERIC

  3. FLOAT

  4. CHARACTER

Answer: A) DECIMAL

5) Which operator is used to compare a value to a specified list of values?

  1. BETWEEN

  2. ANY

  3. IN

  4. ALL

Answer: C) IN







MCQ (10 Mins)

1) Select the syntax of Single Line Comment.

  1. .

  2. !

  3. --

  4. #

Answer: C) –


2) Select the Aggregate function(s) among the following.

  1. AVG()

  2. FIRST()

  3. LAST()

  4. All of the above

Answer: D) All of the above


3) Which function returns the largest value of the column?

  1. MIN()

  2. MAX()

  3. LARGE()

  4. AVG()

Answer: B) MAX()


4) Which of the following is not a valid SQL type?

  1. DECIMAL

  2. NUMERIC

  3. FLOAT

  4. CHARACTER

Answer: A) DECIMAL

5) Which operator is used to compare a value to a specified list of values?

  1. BETWEEN

  2. ANY

  3. IN

  4. ALL

Answer: C) IN


MCQ (15 mins)


1. MVC stands for:

A. model view controller

B. model view cabinet

C. none

Answer: A

2. Which Namespaces are required for Data Annotation using MVC?

A. System.ComponentModel.DataAnnotations

B. System.ComponentModel

C. none

D. both

Answer: D

3. Can we use view state in MVC?

A. yes

B. no

C. both

D. none

Answer: B

4. Can you point your browser to a view and have it render?

A. yes

B. no

Answer: A

5. Advantages of MVC?

A. MVC segregates your project into a different segment, and it becomes easy for developers to work on

B. It is easy to edit or change some part of your project, making the project less development and

maintenance cost

C. MVC makes your project more systematic

D. All of the mentioned

Answer: D






MCQs


1. Node Js is ________?

  1. Asynchronous (A)

  2. Synchronous


2. Which function is used to include modules in Node Js.

  1. include();

  2.  require(); (A)

  3.  attach();


3. To install Node.js express module

  1. $ npm install express (A)

  2.  $ node install express

  3.  $ install express

  4.  None of the above


4. Node.js runs on __________

  1. Client

  2.  Server (A)

  3.  Both, server and client

  4.  None of the above


5. Which of the following types of application can be built using Node.js?

  1. Web Application

  2.  Chat Application

  3.  RESTful Service

  4.  All of the above (A)






1. 200, 400 status code stands for:

A. success, bad request

B. Bad request, success

C. Internal error, Success  (correct)

D. Success, Internal error

 

 

2. Modules can be exposed using:

A. expose

B. module

C. exports(correct)

D. All of the above

 

 

3. HTTP status code for delete with NO CONTENT, when request body is empty?

A. 200

B. 201(correct)

C. 204

D. 304

 

 

App Building: Ecommerce Website - Home Page and

Product List Page

 

 

 

4. Which of the following is not an HTTP method?

A. Create

B. Put  (correct)

C. Post

D. Option

 

 

5. Which object is used to send the data to user?

A. Response Object

B. Request Object

C. Next Object  (correct)

D. sqlConnection Object




MCQ’s

 

1. Which of the of the following join return row that has same value on which the join operation is

performed?

a) Left join

b) Right Join

c) Inner Join (correct)

d) Full Join

 

 

2. What is the correct syntax of IF clause in sql?

a) IF(condition, value_if_true, value_if_false)   (correct)


b) IF(condition, value_if_false, value_if_true)

c) IF(condition, value_if_false,value_if_true)

d) All of the above

 

 

3. What all information are needed for fetching the product detail?

a) Category id

b) User id

c) Product id

d) Both b and c    (correct)

 


4. Which join combines all the row of both the tables?

a) Left join

b) Right Join

c) Inner Join

d) Full Join    (correct)

 

 


5. Which table is needed to find the details of the product along with the information of whether it is added

in cart or not?

a) Product

b) OrderItem

c) OrderDetails

d) All of the above      (correct)
































































Post a Comment (0)
Previous Post Next Post