Data Structures Final Fall 2018 - SOLUTION
Data Structures Final Fall 2018 - SOLUTION
Graphs … node represent a course and an edge connect two nodes if their timings clash
Check if the graph is bipartite or not …. If its bipartite then 2 teachers are enough ….
d. Suppose you are implementing a web browser that has a collection of malicious websites and whenever a
user try to visit a web page, your browser must check whether that website is malicious or not. What data
structure is most suitable to represent this data and why? How would you solve this problem with your
suggested data structure? Briefly explain your idea.
e. For which character frequencies of encoding data, Huffman algorithm always generates a skewed binary
tree.
Fibonacci nos, or Frequency sum of two characters is smaller than the next frequency of character picked from
queue. For Example:
E A B C D
30 15 8 5 1
23
9 14
4 5 8 A3 -3
E2 2 2 3 T4 4
U2 S2 R2
.1 C1 D1 H1 I1
0110 111 1010 100 1011 0111 0011 100 0111 1011 000 1010 111 0100 110 100 110 111 0101 110 100 000
0010
Decoded Message:
l1-3s2T4R2U2C1T4U2R2E2S2-3D1A3T4A3-3H1A3T4E2.1
I-STRUCTURES-DATA-HATE.
g. Suppose we want to reverse first k elements in a FIFO queue. For example if the input queue is: {10, 20,
30, 40, 50, 60} and k=4. Then output queue must be: {40, 30, 20, 10, 50, 60}. The only functions available
for the Queue are:
Enque() – inserts a data item at the end of the queue
Dequeu() – Removes an element from the start of the queue and return the removed element
Isempyt() – Return true if queue is empty and false otherwise
getSize() – returns the number of elements in the queue
How would you reverse the first k elements of the queue using the above functions only? Explain your idea in
3-4 lines
Hint: You may use some other standard data structure to solve this problem
First dequeu k elements from the queue and push in the stack.
Then for all k element, pop from the stack and enque in the queue
Lastly, for first n-k elements of the queue deque one element at a time and enque at the end of the list.
Hint: the above DeleteMin operation is more or less similar to deletion in simple heaps.
The operation DeleteMin is analogous to deletion in conventional heaps. Specifically, the required element is
extracted and the vacant position is filled with the last element of the heap. The minmax ordering is
maintained after applying the TrickleDown procedure
void PrintSecondMax()
int min=data[2]
if(data[i]<min)
min = data[i];
cout<<min<<endl;