Homework 6

[Me] | Nov 21, 2024 min read

Answer 1

                a b c d
Frequency       2 3 2 1
Distribution    2 5 7 8
Original Array (Reversed)Distribution ArrayNew Index (Distribution -1)
b[2 5 7 8]4
a[2 4 7 8]1
a[1 4 7 8]0
b[0 4 7 8]3
c[0 3 7 8]6
d[0 3 6 8]7
c[0 3 6 7]5
b[0 3 5 7]2

Updated Array

['a', 'a', 'b', 'b', 'b', 'c', 'c', 'd']

Answer 2

Yes, because same elements are placed in same order as they are seen in input array.

Answer 3

a.

If m is length of search string. Shift of j’th character is calculated by m - j - 1. Using this algo, shift table is

    A C  G T
    5 2 10 1

b.

    Text        : TTATAGATCTCGTATTCTTTTATAGATCTCCTATTCTT
    Pattern T 1 : TCCTATTCTT
    Pattern C 2 :  TCCTATTCTT
    Pattern T 1 :    TCCTATTCTT
    Pattern A 5 :     TCCTATTCTT
    Pattern T 1 :          TCCTATTCTT
    Pattern T 1 :           TCCTATTCTT
    Pattern T 1 :            TCCTATTCTT
    Pattern A 5 :             TCCTATTCTT
    Pattern T 1 :                  TCCTATTCTT
    Pattern C 2 :                   TCCTATTCTT
    Pattern C 2 :                     TCCTATTCTT
    Pattern T 1 :                       TCCTATTCTT
    Pattern A 5 :                        TCCTATTCTT
    Pattern T   :                             TCCTATTCTT [FOUND]

Pattern will be found after 10 searches

Answer 4

a.

Hashes

Kk(h)
308
209
561
759
319
198

Hash Table

idxValues
0
156
2
3
4
5
6
7
830->19
920->75->31
10

b.

Most key comparisons = 3 (For 31)

c.

Average can be calculated as following

$$ \dfrac{1}{6} + \dfrac{1}{6} + \dfrac{1}{6} + \dfrac{2}{6} + \dfrac{3}{6} + \dfrac{2}{6}=1.6666 \approx 1.7 $$

Answer 5

a.

Hashes are same as previous question

Closed Hash table.

012345678910
30
3020
563020
56302075
3156302075
315619302075

b.

Most key comparisons = 6 (For 19)

c.

Average can be calculated as following

$$ \dfrac{1}{6} + \dfrac{1}{6} + \dfrac{1}{6} + \dfrac{2}{6} + \dfrac{3}{6} + \dfrac{6}{6} \approx 2.3 $$

Answer 6

Operationunordered arrayordered arraybinary search treebalanced search treehashing
SearchΘ(n),Θ(n)Θ(log n),Θ(log n)Θ(log n),Θ(n)Θ(log n),Θ(log n)Θ(1),Θ(n)
InsertionΘ(1),Θ(1)Θ(n),Θ(n)Θ(log n),Θ(n)Θ(log n)Θ(log n)Θ(1),Θ(n)
DeletionΘ(1),Θ(1)Θ(n),Θ(n)Θ(log n),Θ(n)Θ(log n)Θ(log n)Θ(1),Θ(n)
comments powered by Disqus