Posts

Showing posts from January, 2021

Heap Sort

Image
  Heap Sort Algorithm In this tutorial, you will learn how heap sort algorithm works. Also, you will find working examples of heap sort in C, C++, Java and Python. Heap Sort is a popular and efficient sorting algorithm in computer programming. Learning how to write the heap sort algorithm requires knowledge of two types of data structures - arrays and trees. The initial set of numbers that we want to sort is stored in an array e.g.  [10, 3, 76, 34, 23, 32]  and after sorting, we get a sorted array  [3,10,23,32,34,76] Heap sort works by visualizing the elements of the array as a special kind of complete binary tree called a heap. As a prerequisite, you must know about  a complete binary tree  and  heap data structure . Relationship between Array Indexes and Tree Elements A complete binary tree has an interesting property that we can use to find the children and parents of any node. If the index of any element in the array is  i , the element in the index  2i+1  will become the left chil

Format() Function in Python

Definition :  The format function is used for printing a certain type of value held within the second bracket. Syntax :  print( " STATEMENT .....{}.....STATEMENT.....".format(<variable name>/ <value>))  Important things to remember :- 1. If we use a variable name, we should leave the brackets empty {}, rather than {<variable name>}. 2.Not only variables we can also replace constants for example : - print("Hello {word}".format(word = "world")), we will get the output as " Hello world ". 3. We can also leave the {} empty rather than replacing by a constant. For example print(" Hello {} ".format("World")), this will also give the output as " Hello world" Program in Online Compiler Formatting Types Inside the placeholders you can add a formatting type to format the result: :< Try it Left aligns the result (within the available space) :> Try it Right aligns the result (within the available space