CSCI Midterm Review

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Suppose the numbers 4, 2, 6, 1, 3, 5, 15, 7, 16 are inserted in that order into an initially empty AVL tree. Find the resulting AVL after inserting number 12 followed by proper rotations. Resulting values read from left to right in each level and null node indicated by --

4 2 7 1 3 6 15 -- -- -- -- 5 12 16

Given keys 20, 30, 33, 35, 39, 40, 50, 60, 100 What order of key insertion would construct a Full Binary Tree

40, 30. 60. 20, 35, 50, 100, 33, 38

The maximum comparisons needed in Binary Search on sorted array of size 32 is

5

After inserting keys 5, 6, 8 , 10, 20, 30, 40 to a BST in the same order. Find the height of the BST

6

The maximum comparisons needed in Binary Search on sorted array of size 64 is

6

Suppose the numbers 13, 11, 7, 14, 9, 12, 6, 15, 10, 8 are inserted in that order into an initially empty binary search tree. The binary search tree uses the usual ordering on natural numbers. What is the in-order traversal sequence of the resultant tree?

6 7 8 9 10 11 12 13 14 15

Let h'(x) = [h(x) + f(i2)]% n where i =0,1,2,3,4...f(i) = i insert keys 7,2,17,65,40 to a hash table of size 5 key map to the array index given by

65 17 7 2 40

After inserting keys 5, 6, 8 , 10, 20, 30, 40, 100 to a BST in the same order. Find the size of the tree

8

Find true statements about Queue (There may be more than one answer) A. Queue is a FIFO (First in First Out) Data Structure. B. Elements are removed in the Rear of the queue C. Elements are inserted at the Front of the queue D. Not any of these

A

Expected output of the following is int y=1000; int *yPtr; yPtr = &y; cout<<" &y = "<< &y <<" \n "; cout<<" y = " << y <<endl; cout<< "*yPtr = "<<*yPtr<<"\n "; cout<<"yPtr = "<< yPtr <<" \n ";

&y = 0x7fff9942bde4 y = 1000 *yPtr = 1000 yPtr =0x7fff9942bde4

Binary Search works when the array is

- sorted in descending order - sorted in ascending order

Given the following pseudo code, indicate j's value at the end of iteration i = 2. for (int i = 0; i < 5; ++i) { int j = 0 j = j * i }

0

Find the intermediate steps of the following data set when it is being sorted with the Quick sort? (Using start pivot as index 2)5 10 1 50 3 0

0,1,5,50,3,10 -- 0,1,5,50,3,10 -- 0,1,5,10,3,50 -- 0,1,5,3,10,50

Given that T(n) =T(1) +∑ni=2i what is T(n) and it's complexity ?

1 +(n+2)(n−1) /2 and Θ(n2)

Output of the following pseudo code int main() { int count=5 for( count =1; count <= 10; count++ )// loop 10 times { if( count ==5) break cout << count <<" " } cout << "\n Out of loop at count = " << count << endl

1 2 3 4 Out of loop at count = 5

Given the following AVL Tree: Find balance factors of node key 2, 4, 7, 5 respectively

1, 0, 1, 1

Given the following pseudo-code, how many times will the "inner loop body" execute? int row int col for(row = 0; row < 2; row = row + 1) { for(col = 0; col < 5; col = col + 1) { // Inner loop body } }

10

How many comparisons are required to order an array of 5 elements using the selection sort?

10

Which array represents the max heap -- : indicate empty array cell

10 8 6 4 5 1 2 -- --

What are the correct intermediate steps of the following data set when it is being sorted with the Quick sort? (Using middle pivot)15,20,10,18

10, 20,15,18 -- 10,18,15,20 -- 10,15,18,20

If pre order traversal of a binary tree output 15, 10, 12, 11, 20,17, 19 Find the order of postorder traversal of the tree

11, 12, 10, 16, 19, 18, 20, 15

If there are 50 elements in an unsorted array. Find the total comparisons required to sort the using Bubble sort.

1275

The preorder traversal sequence of a binary search tree is 30, 20, 10, 15, 25, 23, 39, 35, 42. Which one of the following is the postorder traversal sequence of the same tree?

15, 10, 23, 25, 20, 35, 42, 39, 30

What are the correct intermediate steps of the following data set when it is being sorted with the bubble sort? 15,20,10,18

15,10,20,18 -- 15,10,18,20 -- 10,15,18,20

What are the correct intermediate steps of the following data set when it is being sorted with the Insertion sort? 15,20,10,18

15,20,10,18 -- 10,15,20,18 -- 10,15,18,20 -- 10,15,18,20

What are the correct intermediate steps of the following data set when it is being sorted with the Insertion sort?15,20,10,18

15,20,10,18 -- 10,15,20,18 -- 10,15,18,20 -- 10,15,18,20

If we remove the root node, which of the node from the left subtree will be the new root?

16

Let h'(x) = [h(x) + f(i3)]% n where i =0,1,2,3,4...f(i) = i insert keys 7,2,17,65,40 to a hash table of size 5 key map to the array index given by

17 65 7 2 40

After inserting keys 5, 6, 8 , 10, 20, 30, 40 to a BST in the same order. Find the height of the node with key 20

2

The height of a binary tree is the maximum number of edges in any root to leaf path. The maximum number of nodes in a binary tree of height h is:

2(h+1) -1

How many times the following Inner loop body runs int row; int col; for(row = 0;row <= 3;row ++){ for(col = 0;col < 5;col++){ // Inner loop body } }

20

Consider a hash table with 10 slots and the collisions are resolved by linear probing. The following keys are inserted in the order: 15, 2, 1, 5, 20, 31, 12, 21, 17, 34.

20 1 2 31 12 15 5 21 17 34

After inserting keys 5, 6, 8 , 10, 20 to a BST in the same order. Find the depth of the node with key 10

3

Find the number of rotations required to insert of elements 9, 6, 5, 8, 7, 10 into an empty AVL Tree

3

For the following pseudo-code, indicate how many times the loop body will execute for the input values: 2 5 -3 4 6. userNum = 3 while (userNum > 0) { // Do something cin>> userNum }

3

The following numbers are inserted into an empty binary search tree in the given order: 10, 1, 3, 5, 15, 12, 16 What is the height of the binary search tree ?

3

Consider the following lists of partially sorted numbers. The double bars represent the sort marker Insertion Sort. How many comparisons and swaps are needed to sort the next number. [1 3 4 8 9 || 5 2]

3 comparisons, 2 swaps

Consider a hash table with 9 slots. The hash function is ℎ(k) = k % 9. The collisions are resolved by chaining. The following 9 keys are inserted in the order: 5, 28, 19, 15, 20, 33, 12, 17, 10. The maximum, minimum, and average chain lengths in the hash table, respectively, are

3, 0, and 1

The maximum comparisons needed in Linear Search on array of size 32 is

32

The elements 32, 15, 20, 30, 12, 25, 16 are inserted one by one in the given order into a Max Heap. The resultant Max Heap in array is.

32 30 25 15 12 20 16

The elements 32, 15, 20, 30, 12, 25, 16 are inserted one by one in the given order into a Max Heap. The resultant Max Heap in the array is.

32 30 25 15 12 20 16

Assume we are sorting in increasing order. 32 30 29 33 31 35 34 Let's use Quicksort with pivot middle floor value with recursive call find one of the correct intermediate step of the above data set

32 30 29 33 31 -- 34 35 29 -- 30 31 33 32 -- 34 -- 35 29 -- 30 31 -- 33 32 -- 34 -- 35 29 -- 30 -- 31 -- 33 --32 -- 34 -- 35

Given keys 20, 30, 35, 39, 40, 60, 100 What order of key insertion would construct a Complete Binary Tree

39, 30, 60, 20, 35, 40, 100

Given Class name myClass True about a default constructor declaration in class myClass { ... } : A. The following calls the default constructor 1 time: vector<myClass> myClass(3); B. The following calls the default constructor once: myClass object; C. The following calls the default constructor twice: myClass object1;myClass object2; D. class myClass{void seat();}

B, C

True about the following A. Getter used to update private member values B. Accessor used to update private member values C. Mutator and Accessor required only when private or protected data member occurs D. Mutator and Accessor also define as setter and getter

C, D

Which of the following traversal outputs the data in sorted order in a BST?

Inorder Traversal

Consider the if-elseif-else structure below: if (x < -10) cout<< "Disagrees" else if (x == 10) cout<<"Neutral" else if (x > 0) cout<<"Agrees" else cout<<"Invalid entry"

Invalid entry

Which of the following method is used for sorting in merge sort?

Merging

What is true about the following code segment class A { public: void Print(); protected: string name; private: string address; }; class B: public A {} A. function print available in A and everyone else but not B B. variable 'address' only accessible by A and B not anyone else C. B is the superclass of A D. variable 'name' only accessible by A and B not anyone else

D

Assume you have letters I U P U I and do the following step1) insert all the letters to a stack respectively step 2) Remove all the letters from stack and insert to a queue step 3) Remove each letter from Queue and print it out your output will be?

I U P U I

What is the time complexity of Build Heap operation. Build Heap is used to build a max(or min) binary heap from a given array

O(nLogn)

What is the worst case complexity of Bubble sort?

O(n^2)

What is the worst case complexity of selection sort?

O(n^2)

For the given recurrence relation T(n) = aT(n-b) + f(n) if a<1 The worst case complexity is

O(n^k)

What is the time complexity of Build Heap operation. Build Heap is used to build a max(or min) binary heap from a given array

O(nlogn)

Which of the following searching technique generally does not get affected on increasing the size of search list.

Search by Hashing

class Restaurant { public: void SetName(string restaurantName) { name = restaurantName; } void SetRating(int userRating) { rating = userRating; } void Print(); private: string name; int rating; }; void Restaurant::Print() { cout << name << " -- " << rating << endl; } Find true statement(s) - SetName() was defined inlined - variable "rating" must define in the public since it is used in the inline function - Member function Print() defined inline

SetName() was defined inlined

Find the correct statement of the following A. A class creator can overload a constructor by defining multiple constructors differing in parameter types B. ptr->classMember; or *ptr.classMember; is valid in creating class objects C. in c/c++ we can define function names with operators like +, -, * etc. D. function template and class template uses the same idea

all

What are the correct intermediate steps of the following data set when it is being sorted with the Selection sort? 15,20,10,1

What are the correct intermediate steps of the following data set when it is being sorted with the Selection sort? 15,20,10,1

In heap sort, after repeatedly deleting the last minimum element and construct, the array will contain elements in?

decreasing sorting order

Merge sort uses which of the following technique to implement sorting

divide and conquer

What are the minimum default functions required to implement Queue class after creating an empty Queue

enqueue(), dequeue(), isEmpty()

Given code: What is the final grade? double gradePoints = 85; char final_grade = 'F'; if(gradePoints > 90) final_grade = 'A'; if(gradePoints > 80) final_grade = 'B'; if(gradePoints > 70) final_grade = 'C'; else if(gradePoints > 60) final_grade = 'D';

final grade is C

What is the location of a parent node for any arbitary node i? (in heap)

floor(i/2) position

What is the location of a parent node for any arbitrary node i? (in a heap)

floor(i/2) position

To obtain an output as : 0 1 3 4 5 Add the following code for (int i = 0; i <= 5; ++i) { // code here cout<< i << " "; }

if(i==2) continue;

What is true about the complexity of the following void func(int n){ if(n>0){ log n =1 for(int i=0; i<n; i=i*2) cout<< n<<endl; func(n-1); } }

infinite loop

Find the output int key = 1; switch(key){ case 1: cout << "key is 1 "; case 2: cout << "key is 2 "; break; case 3: cout << "key is 3 "; case 4: cout << "key is 4 "; default: cout << "key is default "; break;}

key is 1 key is 2

Which of the following methods is the most effective for picking the pivot element?

median-of-three partitioning

Quick sort uses

partitioning

What are the minimum default functions required to implement stack class after creating an empty Stack

push(), pop(), isEmpty()

In a max-heap, element with the greatest key is always in which node?

root node

In a max-heap, element with the largest key is always in the ....?

root node

Suppose that we have numbers between 1 and 100 in a binary search tree and want to search for the number 55. Which of the following sequences CANNOT be the sequence of nodes examined (in tree traversal)?

{9, 85, 47, 68, 43, 57, 55}

Complexity of T(n) = 2T(n-1) +n is

Θ(n^2n)

Find complexity of T(n) = 4T(n/4) +n

Θ(nlogn) where log of base 4

Best Case Time Complexity of Binary Search is

Ω(1)

What is the worst case time complexity for search, insert and delete operations in a general BST?

O(n) for all

Find the Recurrence Relation func(int n){ if(n>1){ for(int i=0; i<n; i=i++) cout<< n<<endl; func(n/2); func(n/2); } }

T(n) = 2T(n/2) +n

find the recurrence relation of the following function void func (int n) { if(n>0 ){ cout<< n2<<endl; func(n-1); } }

T(n) = T(n-1) +2

Given that T(n) =T(n/m) + 1 find the qth step and q will be

T(n/m^q) +q where q = log^nm

In a Bubble sort structure, there is/are?

Two for loops, one nested in the other

In a selection sort structure, there is/are?

Two for loops, one nested in the other

What is true about LIFO(Last In First Out)

- Uses in Stacks - Same as FILO - Represents insertion & deletion operations respectively

What is true about using C++ templates (There may be more than one answer)

- What is true about using C++ templates (There may be more than one answer) - What is true about using C++ templates (There may be more than one answer)

What is true about memory leaks?

- When the ability to access the allocated memory loses, memory leak occurs - Failing to free allocated memory known as memory leak

Find the correct statement/s A. Registrar's line is a good analogy for Stack B. Stack remove the item most recently added C. Queue remove the item most recently added D. Stack remove the item least recently added

B

What are the application that you may use Queue

* Traffic analysis * Call waiting

What is true about Overriding member function?

- A virtual function is a member function that may be overridden in a derived class - Member function in the superclass can be altered by override function in the subclass - Base class and derived class can have the same name and parameters due to overriding

What statements are true about Priority Queue

- An element of higher priority is processed before any element of lower priority. - A priority queue is a collection of elements such that each element has been assigned a priority.

What statements are true about sequential search(unordered list) and binary search(ordered array)

- Binary search cannot perform on unordered list - Sequential search is slow in large data sets and binary search is slow in inserting data

What is true about scope?

- Block scopes can define using { } - Scope is Portion of the program where an identifier can be used - File scope will remain till end of the program

What is true about Derived class?

- Derived class can be a superclass of another - Derived class is a subclass - Derived class can access protected data of its superclass

Which of the following is a true about Binary Trees

- Height of complete tree with N nodes is ⎣log N⎦. - The height of a binary tree is the maximum number of edges in any root to leaf path

Which of the following is a true about Binary Trees

- Height of complete tree with N nodes is ⎣log N⎦. -The height of a binary tree is the maximum number of edges in any root to leaf path

What is true about Inheritance?

- Helps to extend a class to another class with more functionality - without inheritance there is no need of 'protected' access specifier - Two classes will have parent child relationship

What is true about Stack and Array?

- Insertion and deletion in array can be done at any index in the array. - An array is a collection of items stored at contiguous memory locations - A stack is a linear data structure in which elements can be inserted and deleted only from one side of the list (top)

Time Complexity of an algorithm can be approximated by

- Measuring 'End Time - Start Time' of a program. - Estimating Recurrence relations.

Find TRUE statements of Perfect Binary Tree

- Number of nodes at depth of 5 is 32 - Number of internal nodes in the tree with height 5 is 31 - Number of Leaf nodes at height 5 is 32

Which of the following is a true about Binary Trees

- The maximum number of binary trees that can be formed with three unlabeled nodes is 5 - Constructing Binary Tree with sorted keys will give you a Tree with shape of Linked List

Find what is true A. To give an lower bound on Ω= 'Big Omega' a function we use B. Complexity of the Binary Search is n2 C. For any 2functions f(n) and g(n), we have f(n)=Θ(g(n)) if and only if of(n)=O(g(n)) and f(n)=Ω(g(n)) D. worst case running time of an algorithm given by O = 'Big O'

A, C, D

Which of the following sorting algorithm does generally do not use recursion?

Bubble sort

What is the following code segment of AVL tree do? int avl(binarysearchtree root): if(not root) return 0 left_tree_height = avl(left_of_root) if(left_tree_height== -1) return left_tree_height right_tree_height= avl(right_of_root) if(right_tree_height==-1) return right_tree_height

Check the validity of AVL tree

Relation between children and the parent of heap (if start index is 1)

Children of parent k is located at 2k and 2k+1

What is following code segment would do node<T>* p1, *p2; p1= front1; p2= front2; while(p1->next != NULL) { p1 = p1->next; } p1->next = p2;

Combining two linked lists

What is following code segment would do node<T>* p1, *p2; p1= front1; p2= front2; while(p1->next != NULL) { p1 = p1->next; } p1->next = p2;

Combining two linked lists

What is the time taken to perform a delete min operation of a min Heap?

O(log N)

What is the time complexity of merge sort?

O(n log n)

If all the n elements are in an input array is equal for example {3,3,3,3,3,3}, What would be the running time of the Insertion sort Algorithm?

O(n)

What is the auxiliary space complexity in merge sort?

O(n)

What is the auxiliary space complexity of merge sort?

O(n)

What is the space complexity of a heap?

O(n)

When you store the following 10 values in array of length 10, using open hashing technique (chaining). What is the possible maximum time complexity of search. (n = 10) 0 10 20 30 40 50 60 70 80 90

O(n)

Quick sort uses

Partitioning

Which of the following methods Quick sort uses

Partitioning

Out put given as: num1 + num2 is 21 The possible function call will be void PrintSum(int num1, int num2) { cout << num1 << " + " << num2 << " is " << (num1 + num2); }

PrintSum(0 , 21);

The function travel() receives root of a Binary Search Tree (BST) and a positive integer k as arguments. What is the code segment prints // A BST node struct node { int data; struct node *left, *right; }; int count = 0; void travel(struct node *root, int k) { if (root != NULL && count <= k) { travel(root->right, k); count++; if (count == k) printf("%d ", root->data); travel(root->left, k); } }

Prints the kth largest element in BST

What does a sorting algorithm do?

Puts a list of items in sorted order

What is data structure would fit the idea of Last In Last Out (LILO)

Queues

Which of the following is not a stable sorting algorithm in its typical implementation.

Quick Sort

Which of the following is a double rotation?

RL rotation

What will the following code segment would do ?

Remove nodes from the front repeatedly

What will the following code segment would do ? Node<T>* p; while (front!= NULL) { p = front; front = front->next; delete p; }

Remove nodes from the front repeatedly

Binary Search works when the array is

Sorted in ascending order Sorted in descending order

What is following code segment do? Node* p; p = front; while(p->next != NULL) // while ( p != NULL) { cout<<data;p=p->next; }

Traversing a Linked List and print data

What is following code segment do? Node* p; p = front;while(p->next != NULL) // while p != NULL) { cout<<data; p=p->next; }

Traversing a Linked List and print data

Which of the following is Not an application of priority queue?

Undo operation in text editors

In Merge Sort, what (Data Structure) do you use to combine subarrays into a sorted whole ?

Uses an Auxiliary array

In a selection sort structure, there is/are?

two for loops, one nested in the other

Choose the correct code segment for merge sort.

void merge_sort(int arr[], int left, int right) { if (left < right) { int mid = left+(right-left)/2; merge_sort(arr, left, mid); merge_sort(arr, mid+1, right); merge(arr, left, mid, right); //function to merge sorted arrays } }

Choose the proper code for merge sort.

void merge_sort(int arr[], int left, int right) { if (left < right) { int mid = left+(right-left)/2; merge_sort(arr, left, mid); merge_sort(arr, mid+1, right); merge(arr, left, mid, right); //function to merge sorted arrays } }


Set pelajaran terkait

Introduction to Business Process: Chapter 2 Quiz

View Set

Ap Gov Chapter 6 Judiciary Study Guide

View Set

MGMT 1 - C/9 - PRODUCTION & OPERATIONS MANAGEMENT

View Set

Spotlight 9, Unit 1, Listen and learn

View Set