Computer Science > QUESTIONS & ANSWERS > CSE 160031150 cs-cp-automata Georgia ( Best questions and answers - 100% CORRECT ) (All)

CSE 160031150 cs-cp-automata Georgia ( Best questions and answers - 100% CORRECT )

Document Content and Description Below

1. If the depth of a tree is 3 levels, then what is the size of the Tree? 1. 2 2. 4 3. 6 4. 8 Answer: 4 Explanation: Formula is 2n 2. What is the time complexity of adding three matrices of siz... e NXN cell-by-cell? 1. O (N) 2. O (N^2) 3. O (N^3) 4. None of these Answer: 2 Explanation: Time Complexity of Adding Three Matrices because there is only two loop are needed for adding the matrix so complexity will be o(n^2), there is no effect for increase the number of matrix. 3. Vijay wants to print the Following pattern on the screen: 2 2 4 2 4 6 2 4 6 8 He writes the following program: integer i = 1, j=2 // statement 1 while ( i <= 4 ) // statement 2 { j = 2; while ( j <= ? ) // Statement 3 { print j print blank space j = j + 2 } print end-of-line \takes the cursor to the next line i = i + 1 } What is the value of ? in statement 3 :: 1. 8 2. i 3. 2*i 4. 4 Answer: 3 Explanation: n first line we want to print only 0.j=2 then the line should be equal to 2 to print only 0 in first line. So answer is 2*i. 4. Himanshu wants to write a program to print the larger of the two inputted number. He writes the following code: int number1, number 2 input number1, number 2 if ("??") // Statement 1 print number1 else print number2 end if Fill in the ?? in statement 1. 1. number1>number22. number2>number1 3. number2 equals number1 4. number1 <= number2 Answer: 1 Explanation: number 1>number 2 5. Shalini wants to programme to print the largest number out of 3 inputted numbers. She writes the following programme Int number 1, number 2, number 3, temp; Input number 1, number 2, number 3; If ( number 1 > number 2) Temp = number 1 Else Temp= number 2 End if If ( ??) // statement 1 Temp = number 3 End if Print temp Fill in the ?? in statement 1 ? Choose the correct answer? 1. Number 3> number 2 2. Number 3> temp 3. Number 3< temp 4. Number 3> number 1 Answer: 2 Explanation: number 3>temp ,after first condition checking, temp will hold the largest value, so in stmt 1 third no. will be compared with temp and if it is greater than temp will hold the largest no. 6. Rohit writes the following program which inputs a number and prints "Double digit" if the number is composed of two digits and "Not a double digit" if it is not. int number; if (number>10 AND number < 100) print "Double digit" else print "Not a double digit" end if Rohit tries the following inputs: 5 and 66. The program works fine. He asks his brother Ravi to try the program. When Ravi enters a number, the program doesn't work correctly. What did Ravi enter? 1. 8 2. 100 3. 99 4. 10 Answer: 4 Explanation: smallest two digit no. is 10.if we enter 10, condition will become false in first expression. compiler will not evaluate second expressions because in AND operation if one of the condition is false, else part will execute. 7. Rohan writes the following program which inputs a number and prints "Triple digit" if the number is composed of three digits and "Not triple digit" if it is not. int number; if (number>99) print "Triple digit" elseprint "Not triple digit" end if Rohan tries the following inputs: 25 and 566. The program works fine. He asks his brother Ravi to try the program. When Ravi enters a number, the program doesn't work correctly. What did Ravi enter? 1. 99 2. 100 3. 0 4. 1000 Answer: 4 Explanation: Because 1000 is not a triple digit number but by the following code it give 1000 as triple digit the code should be (number>99 AND number <1000) 8. In a sequential programming language, code statements are executed in which order? 1. All are executed simultaneously 2. From top to bottom 3. From bottom to top 4. None of these Answer: 2 Explanation: It‟s the default working order 9. Stuti is making a questionnaire of True-false questions. She wants to define a data-type which stores the response of the candidate for the question. What is the most-suited data type for this purpose? 1. integer 2. Boolean 3. float 4. character Answer: 2 Explanation: Bool used for true or false 10. A variable cannot be used… 1. Before it is declared 2. After it is declared 3. In the function it is declared in 4. Can always be used Answer: 1 Explanation: it‟s the rule to declare variable before to use this 11. What is implied by the argument of a function? 1. The variables passed to it when it is called 2. The value it returns on execution 3. The execution code inside it 4. Its return type Answer: 1 Explanation: max(2,3) 2 and 3 are the argument of function MAX 12. Zenab and Shashi independently write a program to find the the mass of one mole of water, which includes mass of hydrogen and oxygen. Zenab defines the variables: integer hydrogen, oxygen, water // Code A while Shashi defines the three quantities as: integer a, b, c // Code B Which is a better programming practice and why? 1. Code B is better because variable names are shorter 2. Code A is better because the variable names are understandable and non confusing 3. Code A will run correctly, while Code B will give an error.4. Code B will run correctly, while Code A will give an error. Answer: 2 Explanation: Meaning full name makes sense of understanding 13. Every element of a data structure has an address and a key associated with it. A search mechanism does with two or more values assigned to the same address by using the key. What is this search mechanism? 1. Linear search 2. Binary Search 3. Hash coded search 4. None of the above Answer 3 Explanation: Hash Coded Search uses a hash key and hash address in hash table. 14. A programmer writes a sorting algorithm that takes different amount of time to sort two different lists of equal size. What is the possible difference between the two lists? 1. All numbers in one list are more than 100 while in the other are less than 100. 2. The ordering of numbers with respect to the magnitude in the two lists has different properties. 3. One list has all negative numbers while the other has all positive numbers. 4. One list contains 0 as an element while the other does not. Answer:2 Explanation: Sorting algorithm is always based on the comparisons so the list that requires more comparisons will be slow and number of comparisons will be more for unsorted list and will be minimal for sorted list, that is ordering of numbers in same sized list will make difference 15. A sorting algorithm iteratively traverses through a list to exchange the first element with any element less than it. It then repeats with a new first element. What is this sorting algorithm called? 1. insertion sort 2. selection sort 3. heap sort 4. quick sort Answer: 2 Explanation: Selection sort searches for the minimum element in the list then replaces with the first element. 16. A sorting mechanism uses the binary tree concept such that any number in the tree is larger than all the numbers in the sub tree below it. What is this method called? 1. Selection Sort 2. Insertion Sort 3. Heap sort 4. Quick Sort Answer: 3 Explanation: The heap is often placed in an array with the layout of a complete binary tree 17. How many comparisons are needed to sort an array of length 5 if a straight selection sort is used and array is already in the opposite order? 1. 1 2. 10 3. 50 4. 20 Answer: 2 Ans: n (n-1)/2=10 18. Queues serve a major role in 1. simulation of recursion 2. simulation of arbitrary linked list3. Simulation of limited resource allocation 4. expression evaluation Answer: 3 Explanation: Simulation of limited resource allocation scheduling algorithms. 19. The average search time of hashing with linear probing will be less if the load factor 1. Is far less than one 2. equals one 3. Is far greater than one 4. N 5. one of these Answer: 1 Explanation: A critical statistic for a hash table is the load factor, that is the number of elements divided by size of hash table: Load factor where: n = number of elements k = Size of hash table As the load factor grows larger, the hash table becomes slower, and it may even fail to work (depending on the method used). 20. Number of vertices of odd degree in a graph is 1. is always even 2. always odd 3. either even or odd 4. always zero Answer: 1 Explanation: In graph theory, a branch of mathematics, the handshaking lemma is the statement that every finite undirected graph has an even number of vertices with odd degree (the number of edges touching the vertex) 21. The algorithm design technique used in the quick sort algorithm is 1. Dynamic programming 2. Back tracking 3. Divide and conquer 4. Greedy Search Answer: 3 Explanation: Quick sort is a divide and conquer algorithm. Quick sort first divides a large array into two smaller sub-arrays: the low elements and the high elements. Quick sort can then recursively sort the subarrays 22. Linked lists are not suitable for 1. Insertion sort 2. Binary search 3. Queue implementation 4. None of these Answer: 2 Explanation: For binary search, if we are using array, then we can go to middle of array by just dividing index of array by 2. Since array is stored in contiguous memory. But that is not true in case of linked list.If you want to access middle of list then each time you have to traverse from its head. Hence use of linked list is not good idea for binary search 23. A connected graph is the one which 1. Cannot be partitioned without removing an edge 2. Can be partitioned without removing an edge 3. does not contain a cycle 4. Has even number of vertices Answer: 1 Explanation: A graph is connected when there is a path between every pair of vertices. In a connected graph, there are no unreachable vertices. A graph that is not connected is disconnected. A graph with just one vertex is connected. A graph is said to be connected if there is a path between every pair of vertex 24. Stack is useful for implementing 1. radix search 2. breadth first search 3. recursion 4. none of these Answer: 3 Explanation: Stack is useful for Recursion as well as Depth first Search. 25. Which of the following is useful in traversing a given graph by breadth first search? 1. stack 2. set 3. list 4. queue Asnwer: 4 Explanation: It uses a queue instead of a stack 26. In a circular linked list organization, insertion of a record involves modification of 1. One pointer 2. Two pointers 3. Three pointers 4. No pointer Answer: 2 Explanation: Suppose we want to insert node A to which we have pointer p, after pointer q then we will Have following pointer operations 1. p->next=q->next; 2. q->next = p; So we have to do two pointer modifications 27. Which of the following is useful in implementing quick sort? 1. stack 2. set 3. list 4. queue Answer: 1 Explanation: It uses the concept of Recursion and follows stack. 28. Which of the following abstract data types can be used to represent a many to-many relation? 1. Tree 2. Stack 3. Graph 4. Queue Answer: 3 Explanation: As the following rule:graph...many to many tree.. one to many stack... one to one 29. A programmer writes a code snippet in which a set of 3 lines occurs 10 times in different parts of the program what programming concept should be used to shorten the code length? 1. For loop 2. Functions 3. Arrays 4. Classes Answer: 2 Explanation: Function is a block of code which is defined once and can be called multiple times in the program. The feature of code reusability reduced the size of program. 30. X and Y are asked to write a program to sum the rows of 2*2 matrix stored in an array A X writes the Code (code A) as follows: For n= 0 to 1 Sumrow1[n]= A[n][1]+A[n][2] End Y writes the Code (code B) as follows: Sumrow1[0]=A[0][1]+A[0][2] Sumrow1[1]=A[1][1]+A[1][2] Which of the following statement is correct about these codes if no loop unrolling is done by the compiler? 1. Code A would executes faster than Code B 2. Code B would executes faster than Code A 3. Code A is logically incorrect 4. Code B is logically incorrect Answer: 2 Explanation: First statement will take more time to check the loop condition and then execute the loop body based on that condition. 31. Which of the following is the lowest level format to which the compiler converts a program in a higher language before execution? 1. English Code 2. Machine Code 3. Assembly language 4. System language Answer: 2 Explanation: Machine code is also called the binary code which is directly understood by the compiler. So,it is the lowest level format. 32. In which of the following situations can a constructor be invoked? 1. When an object is created 2. When an object is assigned the value 0 3. Only at the end of the code. 4. When the scope of the object is over Answer: 1 Explanation: A constructor is a special member function which is called automatically when the object of class is created. 33. What is the difference between a function and a method? 1. Function is named code unlike method which is part of an object. 2. Function contained in an object is called a method. 3. Function cannot change variables outside its scope unlike method. 4. There is no difference between the two.Answer: 4 Explanation: Method is another name of function which is mostly used in OOP terminology. 34. What is implied by the argument of a function? 1. The variables passed to the function when it is called. 2. The value that the function returns on execution. 3. The execution code inside the function. 4. Return type of the function. Answer 1. Explanation: Argument specifies the number of inputs you want to pass to function body when it is called. For example, to print table of a number, we will pass one argument only in the function body because there is one input only. The function prototype is given below: void table(int); 35. Which tree(s) from the given figure is/are Heap(s)? 1. Only 1 2. Only 2 3. Only 3 4. Both 1 and 2 5. Both 1 and 3 Figure 1. Figure 2 Figure 3 Answer: 4 Explanation:-This is Heap tree because in this diagram; the parent node of every sub tree is greater than the left and right child.(i.e max heap). 36. Programmer is making a database of animals in a zoo along with their properties. The possible animals are dog, lion and zebra. Each one has attributes as herbivorous, color and noctumal. The programmer uses the object-oriented programming paradigm for this. How will the system be conceptualized? 1. Class : Animal, objects: dog, lion and zebra, data members: herbivorous, color and nocturnal 2. Class: Animal, objects: herbivorous, color and nocturnal, data members: dog, lion and zebra 3. Classes: dog, lion and zebra, objects: Animal, data members: herbivorous, color and nocturnal 4. None of the above Answer 1 Explanation: One class has many attributes and it is possible to declare multiple objects of a single class and all these objects have same properties i.e. herbivorous, color and nocturnal 37. What will be returned if f(a, b) is called in the following functions? Function g(int n) { If(n>0) return 1; Else return-1; } Function f(int a, int b) { If(a>b) return g(a-b); If(a<b) return g (-b+a); return 0; 18 3 11 15 1 7 18 1 11 17 3 13 18 1 11 2 3 15} 1. Always +1 2. 0 if a equals b,1 if a>b ,-1 if a<b 3. -1 if a>b ,1 if a<b, 0 otherwise 4. 0 if a equals b, -1 otherwise Answer: 2 Explanation: There are three possible cases: 38. Null function is also known as? 1. Anonymous Function 2. Generic Function 3. Void function 4. Null Operator Answer: 4 Explanation: Null function (or null operator) returns no data values and leaves the program state unchanged. It is called NULL operator also because it does not perform any operation. 39. Which of the following statement is true about a breadth first search? 1. Beginnings from a node, all the adjacent node are traversed first. 2. Beginning from a node, each adjacent node is fully explored before traversing the next adjacent node. 3. Beginning from a node, the nodes are traversed in cyclic order 4. None of the above Answer: 1 Explanation: Breadth-first search (BFS) is an algorithm for traversing or searching tree or Graph data structures. It starts at the tree root (referred to as a 'search key') and explores the neighbor nodes first, before moving to the next level neighbors. 40. How can a call to an overloaded function be ambiguous? 1. The name of the function might have been misspelled 2. There might be two or more functions with the same name 3. There might be two or more functions with equally appropriate signatures. 4. None of the above Answer: 3 Explanation: Function overloading means same name function can be called multiple times but with difference in number or type of arguments 41. Passage class rocket { Private: Integer height, weight Public // statement 1 Function input(int a, int b) { Height= a; Weight= b; } } Function main() { Rocket rocket1, rocket2 } Refer to the pseudo code given in the passage. The code is similar to that in C++ and is self explanatory. An accessible member function and a data member for an object are accessed by thestatements objectname.functionname and objectname.datamembername,respectively. What can be inferred from this code ? 1.“rocket” is class with “rocket1” and “rocket2” as its objects with “height” and “weight” as its attributes 2. “rocket” is class with “rocket1” and “rocket2” as its objects with “height” and “weight” as its objects. 3. “rocket” is class with “rocket1” , “rocket2” ,“height” and “weight” as its attributes. 4. “rocket” is class with “rocket1” , “rocket2” ,“height” and “weight” as its objects. Answer: 1 Explanation: An object is an instance of a class which is required to access the class members. It is generally created in the main() .On the other hand, data elements indicates the attributes of class which is always created in the class body under particular scope. 42. _________is the compile time binding whereas______is the run time binding of functions. 1. Function overriding, function overloading. 2. Abstraction, encapsulation 3. Function overloading, Function overriding. 4. Varies from program to program. Answer: 3 Explanation: Function overloading means same name function is defined multiple times but with the difference in number or type of arguments. Ex: (function call) disp(); disp(10); disp(10,20); it will be resolved during compile time in which compiler decides the function body based on number or type of arguments in function calling. 43. Why is an algorithm designer concerned primarily about the run time and not the compile time while calculating time complexity of the algorithm? 1. Run time is always more than compile time. 2. Compile time is always more than run time 3. Compile time is a function of run time 4. A program needs to be compiled once but can be run several times. Answer: 4 Explanation: Because the execution time is more important .if a program will take more time than that code can‟t be an efficient code. 44. What is the term given in the memory allocation that takes place during run time rendering the resizing of the array? 1. Static allocation 2. Dynamic allocation 3. Automatic allocation 4. Executive allocation Answer: 2 Explanation: Because array at compile time is static .if we want to resize the array at run time we will have to use DMA (dynamic memory allocation) using pointer i.e (malloc(),calloc(),realloc()) 45. Consider the following code: function modify(y, z) { y = y + 1 z = z + 1 return y - z } function calculate( ) {integer a = 12, b = 20, c c =modify(a, b); print a print space \ print c } Assume that a and b were passed by reference. What will be the output of function calculate () ? 1. 12 -8 2. 13 -8 3. 12 8 4. 13 8 Answer: 2 Explanation: In call by reference technique, the reference of actual arguments is passed to formal arguments. So, any change in formal arguments alter the actual value. In given example: a=12 and b=20 which will be passed to y and z by reference as below: c=modify(&a,&b); int modify(int *y,int *z) { *y = *y + 1 *z = *z + 1 return *y - *z } y=12 and z=20 y=y+1 (12+1=13) z=z+1 (20+1=21) return (y-z) [13-21=-8] The returned value will be stored in “c” variable. So, output will be 13 and -8 46. A programmer writes a program to find an element in the array A [5] with the elements 8, 30, 40, 50, 70. The program is run to find a number “X”, that is found in the first iteration of binary search. What is the value of “X”? 1. 40 2. 8 3. 70 4. 30 Answer: 1 Explanation: In this technique, first of all, value in mid position is searched (as a first step).If it is not found, and then we will check left part and right part respectively. So, if the value is found in first iteration, it can be mid value only. 47. A librarian has to arrange the library books on a shelf in a proper order at the end of each day. Which of the following sorting techniques should be the librarian ideal choice? 1. Bubble sort 2. Insertion sort 3. Selection sort 4. Heap sort Answer: 2 Explanation: Books in shelf‟s denotes that their not so many books in the shelf‟s and there must be minimum no of swap (movement of hands in replacing books while arranging)so insertion sort is the best algorithm for small no of elements. Which best case is O(n) and worst case O(n^2) which is better than bubble and selection sort. 48. Aakash wants to write a function that has three parameter length breadth and height. Buthe wants this function to be such that provided height will become optional i.e user manually not pass the value of height to the function but still the function should work. Which of the concept should he use? 1. Global variable 2. Default argument 3. Argument passing 4. Extern variable Answer: 2 Explanation: In languages, a default argument is an argument to a function that a programmer is not required to specify. In most programming languages, functions may take one or more arguments. Usually, each argument must be specified in full (this is the case in the C programming language. Later languages (for example, in C++) allow the programmer to specify default arguments that always have a value, even if one is not specified when calling the function. 49. Which of the following sorting techniques has its best case performance done in (n log n) steps? 1. Insertion sort 2. Bubble sort 3. Selection sort 4. Merge sort Answer: 4 Explanation: O (nlogn) is the complexity for merge sort. 50. How many nodes does a full binary tree with “n” leaves contain? 1. 2n+1 nodes 2. Log2n nodes 3. 2n-1 nodes 4. 2n nodes [Show More]

Last updated: 2 years ago

Preview 1 out of 104 pages

Buy Now

Instant download

We Accept:

We Accept
document-preview

Buy this document to get the full access instantly

Instant Download Access after purchase

Buy Now

Instant download

We Accept:

We Accept

Reviews( 0 )

$11.00

Buy Now

We Accept:

We Accept

Instant download

Can't find what you want? Try our AI powered Search

77
0

Document information


Connected school, study & course


About the document


Uploaded On

Jul 29, 2021

Number of pages

104

Written in

Seller


seller-icon
Cheryshev

Member since 4 years

102 Documents Sold

Reviews Received
6
4
1
0
1
Additional information

This document has been written for:

Uploaded

Jul 29, 2021

Downloads

 0

Views

 77

Document Keyword Tags


$11.00
What is Scholarfriends

In Scholarfriends, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.

We are here to help

We're available through e-mail, Twitter, Facebook, and live chat.
 FAQ
 Questions? Leave a message!

Follow us on
 Twitter

Copyright © Scholarfriends · High quality services·