Posts

Showing posts from September, 2021

Complete Binary tree(CBT) and Almost Complete Binary tree(ACBT): Total nodes and formulae :

Connect with me on Instagram         Twitter             LinkedIn              my website                facebook          Whatsapp                gmail   Important  about CBT(complete binary tree) & ACBT(Almost complete binary tree) let : k = level of tree, n = total nodes, ^ is power  total nodes in CBT : 2 (k-1)    total nodes n : n =  2 (k) – 1 in kth level CBT :                                     leaf nodes  : (n/2) + 1 ;                                  non leaf nodes : (n/2) ; in CBT i k level , n nodes then :                                n  =  2 (k) – 1                              n + 1 =  2 (k)   taking log both side with base 2 ,                            k = Log 2( n); in a 10 level CBT :                              maximum nodes : 1023 (2 (k)  – 1)                             minimum node :    1023 (2 (k)  – 1) in a 10 level ACBT :                         maximum nodes :    1023 (2 (k)  – 1)                          minumum nodes : 512                

Given two sorted arrays of size m and n .Find the number of common elements in them and also find what are that common elements.

This can be done in 3 ways :(considering worst case)//only for sorted 1. O(m*n) // if m == n, then (n*n) 2. O(nLog(m))// if m>n else O(mLog(n))  Using Binary search 3. O(m + n) // this is optimal worst case time// using concept of merge sort for example : array a[] = { 10,20,30.40,50,60,70,80,90};//only for sorted array b[] = { 10,15,20,25,30}; output : 10 20 30 number of same elements : 3 follow me on : Instagram         Twitter             LinkedIn              my website                facebook          Whatsapp                gmail