예제 #1
0
def search_hufftree(items):
    defective = 0
    tree = hs.encode(items)
    l, r = hs.group(tree)

    return defective
예제 #2
0
#        branch_sum = sum([t[0] for t in current_branch])
#        if branch_sum !=0 :
#            if(len(current_branch)==1):
#                defective.append(current_branch)
#                exit
#            else:
#                l,r = hs.group(current_branch)
#                to_crawl.extendleft([r])
#                to_crawl.extendleft([l])
#        loops += 1
#    return loops-len(to_crawl),defective
    
#items to search
n = 4
items = [0]*n
position = randint(0,n-1)
items[2] = 1

#probabilities
probs = [2**-(x+1) for x in range(0,n)] #[0.5, 0.25, 0.125, 0.125]# #np.random.dirichlet([1]*n)
non_iid_items = zip(items, probs)

#binary searching the items
defindex, bsloops = binary_search(items)

#huffman searching the items
t = hs.encode(non_iid_items)
hsloops = huffman_search(t)