CS Midterm 1 Kahoot

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

In the following C function, let n >= m. int gcd(n,m) { if (n%m ==0) return m; n = n%m; return gcd(m, n); } A) O(logn) B) O(n) C) O(nlogn) D) O(n^2)

A

A parent class has a final public method show(); A child class has a public method show(); An object is created: Parent o = new Child(); What happens: o.show() ? A) Parent is called. B) Child is called. C) Compiler error. D) Runtime error.

C

T/F: It is possible to give more restrictive access to a derived class function which overrides a base class function.

False

T/F: Protected methods are final.

False

T/F: We can override private methods.

False

T/F: Every iterator is also an iterable.

True

T/F: Final methods cannot be overridden.

True

What happens for the statement marked with a comment? Object o = new GrandChild(); int x = parentMethod();

compiler error

What is the abstract data type that restricts access to the minimum item?

priority queue

A parent class has a public static method show(); A child class has a public static method show(); There is an object: Parent o = new Child(); What happens when: o.show(); is called? A) The parent class is called. B) The child class is called. C) Compiler Error. D) Runtime Error.

A

Recursive partitioning is always: A) Logarithmic B) Linear C) NLogN D) Quadratic

A

A circularly linked list is used to represent a Queue. A single variable p is used to access the Queue. To which node should p point such that both the operations enQueue and deQueue can be performed in constant time? A) front node B) rear node C) not possible D) node next to front

B

Which may not appear in a Java interface? A) public abstract method B) private abstract method C) variable

B

Let P be a singly linked list. Let Q be the pointer to an intermediate node x in the list. What is the worst-case time complexity of the best known algorithm to delete the node x from the list? A) linear B) logarithmic C) constant D) quadratic

C

Randomized quicksort is an extension of quicksort where the pivot is chosen randomly. What is the worst case complexity of sorting n numbers using randomized quicksort? A) Linear B) NlogN C) Quadratic D) Logarithmic

C

Which is not inherited from the parent class? A) private instance variables B) public instance variables C) public instance methods D) all are inherited

D

Which of the following points is/are true about Linked List data structure when it is compared with array: A) Arrays have better cache locality that can make them better in terms of performance. B) It is easy to insert and delete elements in Linked List. C) Random access is not allowed in a typical implementation of Linked Lists. D) The size of array has to be pre-decided, linked lists can change their size any time. E) all of the above

E

T/F: Every iterable is also an Interator

False

T/F: Final methods can be overridden.

False

T/F: In java, we can specify whether the inheritance is protected, public or private.

False

What is the term for an object whose sole purpose is to have its one and only method be called?

Functor

Which is a divide-and-conquer algorithm that obtains an O(NlogN) sort, in the worst case?

Merge sort

Is the following O(n^2)? n^3 / (sqrt(n))

No.

What is the Big-O behavior of this loop nest? for(int i =1; i <=n; ++i) for(int j =1; j<= n; J*=2) sum++

O(N logN)

What is the best time complexity of bubble sort?

O(N)/Linear

What is the worst case time complexity of insertion sort where position of the data to be inserted is calculated using binary search?

O(N^2)/Quadratic

In the worst case, the number of comparisons needed to search a singly linked list of length n for a given element is:

O(n)/Linear

Number of comparisons in selection sort of an N-item array is the same, regardless of order.

True

T/F: In Java, all classes inherit from the Object class directly or indirectly. The Object class is root of all classes.

True

T/F: In Java, it is not allowed to do super.super. The result is a compiler error.

True

T/F: It is compiler error to give more restrictive access to a derived class function which overrides a base class function.

True

T/F: Multiple inheritance is not allowed in Java

True

T/F: Protected members are accessible within a package and inherited classes outside the package.

True

T/F: Protected methods are not final.

True

T/F: Queue is a iterable

True

T/F: The minimum possible time complexity of a comparison based sorting algorithm is O(nLogn) for a random input array.

True

T/F: The worst case time complexity is always greater than or same as the average case time complexity.

True

T/F: There is nothing like type of inheritance in Java where we can specify whether the inheritance is protected, public or private

True

T/F: We cannot override private methods.

True

T/F: logN < N

True

Give the functions in increasing order of asymptotic complexity of functions f1, f2, f3 and f4 (ex: f1, f2, f3, f4): f1(n) = 2^n f2(n) = n^(3/2) f3(n) = nLogn f4(n) = n^(Logn)

f3, f2, f4, f1

What is happening for the equals() method? public class Point { public int x,y; public Point(int _x, int _y) { x = _x; y = _y; } public boolean equals(Point other) { return x == other.x && y == other.y; }}

method overloading

Which of the following operations is not O(1) for an array of sorted data. You may assume that array elements are distinct. A) find the ith largest element B) delete an element C) find the ith smallest element D) all of the above

B

Which of these is false? A) 2N^2 + 3N = O(N^2) B) N^2 + N logN = O(N logN) C) (N logN) / (logN - 1) = O(N) D) N / (N + 2) = O(1)

B

Consider the program: void function(int n) { int i, j, count=0; f or (i=n/2; i <= n; i++) for (j = 1; j <= n; j = j*2) count++;} The complexity of the program is: A) O(log n) B) O(n^2) C) O(n^2logn) D) O(nlogn) E) O(n^n)

D

For which data structure(s) is an addFirst operation O(1)? A) ArrayList B) basic array C) singly-linked list D) doubly-linked list E) both A & B F) both C & D

F

T/F: Polymorphism can happen when a function is static.

False

T/F: The minimum possible time complexity of a comparison based sorting algorithm is O(N) for a random input array.

False

T/F: logN > N

False

T/F: n^(Logn) < n^(3/2)

False

What is time complexity of fun()? int fun(int n) { int count = 0; for (int i = n; i > 0; i /= 2) for (int j = 0; j < i; j++) count += 1; return count; }

O(N)/Linear

Suppose we have a O(n) time algorithm that finds median of an unsorted array. Now consider a QuickSort implementation where we first find median using the above algorithm, then use median as pivot. What will be the worst case time complexity of this modified QuickSort. (give in form O(#) with no spaces)

O(NLogN)

What is the Big-O behavior of this loop nest? for(int i = 1; i<=n; ++i){ for(int j = 1; j<=i; j++) { sum++; }}

O(N^2)

What is the time complexity of fun()? int fun(int n) { int count = 0; for (int i = 0; i < n; i++) for (int j = i; j > 0; j--) count = count + 1; return count; }

O(N^2)/Quadratic

Which sorting algorithm is fastest for an N-item array that is nearly sorted (<= N inversions)?

insertion sort

What happens? Child o = new GrandChild(); s = o.grandChildMethod();

invokes grandChildMethod

Which of these runs in N logN time when presented with an array of N identical items? A) insertion sort B) merge sort C) quick sort (median of three) D) both merge & quick sort

merge sort

A parent and child class have public methods with the same name: Print(); In main, the following objects are created: Base x = new Base(); Base y = new Derived(); Derived z. new Derived(); Which object is called when: A) print(x) B) print(y) C) print(z) ? separate class names with commas

parent, child, child

Which sorting algorithm will take least time when all elements of input array are identical? Consider typical implementations of sorting algorithms. A) Insertion B) Selection C) Quick D) Merge

A

Which of the following correctly declares an array? A) int geeks[20]; B) int geeks; C) geeks{20} D)array geeks[20]

A

Which of the following sorting algorithms has the lowest worst-case complexity? A) Merge Sort B) Bubble Sort C) Quick Sort D) Selection Sort

A

What is the Big-O behavior of the following: While(nVal >0) { nVal = nVAl/2 } A) Logarithmic B) Linear C) Quadratic D) NLogN

A

How many times more complex would an algorithm of quadratic complexity require a list of 500 items vs 50 items?

100

If a quicksort chooses the worst possible pivot for a list of 1024 items, how many comparisons will be required?

1047552

For a list size of 2048, how many recursive calls will be required to partition the list for a divide & conquer algorithm?

11

What is the result of this postfix expression: 4 2 + 3 5 1 - * +

18

How many queues are needed to implement a stack. Consider the situation where no other data structure like arrays, linked list is available to you.

2

How many stacks are needed to implement a queue. Consider the situation where no other data structure like arrays, linked list is available to you.

2

A program P reads in 500 integers in the range [0..100] exepresenting the scores of 500 students. It then prints the frequency of each score above 50. What would be the best way for P to store the frequencies? (GATE CS 2005) A) an array of 50 numbers B) an array of 100 numbers C) an array of 500 numbers D) an array list of 550 numbers

A

Consider a situation where swap operation is very costly. Which of the following sorting algorithms should be preferred so that the number of swap operations are minimized in general? A) Selection sort B) Insertion sort C) Merge sort D) Quick sort

A

What are the time complexities of finding 8th element from beginning and 8th element from end in a singly linked list? Let n be the number of nodes in linked list, you may assume that n > 8. A) constant and linear B) constant for both C) linear and constant D) linear for both

A

A list of n string, each of length n, is sorted into lexicographic order using the merge-sort algorithm. The worst case running time of this computation is: A) O(n log n) B) O(n^2 logn) C) O(n^2 + logn) D) O(n^2)

B

Consider the following pseudocode that uses a stack: declare a stack of characters while ( there are more characters in the word to read ) { read a character push the character on the stack } while ( the stack is not empty ) { pop a character off the stack write the character to the screen } What is output for input "geeksquiz"? A) geeksquizgeeksquiz B) ziuqskeeg C) geeksquiz D) ziuqskeegziuqskeeg

B

For which of the ArrayList objects will this statement compile? (Assume usual shape hierarchy.) A) ArrayList<Shape> myList B) ArrayList<Circle> myList C) It will compile for both. D) It will not compile for either.

B

T/F: What does it mean when we say that an algorithm X is asymptotically more efficient than Y? A) X will be a better choice for all inputs B) X will be a better choice for all inputs except possibly small inputs C) X will be a better choice for all inputs except possibly large inputs D) Y will be a better choice for small inputs

B

The minimum number of comparisons required to determine if an integer appears more than n/2 times in a sorted array of n integers is (think binary search): A)O(n) B) O(logn) C)O(log*n) D)O(1)

B

What does the following function do for a given Linked List with first node as head? void fun1(struct node* head) { if(head == NULL) return; fun1(head->next); printf("%d ", head->data); } A) prints all nodes of linked list B) prints all nodes of linked list in reverse order

B

What is the time complexity of following function fun()? Assume that log(x) returns log value in base 2. void fun() { int i, j; for (i=1; i<=n; i++) for (j=1; j<=log(i); j++) printf("GeeksforGeeks"); } A) Linear B) N log N C) Quadratic D) Logarithmic

B

A parent class has a public method foo(), and a child class has a private method foo(). If the following object is created: Parent o = new Child(); What class is called when o.foo() ? A) Parent B) Child C) Compiler Error

C

A) for(i = 0; i < n; i++) B) for(i = 0; i < n; i += 2) C) for(i = 1; i < n; i *= 2) D) for(i = n; i > -1; i /= 2) If n is the size of input(positive), which function is most efficient(if the task to be performed is not an issue)?

C

For which data structure(s) is an addLast operation NOT O(1)? A) ArrayList B) basic array C) singly-linked list D) doubly-linked list E) both A & B F) both C & D

C

The result evaluating the postfix expression 10 5 + 60 6 / * 8 - is A) 284 B) 213 C) 142 D) 71

C

The tightest lower bound on the number of comparisons, in the worst case, for comparison-based sorting is of the order of: A) Linear B) Quadratic C) N*LogN D) N(LogN)^2 E) Cubic

C

Which of the following is true about linked list implementation of queue? A) In push operation, if new nodes are inserted at the beginning of linked list, then in pop operation, nodes must be removed from end. B) In push operation, if new nodes are inserted at the end, then in pop operation, nodes must be removed from the beginning. C) Both D) None

C

Which of the following sorting algorithms can be used to sort a random linked list with minimum time complexity? A) Insertion sort B) Quick sort C) Merge sort D) Selection Sort

C

You are given pointers to first and last nodes of a singly linked list, which of the following operations are dependent on the length of the linked list? A) delete first element B) insert a new element as the first element C) delete the last element D) add a new element at the end of the list

C

T/F: 2^n > n^(Logn)

True

T/F: Private methods are final.

True

T/F: When a function is static, runtime polymorphism doesn't happen.

True

T/F: n^(3/2) < n^(Logn)

True


संबंधित स्टडी सेट्स

NW Mutual Q3 - Life insurance policies

View Set

PTA 2210 Manual Muscle Testing: Trunk

View Set

Econ Modules 5 and 4 Practice Exams

View Set

What is the supreme law of the land?

View Set

Chapter 13: Eye Assessment for Advanced and Specialty Practice

View Set

Understanding Probability - Assignment

View Set

Chapter 5 CPU Scheduling Questions

View Set