You are on page 1of 13

1.

Following elements are to be stored in a hash table using


the hash function h(k) = k % 8 in the order shown: 65, 27,
50, 9, 36, 43, 20

Identify the hash values for which collision occurs.

a) Collision will occur for hash values 1,2


b) No collision will occur
c) Collision will occur for hash values 1,4
d) Collision will occur for hash values 1,3,4

Answer D
Explanation:
k=65, 27, 50, 9, 36, 43, 20
65%8=1
27%8=3
50%8=2
9%8=1
36%8=4
43%8=3
20%8=4

1: 65, 9
2: 50
3: 27,43
4: 36,20

2. Consider the below inputs:

input linked_list (Head to Tail): 1->2 ->5 ->3


input_stack (Top to Bottom): 4, 2, 5, 10

def generate (input linked list, input stack) :

©Talentio Solutions India Private Limited


5th Floor, Mayfair Building, SP Road, Begumpet, Hyderabad – 500 003
www.talentio.in
temp- input_linked_list.get_head()
#get head () returns the head node
element=0
while (temp.get_next () is not None) :
#get_next () returns the address of the next node
temp.set_data (temp.get_data () +temp.get_next ().get_data ()
+element)
#get data () returns the data stored in the node
if temp.get_data ()%2!=0:
temp.set_data (temp.get_data() +input_stack.pop())
#seg data (data) updates the data stored in the node
element-temp.get_data ()
else:
input_stack.push (element)
element=temp.get_next () .get_data ()
temp=temp.get_next ()
temp.set_data (temp.get_data ()+input_stack.pop ())
input_zack.push(element)
element=temp.get_next ().get_data ()
temp-temp.get_next ()
temp.set_data(temp.get_data ()+input_stack.pop())

What will be the content of input_linked_list from head to tail and


input_stack from top to bottom after the execution of the function
generate?

Assumption: Stack and LinkedList classes, with the necessary


methods, are available

a) input_linked_list (Head to Tail): 7->14->20->5


input_stack (Top to Bottom):5,10
b) input_linked_list (Head to Tail): 5->7->10->5
input_stack (Top to Bottom): 2,5, 10
c) input_linked_list (Head to Tail):7->14->20->3
input_stack (Top to Bottom):5,10
©Talentio Solutions India Private Limited
5th Floor, Mayfair Building, SP Road, Begumpet, Hyderabad – 500 003
www.talentio.in
d.)input_linked_list(Head to Tail):7->14->20->5
input_stack (Top to Bottom): 10

Answer B

Explanation:

All the nodes are checked for the values to be a multiple of 2 and when
they are not a value of the stack is popped and added to them and the
previous values are overwritten.

3. What would be the values of the output_queue from front to rear


when the below input_queue is passed as input to the given
function?
input_queue(front to rear): 3, 7, 6, 2, 5, 6, 3, 2

def function(input_queue):
output_queue=Queue (18)
while(not input_queue. is_empty()):
var=input queue.dequeue()
if var<=5:
output_queue. enquebb(input_queue.dequeue()+1)
else:
output_queue. enqueue
(output_queue.dequeue()+input_queue.dequeue())
return output_queue

Assumption:Queue class, the with necessary methods, is available

©Talentio Solutions India Private Limited


5th Floor, Mayfair Building, SP Road, Begumpet, Hyderabad – 500 003
www.talentio.in
a) 3, 6, 13, 3
b) 10, 7, 3
c) 10, 7, 3, 2
d) 8, 7, 5

Answer B
input_queue(front to rear): 3, 7, 6, 2, 5, 6, 3, 2
output_queue: 10,7,3

4. Consider the following Python code that depicts BINARY SEARCH


algorithm for the list of elements sorted in ASCENDING ORDER

def binary search(num_list, element):


low=0
high=len(num_list)-1
mid=(low+high)//2

while(num_list[mid]!=element and low<high) :


if(element>num_list[mid]):
low=mid+1
else:
high=mid-1
mid=(low+high)//2
if(element == num_list[mid]):
print(“element is in the list at Index",mid)
else:
print(" element is not in the list")

Note: Line numbers are for reference only

It has to be used on the list of elements sorted in DESCENDING ORDER


©Talentio Solutions India Private Limited
5th Floor, Mayfair Building, SP Road, Begumpet, Hyderabad – 500 003
www.talentio.in
what modification needs to be done in the given code.

a) Charge the code on line number 4 and 10 as mid= int((low+high)/2)

b) Change the code at line number 6 as if(num_list[mid]==element)

c) Change the code at line number 6 as if(element<num_list(mid))

d) Change the code at line number 6 as if(element>=num_list[mid])

Answer C

Explanation: For DESCENDING ORDER conditions are:

if(element<num_list[mid]): low=mid+1

if(element>num_list[mid]): high=mid-1

5. John is visiting a zoo. After roaming for sometime, he finds that he


has lost his way. John wants to reach the entry exit gate. He
remembers ‘Vans ice-Cream’, a landmark which he saw while
strolling in the zoo. John finds that there are 3 ways to reach Vans
Ice-Cream from his current location and from Vans Ice Cream There
are 4 ways to reach the entry exit gate.
Considering the above scenario, identify the most suitable data
structure that can be used to represent all possible ways to reach
the entry exit gate from John's current location?

a) Graph

b) Tree

c) Stack

©Talentio Solutions India Private Limited


5th Floor, Mayfair Building, SP Road, Begumpet, Hyderabad – 500 003
www.talentio.in
d) Queue

Answer A

Explanation: Graphs are awesome data structures that you use every
day through Google Search, Google Maps, GPS, and social media. They
are used to represent elements that share connections. The elements
in the graph are called Nodes and the connections between them are
called Edges. This is a similar instance.

6. Consider the stack stack1 with the following elements

stack1(top to 14 35 22 10 5 20
bottom)

Consider the following Python code:

def stack_function(stack1):
stack2=Stack(5)
while not stack1.is_empty():
if (stack1.pop()%5==0):
break
else:
if (not stack1.is_empty()):
stack2.push(stack1.pop()*2)
if stack2.is empty():
stack1.pop()
else:
stack2.push(10)
return stack2

What will be the content of stack2 from top to bottom after the
©Talentio Solutions India Private Limited
5th Floor, Mayfair Building, SP Road, Begumpet, Hyderabad – 500 003
www.talentio.in
execution of the above function when stack 1 is passed as input
parameter.

Assumption:Stack class with the necessary methods is available.

a) 10 20 10 70
b) 70 10 20 10
c) 50 20 10 70
d) 10 70 10 70

Answer A
stack1(top to bottom): 14, 35, 22, 10,5,20
stack2(top to bottom): 10 20 10 70

7. Consider the below code snippet.


identify the most efficient test data set for testing the below code
using ‘Logic Coverage’ technique.

if previous_year_percentage>75 and previous_year_percentage<=85:


scholarship=5000

elif previous_year_percentage>85 and


previous_year_percentagec<=95:
scholarship=3000

elif previous_year_percentage>95:
scholarship=10000

else:
scholarship=0

©Talentio Solutions India Private Limited


5th Floor, Mayfair Building, SP Road, Begumpet, Hyderabad – 500 003
www.talentio.in
a) 79, 87, 91, 99

b) 78, 80, 92, 99

c) 74, 77, 9o, 100

d) 74, 75, 76, 84, 85, 86, 94 95, 96, 97

Answer C
Explanation:
Logic corresponds to the internal structure of the code and this testing
is adopted for safety-critical applications such as software used in the
aviation industry. This Test verifies the subset of the total number of
truth assignments to the expressions.
Basically, you would be testing all the conditional statements for their
respective True and False inputs. Here option C and option D provide
logic coverage but the efficient one among them would be option C.

8. The following numbers are to be stored in a hash table (arriving in


the order shown) using the hash function , h(k) = k%5
4, 7, 16, 8, 18
Identify for which numbers
collision will NOT occur
after mapping the
numbers
with the diven hash function.
a) 4, 7, 16, and 8
b) 4, 7 and 16
©Talentio Solutions India Private Limited
5th Floor, Mayfair Building, SP Road, Begumpet, Hyderabad – 500 003
www.talentio.in
c) 4, 7, 16 and 18
d) 4 and 7

Answer B

Explaianation: h(k) = k%5


k= 4, 7, 16, 8, 18

4%5=4

7%5=2

16%5=1

8%5=3

18%5=3

9. Consider the following in_stack:


Consider the below python
function which takes the
above in_stack as input
parameter

def alter_stack ( in_stack) :


out_stack = Stack(5)
While ( not in_stack, is_empty ( ) ):
val = in_stack,pop ( )
if ( not in_stack,is_empty ( ) ):
temp_val= in_stack.pop ( )
Out_Stack.push (valv+vtemp_val)
in_stack.push(temp_val)
else:
©Talentio Solutions India Private Limited
5th Floor, Mayfair Building, SP Road, Begumpet, Hyderabad – 500 003
www.talentio.in
out_Stack.push (2)
return out_stack
What will be the content of
the out_stack (top to
bottom) after the
execution of the above
function?
Assumption: Stack class,
with the necessary methods
is available
a) 2, 5, 9
b) 1, 3, 5, 7, 9
c) 2, 3, 5, 7, 9
d) 2, 7, 9

Answer: c

10. Consider an output _queue with the following elements


Consider the following Python function which accepts the
input_queue(front to rear)=4,3,13,8,2 and an integer number as
input parameters:

Def queue_function (input_queue, num);


Output_queue=Queue(5)
Temp_queue=Queue(5)
While(num>0);
num=num-(input_queue.dequeue())
If(num%2==0):
Temp_queue,enqueue(input_queue.dequeue())
While(not temp_queue.is_empty()):
Temp1=input_queue.dequeue()

©Talentio Solutions India Private Limited


5th Floor, Mayfair Building, SP Road, Begumpet, Hyderabad – 500 003
www.talentio.in
Temp2=temp_queue.dequeue()
Output_queue.enqueue(temp1+temp2)
Return output_queue

What will be the contents of output_queue after execution of the


above function when the given input_queue and num=8 is passed
as parameters?
Note: the orders of elements in options is from front to rear
Assumption: Queue class with the necessary method is
available
A)11.5
B)9
C)8
D)none

Answer c

11. What will be the output of the following code?

def vegetables(veggies):
veggies.push(“Eggplant”)
veggies.push(“Carrot”)
veggies.push(“Beetroot”)
eaten=Stack(7)
while not veggies.is_empty():
#”find”method returns -1 if passed substring is not
found
if veggies.pop().find(‘r’)!=-1:
eaten.push(veggies.pop())
else:

©Talentio Solutions India Private Limited


5th Floor, Mayfair Building, SP Road, Begumpet, Hyderabad – 500 003
www.talentio.in
eaten.push(‘NA’)
return eaten
veggies=Stack(7)
veggies.push(“Onion”)
veggies.push(“Potato”)
veggies.push(“Broccoli”)
veggies.push(“Cabbage”)
print (vegetables(veggies))
Assumption: Stack class,with the necessary
methods is available,is available

a) Stack data(Top to Bottom):NA NA Potato


NA NA Carrot
b) Stack data(Top to Bottom):NA Potato NA NA Carrot
c) Stack data(Top to
Bottom):NA NA Broccoli NA
NA Carrot Beetroot
d) Stack data(Top to Bottom):Carrot NA NA Potato NA

Answer b

12. Which of the following hash


functions hash functions would
lead to the least number of
collisions when the following
values are stored in the hash table?
48, 98, 34, 25, 18

a)H(key) = key968
b)H(key) = key9610

©Talentio Solutions India Private Limited


5th Floor, Mayfair Building, SP Road, Begumpet, Hyderabad – 500 003
www.talentio.in
c)H(key) = key969
d)H(key) = key963

13. Which of the following hash functions is the best if the


following elements – 2, 4, 6, 18,
84, and 90 are to be stored in a
hash table ?
a. H(K)=K%2
b. H(K)=K%3
c. H(K)=K%4
d. H(K)=K%5

Answer D
Explaianation:
k=2, 4, 6, 18, 84, 90
k%2: 0,0,0,0,0,0
k%3: 2,1,0,0,0,0
k%4: 2,0,2,2,0,2
k%5: 2,4,1,3,4,0
collisions are less in k%5

©Talentio Solutions India Private Limited


5th Floor, Mayfair Building, SP Road, Begumpet, Hyderabad – 500 003
www.talentio.in

You might also like