Suppose there are three decks of cards on the table, a number is written on each
ID: 3843097 • Letter: S
Question
Suppose there are three decks of cards on the table, a number is written on each card. And each deck is sorted in decreasing order (The maximum value is on the top). The goal is to find the minimum value between all these three decks with the smallest number of steps. You only can see the top card. Use stack and recursion to solve this problem. Using the following key-value pairs, answer to the the questions: (98, Brent), (76, Amyntas), (54, Sharar), (31, Fedele), (23, Olav), (46, Dharma), (78, Isiah), (64, Calixto), (57, Osheem), (43, Hippokrates), (52, Anatoliy), (34, Prasas), (77, Kepa) Insert the key-value pairs in a hash table of size 10. What happens if the hash function is not good? How to solve the problem without changing the hash function? (Suppose we don't know what is a good hash function) Insert the key-value pairs inside a BS-Tree. Do an in-order tree walk over the tree to print out the contents. What is the average search time in the tree if it is balanced? What is the worst case scenario for a BS-Tree and what would be the average running time for that case? Use heapsort to sort the key-value pairs. You have to show each step of making a heap (Only the result of heapify). And how step by step you sort the result (Only result of heapify). Create the following data structure. Each node has a x, y and z child node. Each node has a left and right sibling nodes that connects it to its siblings. To insert a value in the data structure it will be compared with each node, and it will be inserted in a branch that has closest value. If one of the siblings are empty this value will be placed. What is the average insert time in the balanced structure?Explanation / Answer
The approach can be as follows:
1. All the three decks can be considered as stacks.
2. All the decks are arranged in decreasing order so this means the smallest card (most minimum) will be at the bottom
of the stack for every deck of cards.
3. We need to find the card with minimum value among the three decks
4. So one of the appraoch will be to keep on popping the three decks till they conatin the last card.Then we can find the minimum of these three cards and get the minimum value card out of three decks.
minimumof (a , b, c){
if (c <= a && c <= b)
return c
if (a <= c && a <= b)
return a
if (b <= a && b <= c)
return b
}
findminimum (deck1, deck2, deck3){
if (size(deck1) == 1 && size(deck2) == 1 && size(deck3) == 1){
return minimumof(pop(deck1), pop(deck2), pop(deck3))
}
else {
if (size(deck1) > 1)
pop(deck1)
if (size(deck2) > 1)
pop(deck2)
if (size(deck3) > 1)
pop(deck3)
findminimum (deck1, deck2, deck3)
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.