Skip to main content

Posts

Showing posts from January, 2022

Binary Tree | Inorder, Preorder, Postorder Recursive and Non-Recursive Traversal | Mirror Binary Tree | Height of Tree | Cloning Binary Tree | Number of Leaves | Number of Internal Nodes | Erasing all nodes of Binary Tree

  Problem Statement: Beginning with an empty binary tree, construct a binary tree by inserting the values in the order given. After constructing a binary tree perform the following operations on it- Perform inorder, preorder and postorder traversal (Implement both recursive and non-recursive methods) Change a tree so that the roles of the left and right pointers are swapped at every node Find the height of the tree Copy this tree to another  Count number of leaves, number of internal nodes. Erase all nodes in a binary tree Note :- Scroll horizontally to see the full line of code. #include < iostream > using namespace std ; class node {     // data members public :     int data ;     node * left ;     node * right ;     // node constructor     node ( int val )     {         data = val ;     } }; class nodePointer { public :     node * link ;   ...

What is Software? | It's Applications

  Software is:     1) Instructions (computer programs) that when executed provide desired features, function, and performance;     2) data structures that enable the programs to adequately manipulate information and      3) documentation that describes the operation and use of the programs. Photo by Radowan Nakif Rehan on Unsplash Software Applications: System software application software engineering/scientific software embedded software product-line software WebApps (Web application) AI software Software - New Categories Open Word Computing - pervasive, distributed computing Ubiquitous computing - wireless networks Netsourcing - the Web as a computing engine Open Source - "free" source code open to the computing community (a blessing, but also a potential curse!)

Quick Sort using Python | Data Structure and Algorithm

  Code: Note:- Scroll horizontally to see the full line of code. def swap ( arr , i , j ):     # takes arr as list, and swaps the element at i and j th postion of the arr     temp = arr [ i ]     arr [ i ] = arr [ j ]     arr [ j ] = temp def partition ( arr , start , end ):     # return the index of the pivot element of arr     pivot = arr [ end ]     i = start - 1     for j in range ( start , end ):         if ( arr [ j ] < pivot ):             i = i + 1             swap ( arr , i , j )     swap ( arr ,( i + 1 ), end )     return ( i + 1 ) def quick_sort ( arr , start , end ):     # takes arr as list to be sorted and start and end index of list arr     if ( start < end ):         pivot = partition ( arr , start , end )         # ...

Shell Sort using Python | Data Structure and Algorithm

  Code: Note:- Scroll horizontally to see the full line of code. def shell_sort ( a , n ):     # a is list to be sorted and n is the length of list     gap = n // 2     p = 1     while ( gap >= 1 ):         for i in range ( gap , n ):             current = a [ i ]             j = i - gap             while (( a [ j ] > current ) and j >= 0 ):                 temp = a [ j + gap ]                 a [ j + gap ] = a [ j ]                 a [ j ] = temp                 j = j - gap             a [ j + gap ] = current         gap = gap // 2         print ( " Pass " , p , " : " , a )      ...

Insertion Sort using Python | Data Structure and Algorithm

  Code: Note:- Scroll horizontally to see the full line of code. def insertion_sort ( a , n ):     # a is list to be sorted and n is the length of list     for i in range ( 1 , n ):         current = a [ i ]         j = i - 1         while (( a [ j ] > current ) and j >= 0 ):             temp = a [ j + 1 ]             a [ j + 1 ] = a [ j ]             a [ j ] = temp             j = j - 1         a [ j + 1 ] = current         print ( " Iteration " , i , " : " , a )     return a

Fibonacci Search using Python | Data Structure and Algorithms

  Code: Note:- Scroll horizontally to see the full line of code. def fibonacci_search ( a , target ):     # a is list of intergers and target is key element to be searched     n = len ( a )     fibn_2 = 0     fibn_1 = 1     fibn = fibn_1 + fibn_2     while ( fibn <= n ):         fibn_2 = fibn_1         fibn_1 = fibn         fibn = fibn_1 + fibn_2     offset =- 1     while ( fibn_1 != 0 ):         i = min (( offset + fibn_2 ), n - 1 )         if ( target > a [ i ]):             fibn = fibn_1             fibn_1 = fibn_2             fibn_2 = fibn - fibn_1             offset = i         elif ( target < a [ i ]):             fibn = f...

Sentinel Search using Python | Data Structure and Algorithm

  Code: Note:- Scroll horizontally to see the full line of code. def sentinel_search ( a , target ):     # a is list of intergers and target is key element to be searched     a . append ( target )     i = 0     while ( a [ i ] != target ):         i += 1     if ( i < ( len ( a ) - 1 )):         print ( target , " is present at index " , i )     else :         print ( target , " not found in list " )