Sunday 21 July 2019

UGC NET Computer Science July 2018 - II | Question 23

Question 23
A hash function h defined h(key)=key mod 7, with linear probing, is used to insert the keys 44, 45, 79, 55, 91, 18, 63 into a table indexed from 0 to 6. What will be the location of key 18 ?

Options:
  1. (1) 3
  2. (2) 4
  3. (3) 5
  4. (4) 6
Answer : (3) 5

Explanation Question 23

Given:
Hash table has indexed from 0 to 6.
keys are 44, 45, 79, 55, 91, 18, 63
h(key)=key mod 7  ( h(key) value is in range of 0-6 inclusive)

Solution:

Table after inserting 44, 45
h(key)= key mod 7
h(44) = 44 mod 7 = 2
h(45) = 45 mod 7 = 3
44 is placed position 2 and 45 is placed at position 3.

0 1 2 3 4 5 6
 -   -  44 45  -   -   - 

Table after inserting 79
h(79) = 79 mod 7 = 2
but 2 is already filled by 44, linear probing is applied but 3 is also filled by 45.
To apply linear probing, we check for the next unoccupied position in the table.
So, 79 will occupy 4.

0 1 2 3 4 5 6
 -   -  44 45 79  -   - 

Table after inserting 55, 91
h(55) = 55 mod 7 = 6
h(91) = 91 mod 7 = 0
55 is placed position 6 and 91 is placed at position 0.

0 1 2 3 4 5 6
91  -  44 45 79  -  55

Table after inserting 18
h(18) = 18 mod 7 = 4
but 4 is occupied by 79 so, it will occupy 5.

0 1 2 3 4 5 6
91  -  44 45 79 18 55

Table after inserting 63
h(63) = 63 mod 7 = 0.
0 is also occupied so, it will occupy 1.

0 1 2 3 4 5 6
91 63 44 45 79 18 55

So, option (3) is correct.

PreviousNext
UGC NET CS 2018 July - II Question 22UGC NET CS 2018 July - II Question 24

UGC NET Computer Science July 2018 - II Question 22

Question 22
22. Consider the array A=<4, 1, 3, 2, 16, 9, 10, 14, 8, 7>. After building heap from the array A, the depth of the heap and the right child of max-heap are _________ and _________ respectively. (Root is at level 0).

Options:
  1. (1) 3, 14
  2. (2) 3, 10
  3. (3) 4, 14
  4. (4) 4, 10
Answer : (2) 3, 10

Explanation Question 22

The depth of the max-heap is 3

The right child of max-heap is 10

NTA UGC NET Computer Science 2018 July - II Question 22 - Max heap from array
Max-heap from the array A =<4, 1, 3, 2, 16, 9, 10, 14, 8, 7>

PreviousNext
UGC NET CS 2018 July - II Question 21UGC NET CS 2018 July - II Question 23

Saturday 20 July 2019

UGC NET Computer Science July 2018 - II Question 17

Question 17
17. A software design pattern often used to restrict access to an object is :

Options:
  1. (1) adapter
  2. (2) decorator
  3. (3) delegation
  4. (4) proxy
Answer : (4) proxy

Explanation Question 17
  • Proxy Pattern → We need the ability to control the access to an object. The light objects are called proxies and they will instantiate those heavy objects when they are really need and by then we'll use some light objects instead.  Use of the proxy can simply be forwarding to the real object or to provide additional logic. A proxy is a Interface or wrapper or agent object. Proxy is being called by the client to access the real object serving behind the scenes. 
    Read more about - Proxy Pattern
  • Adapter → Match interface of different classes.
  • Decorator → Add responsibilities objects dynamically. Effectively in the instantiation process, object-creation patterns use delegation effectively to get the job done.
  • Delegation → In software engineering, the delegation pattern is an object-oriented design pattern that allows object composition to achieve the same code reuse as inheritance. In delegation, an object handles a request by delegating to a second object (the delegate). The delegate is a helper object, but with the original context.
From above definations we conclude that "Proxy is a software design pattern often used to restrict access to an object"

So, Option (4) is correct answer.

Similar Questions:

1. A design pattern used to enhance the functionality of an object is
(a) Adapter
(b) Decorator
(c) Delegation
(d) Proxy

2. A design pattern often used to restrict access to an object is
(a) Adapter
(b) Decorator
(c) Delegation
(d) Proxy

3. You have a class that accepts and returns values in British Imperial units (feet, miles, etc.), but you
need to use metric units. The design pattern that would best solve your problem is
(a) Adapter
(b) Decorator
(c) Delegation
(d) Proxy

Question Reference::https://courses.cs.washington.edu/courses/cse331/18sp/exams/cse331-12sp-final-sol.pdf

UGC NET Computer Science December 2019 | Question 16

Question 16 In a certain coding language. 'AEIOU' is written as 'TNHDZ'. Using the same coding language. 'BFJPV' wil...

Popular Posts