Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) A method that requires on the values being sorted in order is a) separate cha

ID: 3917973 • Letter: 1

Question

1) A method that requires on the values being sorted in order is a) separate chaining b) binary search c) linear probing d) quadratic probing 2) In an array named arr of size 5, if we coutecarr[10] this would give a) a runtime error for out-of bounds b) The contents of the location in RAM that would be re 1l r geste ma anti 3) If we have a vector of size 7 containing the numbers 1,2,3,4,5,6,7 and we use vec.resize(5) vec will now contain a) 1,2,3,4,5 b) 12,3,4,5,0,0 c) 3,4,5,6,7 d) it is not possible to resize a vector 4) In the Division Method, h/k)- Ikl mod N collisions are minimized if N is a) a prime number b) a composite (non-prime] number c) a negative number d) 1/k el an even number 5) Accessing an element of an array is a) O(n2) b} O(n) c} O(1) 6) For the tree below, the PostOrder traversal is: a) BCA b) BAC c)ABC d) CAB el CBA

Explanation / Answer

Ans 1:option b (binary search 0

Binary search required the data to be in sorted order and check for mid element

if the search element is greater than mid element will call itself for right subarray

if it is less than mid element will call itself for left subarrayarray

if it is equal to mid element will return the index of mid elementyou have to do the O(n log n) sorting only once, and then you can do the O(log n) binary search as often as you want, whereas linear search is O(n) every time.

Ans 2: option b(The content of the location of RAM that would be at arr[10]= i.e. accesing te data on the location (arr+sizeof (data type)*10) which is a garbage value.

Ans 3: option a (1,2,3,4,5)

resize(int x) – Resizes the vector container so that it contains first ‘x’ elements.

example:

#include <iostream>

#include <vector>

using namespace std;

int main()

{

vector<int> v1;

for (int i = 1; i <= 8; i++)

v11.push_back(i);

cout << "size : " << v1.size();

// resizes the vector size to 5

v1.resize(5);

// prints the vector size after resize()

cout << " size after resize : " << v1.size();

cout << " vector elements are: ";

for (auto it = v1.begin(); it != v1.end(); it++)

cout << *it << " ";

}

output: size:8

size after resize:5

vector elements are :1 2 3 4 5

Ans 4: option a (Prime Number)

Lets suppose you generate the hashcodes k as 5, 10, 15, 20, 25 and n is 10.

After taking modulo of k%n all the keys will either go to index 0 or 5.

So if we have k of the form y, 2y, 3y, 4y,5y…., and n= t, the number of indices that will be used for hashing will be = t/GCF(t,x)

So if we choose t to be Prime, GCF(t,x) will be 1 and the keys will be distributed across the table.

Ans 5: Accesing of array element is O(1) as we know the index and using index an array element can be accessed directly;

ex:

#include<stdio.h>

int main()

{

int arr[]={1,2,3}

printf("%d",arr[2]);

}

output: 3 //(as index start from 0 so 3rd element will be returned or element with index 2 is printed)

Ans 6 : Post order Traversal (Left Right and NODE (LRN) for each node)

starting from root node A:

go to left node B : B don't have left node so check for right node of B and there is no right node of B

so put B in result now go to right of node A i.e. node C so similiary to B node c have both left and right node null so C is also appended to result and node A is appended

so result: BCA (option A)