Numericals On Hashing and Sorting

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Que – 1.

 Given the following input (4322, 1334, 1471, 9679, 1989, 6171, 6173,
4199) and the hash function x mod 10, which of the following statements are
true? (GATE CS 2004) 
i. 9679, 1989, 4199 hash to the same value 
ii. 1471, 6171 hash to the same value 
iii. All elements hash to the same value 
iv. Each element hashes to a different value 
(A) i only 
(B) ii only 
(C) i and ii only 
(D) iii or iv 

Que – 2. The keys 12, 18, 13, 2, 3, 23, 5 and 15 are inserted into an initially
empty hash table of length 10 using open addressing with hash function h(k) = k
mod 10 and linear probing. What is the resultant hash table? 

Que – 6. Which one of the following hash functions on integers will distribute
keys most uniformly over 10 buckets numbered 0 to 9 for i ranging from 0 to
2020? (GATE-CS-2015) 
(A) h(i) =i^2 mod 10 
(B) h(i) =i^3 mod 10 
(C) h(i) = (11 ∗ i^2) mod 10 
(D) h(i) = (12 ∗ i) mod 10 

Q-3: Suppose you have the following sorted list [3, 5, 6, 8, 11, 12, 14, 15, 17, 18] and are using the
recursive binary search algorithm. Which group of numbers correctly shows the sequence of
comparisons used to find the key 8.

A. 11, 5, 6, 8
B. 12, 6, 11, 8
C. 3, 5, 6, 8
D. 18, 12, 6, 8
Q-4: Suppose you have the following sorted list [3, 5, 6, 8, 11, 12, 14, 15, 17, 18] and are using the
recursive binary search algorithm. Which group of numbers correctly shows the sequence of
comparisons used to search for the key 16?

A. 11, 14, 17
B. 18, 17, 15
C. 14, 17, 15
D. 12, 17, 15

Q-1: In a hash table of size 13 which index positions would the following two keys map to? 27, 130

A. 1, 10
B. 13, 0
C. 1, 0
D. 2, 3

Q-2: Suppose you are given the following set of keys to insert into a hash table that holds exactly 11
values: 113 , 117 , 97 , 100 , 114 , 108 , 116 , 105 , 99 Which of the following best demonstrates the
contents of the hash table after all the keys have been inserted using linear probing?

A. 100, __, __, 113, 114, 105, 116, 117, 97, 108, 99
B. 99, 100, __, 113, 114, __, 116, 117, 105, 97, 108
C. 100, 113, 117, 97, 14, 108, 116, 105, 99, __, __
D. 117, 114, 108, 116, 105, 99, __, __, 97, 100, 113

-4: Suppose you have the following list of numbers to sort: <br> [19, 1, 9, 7, 3, 10, 13, 15, 8, 12]
which list represents the partially sorted list after three complete passes of bubble sort?

A. [1, 9, 19, 7, 3, 10, 13, 15, 8, 12]


B. [1, 3, 7, 9, 10, 8, 12, 13, 15, 19]
C. [1, 7, 3, 9, 10, 13, 8, 12, 15, 19]
D. [1, 9, 19, 7, 3, 10, 13, 15, 8, 12]

Q-3: Suppose you have the following list of numbers to sort: [11, 7, 12, 14, 19, 1, 6, 18, 8, 20] which
list represents the partially sorted list after three complete passes of selection sort?

A. [7, 11, 12, 1, 6, 14, 8, 18, 19, 20]


B. [7, 11, 12, 14, 19, 1, 6, 18, 8, 20]
C. [11, 7, 12, 14, 1, 6, 8, 18, 19, 20]
D. [11, 7, 12, 14, 8, 1, 6, 18, 19, 20]

Q-3: Suppose you have the following list of numbers to sort: <br>
[15, 5, 4, 18, 12, 19, 14, 10, 8, 20] which list represents the partially sorted list after three
complete passes of insertion sort?
A. [4, 5, 12, 15, 14, 10, 8, 18, 19, 20]
B. [15, 5, 4, 10, 12, 8, 14, 18, 19, 20]
C. [4, 5, 15, 18, 12, 19, 14, 10, 8, 20]
D. [15, 5, 4, 18, 12, 19, 14, 8, 10, 20]

Q-3: Given the following list of numbers: <br> [21, 1, 26, 45, 29, 28, 2, 9, 16, 49, 39, 27, 43, 34, 46,
40] <br> which answer illustrates the list to be sorted after 3 recursive calls to mergesort?

A. [16, 49, 39, 27, 43, 34, 46, 40]


B. [21,1]
C. [21, 1, 26, 45]
D. [21]

Q-4: Given the following list of numbers: <br> [21, 1, 26, 45, 29, 28, 2, 9, 16, 49, 39, 27, 43, 34, 46,
40] <br> which answer illustrates the first two lists to be merged?

A. [21, 1] and [26, 45]


B. [[1, 2, 9, 21, 26, 28, 29, 45] and [16, 27, 34, 39, 40, 43, 46, 49]
C. [21] and [1]
D. [9] and [16]

Q-3: Given the following list of numbers [14, 17, 13, 15, 19, 10, 3, 16, 9, 12] which answer shows the
contents of the list after the second partitioning according to the quicksort algorithm?

A. [9, 3, 10, 13, 12]


B. [9, 3, 10, 13, 12, 14]
C. [9, 3, 10, 13, 12, 14, 17, 16, 15, 19]
D. [9, 3, 10, 13, 12, 14, 19, 16, 15, 17]

Q-4: Given the following list of numbers [1, 20, 11, 5, 2, 9, 16, 14, 13, 19] what would be the first
pivot value using the median of 3 method?

A. 1
B. 9
C. 16
D. 19
Q-5: Which of the following sort algorithms are guaranteed to be O(n log n) even in the worst case?

A. Shell Sort
B. Quick Sort
C. Merge Sort
D. Insertion Sort
Summary
 A sequential search is O(n)O(n) for ordered and unordered lists.
 A binary search of an ordered list is O(logn)O(log⁡n) in the worst case.
 Hash tables can provide constant time searching.
 A bubble sort, a selection sort, and an insertion sort are O(n2)O(n2) algorithms.
 A shell sort improves on the insertion sort by sorting incremental sublists. It falls
between O(n)O(n) and O(n2)O(n2).
 A merge sort is O(nlogn)O(nlog⁡n), but requires additional space for the merging process.
 A quick sort is O(nlogn)O(nlog⁡n), but may degrade to O(n2)O(n2) if the split points are not near the
middle of the list. It does not require additional space.

You might also like