algorithm contains(value prevalue is the value to search the heap for count is the number of items in the heap heap is the array used to store the heap items postvalue is located in the heapin which case trueotherwise false - while count and heap[ value - + end while if count return true else return false end if end contains the problem with the previous algorithm is that we don' take advantage of the properties in which all values of heap holdthat is the property of the heap strategy being used for instance if we had heap that didn' contain the value we would have to exhaust the whole backing heap array before we could determine that it wasn' present in the heap factoring in what we know about the heap we can optimise the search algorithm by including logic which makes use of the properties presented by certain heap strategy optimising to deterministically state that value is in the heap is not that straightforwardhowever the problem is very interesting one as an example consider min-heap that doesn' contain the value we can only rule that the value is not in the heap if the parent of the current node being inspected and the current node being inspected nodes at the current level we are traversing if this is the case then cannot be in the heap and so we can provide an answer without traversing the rest of the heap if this property is not satisfied for any level of nodes that we are inspecting then the algorithm will indeed fall back to inspecting all the nodes in the heap the optimisation that we present can be very common and so we feel that the extra logic within the loop is justified to prevent the expensive worse case run time the following algorithm is specifically designed for min-heap to tailor the algorithm for max-heap the two comparison operations in the else if condition within the inner while loop should be flipped