Heapsort – C++

Heap sort is simple to implement, performs an O(n·lg(n)) in-place sort, but is not stable.

The first loop, the Θ(n) “heapify” phase, puts the array into heap order. The second loop, the O(n·lg(n)) “sortdown” phase, repeatedly extracts the maximum and restores heap order.
Example –
Sorting_heapsort_anim

  • Not stable
  • O(1) extra space (see discussion)
  • O(n·lg(n)) time
  • Not really adaptive

Algorithm –

(1) for x on list L do
(2) INSERT(x, S);
(3) while not EMPTY(S) do begin
(4) y := MIN(S);
(5) writeln(y);
(6) DELETE(y, S)
end

Click Down For Program –

Continue reading

BINARY SEARCH TREE : TRAVERSAL, INSERTION, SEARCHING

Binary Search Tree : Binary Search Tree is an ordered or sorted binary tree,in which traversing and searching a bit little complexion; Node having small value arranged in left side of root node, whether high value is arranged in in right side of root node.

Continue reading