Posts

Showing posts from 2019

WHAT IS INSERTION SORT ?

Image
INSERTION SORT  I nsertion sort is a very simple sorting algorithm in which the sorted array (or list) is built one element at a time. We all are familiar with this technique of sorting, as we usually use it for ordering a deck of cards while playing bridge. The main idea behind insertion sort is that it inserts each item into its proper place in the final list. To save memory, most implementations of the insertion sort algorithm work by moving the current data element past the already sorted values and repeatedly interchanging it with the preceding value until it is in its correct place. Insertion sort is less efficient as compared to other more advanced algorithms such as quick sort, heap sort, and merge so Technique    Insertion sort works as follows:  The array of values to be sorted is divided into two sets. One that stores sorted values and another that contains unsorted values.   The sorting algorithm will proceed unti...

What is Bubble sort exactly is ?

Image
Bubble sort  algorithm    Bubble sort is a very simple and very  easy to implement  sorting technique Default arrange in  ascending order  logic  let's take an example, an example, we have a list of numbers stored in array                                                                                       logic start with comparison of first two element and if the left element is greater than right element they swap their position  Comparison proceeds till the end of array  logical illustration  ALGORITHM  Modified ALGORITHM :- Bubble_Sort(A,N): A is array of values and N is the number of element    Repeat step 2,3,&4 for round =1,2,3,....

Memory Management

Total memory allocation of a Program are divided into 4 parts  Instruction Data Stack   Heap what they store ? Instruction   --- store all lines and instruction in program . Data  --   global and static variable. Stack --  function , local , variable, variable in  function ,recursion time memory                           and loop (any memory that are needed for operation)                           time and various memory that are required at time while performing job . Heap -- dynamic created memory.(by malloc , new )  Instruction   and Data     both memory size are fix at the time of program start . 2. Stack and Heap     memory co...

What is Memory Leak? Discuss the importance.

Image
What is Memory Leak? First we have to understand memory management. Memory leak occurs when programmers create a memory in heap and forget to delete it. Memory leaks are particularly serious issues for programs like daemons and servers  Memory leakage occurs in C++ when programmers allocates memory by using new keyword and forgets to deallocate the memory by using delete() function or delete[] operator. One of the most memory leakage occurs in C++ by using wrong delete operator. The delete operator should be used to free a single allocated memory space, whereas the delete [] operator should be used to free an array of data values. In c /* Function with memory leak */ #include <stdlib.h> void f () { int *ptr = ( int *) malloc ( sizeof ( int )); /* Do some work */ return ; /* Return without freeing ptr*/ }  In c++ // Program with memory leak #include <bits/stdc++.h> using ...