Posts

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

To the 20 year old me

2020 has just ended. This year was a strange one. It was the year, which claimed millions of lives, jobs and confined us to stay at our homes due to the pandemic. I just turned 20, a few days back. 20, an age where one says a goodbye to their teen life and enters into the proper adulthood.  This year was sadly one of the most unproductive years of my life. I stayed most of my time indoors, playing games and studying nothing. But as the year has ended, I am optimistic that at least, this year I will value the time and turn the most out of it into something fruit-full.  A short poem, which I wrote to myself for the future Abhishek to read.    To the 20 year old me Abhishek, now you are 20, an age of duties and responsibilities. You dream a lot, you think a lot, your ambitions are as big as it could be, but sadly there is no effort to turn it into a reality. The next five years mean a lot, a job to find and to meet a girl, who would be the one. So don't waste your time in the foolish

Comparison Logical and Bitwise Operator ( Java Part - 4 )

J ava Comparison Operators Comparison operators are used to compare two values: Operator Name Example Try it == Equal to x == y Try it » != Not equal x != y Try it » > Greater than x > y Try it » < Less than x < y Try it » >= Greater than or equal to x >= y Try it » <= Less than or equal to x <= y Try it » Java Logical Operators Logical operators are used to determine the logic between variables or values: Operator Name Description Example Try it &&  Logical and Returns true if both statements are true x < 5 &&  x < 10 Try it » ||  Logical or Returns true if one of the statements is true x < 5 || x < 4 Try it » ! Logical not Reverse the result, returns false if the result is true !(x < 5 && x < 10) Try it » Java Bitwise Operators Bitwise operators are used to perform binary logic with the bits of an integer or long integer. Operator Description Example Same as Result Decimal & AND -