Blog

python tutorials and learn python

Created with Sketch.

Python Program for Iterative Quick Sort

Python Program for Iterative Quick Sort # Python program for implementation of Quicksort    # This function is same in both iterative and recursive def partition(arr,l,h):     i = ( l – 1 )     x = arr[h]       for j in range(l , h):         if   arr[j] <= x:               # increment index of smaller element             i…
Read more

Python Program for QuickSort

Python Program for QuickSort Like Merge Sort, QuickSort is a Divide and Conquer algorithm. It picks an element as pivot and partitions the given array around the picked pivot.

Python Program for Recursive Insertion Sort

Python Program for Recursive Insertion Sort Insertion sort is a simple sorting algorithm that works the way we sort playing cards in our hands. Below is an iterative algorithm for insertion sort Algorithm // Sort an arr[] of size n insertionSort(arr, n) Loop from i = 1 to n-1. a) Pick element arr[i] and insert…
Read more

Python Program for Insertion Sort

Python Program for Insertion Sort Insertion sort is a simple sorting algorithm that works the way we sort playing cards in our hands. # Python program for implementation of Insertion Sort   # Function to do insertion sort def insertionSort(arr):       # Traverse through 1 to len(arr)     for i in range(1, len(arr)):           key =…
Read more

Python Program for Linear Search

Python Program for Linear Search Problem: Given an array arr[] of n elements, write a function to search a given element x in arr[]. Examples : Input : arr[] = {10, 20, 80, 30, 60, 50, 110, 100, 130, 170} x = 110; Output : 6 Element x is present at index 6 Input :…
Read more

Execute a String of Code in Python

Execute a String of Code in Python Given few lines of code inside a string variable and execute the code inside the string. Examples: Input: code = “”” a = 6+5 print(a)””” Output: 11 Explanation: Mind it that “code” is a variable and not python code. It contains another code, which we need to execute.…
Read more

Python | Permutation of a given string using inbuilt function

Python | Permutation of a given string using inbuilt function A permutation, also called an “arrangement number” or “order”, is a rearrangement of the elements of an ordered list S into a one-to-one correspondence with S itself. A string of length n has n! permutation. Examples: Input : str = ‘ABC’ Output : ABC ACB…
Read more