Binary Tree Important Definition and Properties.

 Binary Tree


Tree: Non-Linear Data Structure in which data is organized in a hierarchical manner.  It is very fast for information retrieval and searching operations. 


Important Terminology of a Binary Tree.


Node: Each element in a tree is called a node.

Edges: Lines connecting two nodes, it is also known as branches. 

Parent Node: The immediate predecessor of a node (node that comes just before a node).

Child Node: The immediate successors of a node (node that comes just next in line).

Root Node: The node that doesn't have any parent node.

Leaf Node: The node that doesn't have any child node. The node other than the leaf node is known as a non-leaf or terminal node. 

Level: Distance of that node from the root.

Height: Total number of level, depth of the tree, Level+1=Height

Siblings: All nodes having the same parent. All siblings are at the same level but it is not necessary that nodes at the same level are siblings.

Path: It is a way to reach a node from any other node. In a tree, there is only one path possible between any two nodes. Path length = Number of Edges on the path.

Degree: The number of children or subtrees connected to a node.

Forest: The subtrees we get after removing the root of the main tree is collectively called as Forest (also known as a set of disjoint trees).  

Strictly Binary Tree: Each node in the tree is either a leaf node or has exactly two children. There is no node with one child. 

Extended Binary tree: Each Empty subtree is replaced by a special node then the resulting tree is extended binary tree or 2-tree.

Full Binary tree: All the levels have the maximum number of nodes.

**If the number of any node is k, then the number of the left child is 2k, the number of right children is 2k+1, and the number of its parent is k/2.

Complete Binary Tree: All the levels have the maximum number of nodes except possibly the last node.


Important Properties of a Binary Tree.

P1. The maximum number of nodes possible on any level i is 2^i where i>=0.

P2. The maximum number of nodes possible in a binary tree of height h is 2^h-1.

P3. The minimum number of nodes possible in a binary tree of height h is equal to h. A tree with a minimum number of nodes is called skew trees.

P4. If a binary tree contains n nodes, then its maximum height possible is n and the minimum height possible is log2(n+1).

P5. In a non-empty binary tree, if n is the total number of nodes and e is the total number of edges, then e = n-1.


P6. In a non-empty binary tree, if n is the number of nodes with no child and m is the number of nodes with 2 children, then n = m+1.

Traversal in Binary Tree
1. Breadth-First Traversal (Level Order Traversal)
2. Depth First Traversal
APreorder Traversal (Root, Left, Right)
BInorder Traversal (Left, Root, Right)
CPostorder Traversal (Left, Right, Root)

Edit your videos for free using VLC media player.

Edit using VLC Media Player

 

VLC is usually thought of as a media player and a very good one at that. However, there’s more to the software than meets the eye. Did you know you can use it to make simple edits to your videos as well as just watch them? This saves you needing to download a separate video-editing tool if you’re short on space or don’t use one often enough to justify the installation.

 

Trim a video clip using a VLC media player.

 

#Step 1:

First, we’ll look at how to trim video, so you can remove unwanted sections to create a clip. To do this, you need some extra tools. Open the View menu and choose Advanced Controls. This adds a Record button and a useful ‘Frame by frame’ button.

 

Video Trim using VLC

#Step 2:

Load the video and watch it through to make sure you’re familiar with where you want to start and endpoints to be. Use the slider to get the video near and immediately press the Record button when you get to the correct place.

 

trim video step 2

#Step 3:

You have to mark the end of your clip manually. When the video gets to the stop point, click the Record button again. The trimmed video file is saved to your Videos folder with ‘vlc_record’ at the front of its name. Do this as many times as required to collect the clips that you need.

 

Stick video clips together using a VLC media player.

While VLC is perfectly capable of sticking video clips together, the option was removed from the latest version of the graphical interface. However, the action can still be performed from the Command Prompt. Start by renaming the files you want to stitch together-use a simple, consecutive system, such as numbering them.

 

#Step 1:

Close any instances of VLC that you have open. Enter cmd in the search box to launch the Command Prompt, and navigate to the folder that contains your renamed video files. In our case, we used cd c:\Users\Praveen Kumar\Videos.

 

#Step 2:

Next, type a command with the path to the vlc.exe file, the names of all the files you want to join, and a couple of additional commands including the name of the final file. Our was “C:\Program Files\VideoLAN\VLC\vlc.exe” 1.mp4 2.mp4 --sout “#gather:std{access=file,dst=join.mp4}” --sout-keep

 

#Step 3:

VLC opens and joins the files together. The process is carried out discreetly, so you won’t see anything appear on the screen. You now have to shut VLC down again before the new file (in our case, called ‘join’) is properly finished. If you look at it before closing VLC, it will appear to be an empty file.

 

#Step 4:

The file’s thumbnail appears. You can reopen VLC and play the video as normal. If you want to watch any changes to the file, such as adding more clips, make sure you rename the output file in Step 2, so it doesn’t overwrite your existing file.

 

#Step 5:

You may feel your video is a bit boring and decide to spice it up with a few video effects. If you do this as you record your clips above, you can insert them into your finished product. Click the ‘Show extended settings’ button and click the Video Effects tab.

 

#Step 6:

There are plenty of effects to experiment with, such as changing the color of your video from the Colors tab. Here, we’ve chosen a Sepia tint. The Essential tab has subtler color changes, Geometry lets you rotate the video and Overlay can insert a logo or text.  

Time Analysis of Recursive Program | Back Substitution Method

Back Substitution method

 

Let’s understand the time complexity of a recursive function with some examples:

 

Example:
 int test(int n)  
 {  
   if(n > 20)  
    return test(n/2) + test(n/2); //recursive call  
 }  


For solving the test(int n), let's say that time taken is T(n). In the above function, “if-condition” will take some constant time then we gonna calculate two tests (n/2) and summing it up. So, there are some constant terms involving “if-condition” and for the addition operation in the recursive call.

 

T(n) = c + 2T(n/2)

This is how we should write a recursive function and then we should try solving the recursive function.


Back Substitution method. 

There are many ways to solve the recursive function, one of the ways are: Back Substitution method.


 //Example 1:  
 int test(int n)  
 {  
   if(n > 1)   //base condition  
    return test(n-1);  //recursive call  
 }  
 //Time Complexity = O(n)   

 

If we assume that the time taken for the test(int n) is T(n) then, the time is actually some constant term for comparison, and after that time is taken to solve the problem on (n-1) inputs.

 

T(n) = 1 + T(n-1) ; when n>1 --------> (1)

        = 1                ; when n=1

We represent the constant term using 1 or c.

 

Back substitution can be applied to any of the problems but it is slow.

T(n-1) = 1+T(n-2) -------->(2)

T(n-2) = 1+T(n-3) -------->(3)

 

Substituting eq(2) in (1);

T(n) = 1+1+T(n-2)

T(n) = 2+T(n-2) -------->(4)

 

Substituting eq(3) in (4)

T(n) = 2+1+T(n-3)

T(n) = 3+T(n-3)

   -

   -

   -

   -

T(n) = k+T(n-k) -------->(5)

Checking the base case of the given algorithm, we find that,

T(n) = 1+T(n-1) ;valid when n>1

n is going to start from a very large number and gonna gradually decrease and at some point, n will be 1, so whenever it reaches 1, we’ll stop.

T(n) = k+T(n-k), This will get eliminated when there will be T(1) then.

n-k = 1

K = n-1

 

Putting the value of k in eq (5),

=(n-1)+T(n-(n-1))

=(n-1)+T(1)

=(n-1)+1           because T(1)=1

=n

 

Therefore, T(n) = n = O(n)


Example 2: Try it yourself.

T(n) = n+T(n-1) ; when n>1

        = 1              ; when n=1

Answer: Time complexity will be O(n^2).

Time complexity of Iterative programs.



About graph: f(n) is the actual time taken by the Algorithm, but in practice, we say it the time taken by the program to exist but when you write it into a program and execute it, we found out that this is not the real-time, it is just an approximation. It means, if f(n) increases for the algorithm, then the program time increases if f(n) decreases program time decrease. 


To find out f(n), we need to know that there are 2 types of algorithm:

Iterative: Here there is no function calling and having for loops and all, then it is iterative.


Recursive: Here there is a function calling itself then it is called recursion.


Any program that can be written using iteration could be written using recursion and any recursion program can be converted into an iteration. So both are equivalent in power. But if we go through analysis, both are different:


In order to analyze an iterative program, we need to count the number of times a loop is getting executed. Whereas, if we have to find out the time taken by the recursive program, we use recursive equations which means, we write a function of in terms of n/2

A(n)->f(n).

A(n)->f(n/2) 


In case the algorithm does not contain Iteration or Recursion means there’s no depending on running time on the I/P size, means whatever is the input size, the running time is going to be a constant value.


So if there’s no Iteration or Recursion in the algorithm, we need not worry about the time, it will be constant for such program we write the order of 1 O(1) which represents constant time.   


Examples:  

 //Example 1:  
 int timecomp(int n)  
 {  
   int i;  
   for(i=0; i<n; i++)  
     printf("RavelingTech"); //this line will be printed n times  
 }  
 //Therefore, the time complexity of the algorithm is O(n).  
 
//Example 2:  
 int timecomp(int n)  
 {  
   int i,j;  
   for(i=0; i<n; i++)  
   {  
     for(j=0; j<n; j++)  
       printf("RavelingTech"); //this line will printed nxn times  
   }  
 }  
 //Therefore, the time complexity of the algorithm is O(n^2).  
 
//Example 3:   
 int timecomp(int n)  
 {  
   int i=1, s=1;  
   while(s <= n)  
   {  
     i++;   //increment in i is linear  
     s=s+i;  //increment in s depends on i  
     printf("RavelingTech");  
   }  
 }  
 /*  
 s | 1 3 6 10 15 21 ........n  
 i | 1 2 3 4 5 6 ........k  
 By the time i reaches to k, s will be the sum of 1st k natural number  
   = k(k+1)/2  
 Now, if the loop has to stop , then  
 k(k+1)/2 > n  
 k = O(√n) <--- Time Complexity.  
 */  

How To Apply Dark Mode to all websites in Edge Browser.

DarkMode

The new Chromium Edge browser is packed with useful new features and some of the edge’s features are tucked away below the bonnet which you can enable through Edge flags settings.

One of the interesting features that you can enable from Edge flags settings in dark mode for web content.

I have already explained how to activate Edge’s dark mode, but this just changes the color of the browser’s interface and doesn’t have any effect on the web pages you visit.

To read the web content in dark mode, type edge://flags in the address bar and search for "dark" in the Search Flags box.

Dark Mode Edge Browser

Click on the drop-down next to ‘Force Dark Mode for Web Contents’, then change this to Enable and Restart your browser when prompted.

Edge Browser Dark Mode

Now your Edge browser is ready to load all web content in dark mode and later if you want you can go through the same settings to disable it. 20 Best Features of Chromium Edge Browser. 

Discard Inactive tabs automatically in Google Chrome.

Auto Tab Discard

Auto Tab Discard solves everyone’s biggest moan about Chrome - by automatically ‘killing’ unused tabs, it claws back much-needed memory. This should speed up your browser and save battery life when you’re using a laptop.

Features of Auto Tab Discard.
  • It speeds up the browser and minimizes memory usage.
  • It designates specific tabs to be whitelisted to prevent discarding.
  • You can retain discarded tabs after closing and re-opening your browser.
  • The favicon of a website displays the discarded state.


Click the extension’s toolbar button for a range of quick settings that let you swiftly discard the current tab or any other tab you may have open, in any Chrome window.

Your tabs won’t suddenly disappear- instead, the browser tool puts a discarded tab into a suspended state until you click back into it, at which point it will reload. You can also jump between current tabs, close them using the navigation arrows or order all tabs to remain open during your session.

             
However, it’s in the add-on’s settings where the ‘auto’ part of its name occurs. Here, you can set a time limit that kicks in when you have a specific number of tabs open. 

What is Computer Programming? Basic.

Programming

Dictionary Definition: Programming is the process of preparing an instructional program for a device.

But that’s a really confusing definition, so in layman’s terms what exactly does that mean? Essentially, it is attempting to get a computer to complete a specific task without mistakes.

Just, for example, you instruct your less than intelligent friend to build a Lego set. He lost the instructions so now he can only build based on your commands. Your friend is far from competent on his own and so you must have to give him EXACT instructions on how to build, even if there is one piece wrong the entire Lego set will be ruined.

Giving instructions to your friend is very similar to how programmers code.

An important thing to note is that computers are actually very dumb. We build them up to be this super-sophisticated piece of technology when in actuality a computer’s main functionality comes from how we manipulate it to serve our needs.

{"Computers are only smart because we program them to be"};

The language that Computer Understand.

Programming isn’t a simple as giving instructions to your friend since, in the case of programming, the computer doesn’t speak the same language as you. The computer only understands machine code, which is a numerical language known as a binary that is designed so that the computer can quickly read it and carry out its instructions.

Every instruction fed to the computer is converted into a string of 1’s and 0’s and then interpreted by the computer to carry out a task. Therefore, in order to talk to the computer, you must first translate your English instruction to Binary.

Directly translating what you want the computer to do into machine code is extremely difficult, in fact almost impossible and would take a very long time to do if you could. This is where programming languages come into play.

Programming languages are fundamentally a middle man for translating a program into machine code-the series of 0’s and 1’s that the computer can understand. These languages are much easier for humans to learn than machine code, and are thus very useful for programmers.

{"A programming language is not English and not machine code, it is somewhere in the middle"};

How Programming Language Vary?

There are many different programming languages out there that each has its own unique uses.
Programming

  • Java and Python: General Purpose languages.
  • HTML/CSS: Designed for specific tasks like web page design.


Each language also varies in how powerful it is:
  • JavaScript is a scripting language and isn’t used for big problems.
  • Java and Python can carry out a much more computationally taxing process.


We measure a programming language’s power level by how similar it is to machine code. Low-level programming languages such as Assembly or C are closer to binary than a high-level programming language such as Java or Python.

The basic idea is that the lower the level of your programming language, the more your code will resemble what the machine can interpret as instructions.

So, try different languages and decide which one’s rules, interface, and level of specification you like the best.  

If you like this post and find it useful then you can show your support by donating a small amount from your heart. You can also show your support by following us on Facebook and Twitter.

Introduction to Asymptotic Notations.

Before implementing any algorithm as a program, we need to analyze which algorithm is good in terms of time and space.

Time: Which one can execute faster.
Memory: Which one can take less memory.  

Here we are mainly going to focus on calculating the Time Complexity which generally depends on the size of the input. Let's understand this point with the help of an example.


Suppose we have an integer array and we want to add an element at the beginning of the list then to perform this operation we need one extra space at the end of the array and we have to shift all the elements of the array by one unit and the number of the shift we have made is equal to the number of elements present in the given array. 


So from this small example, we can understand that Running Time mostly depends on the size of the input. Therefore, if the size of the input is n, then f(n) is a function of n that denotes the Time Complexity. Example: 

Time Complexity calculation

From the above example, we conclude that most of the time is consumed by 12 but wait we cannot conclude just by checking for a single n value, we need to calculate a bigger value of n. Below is the calculation for bigger n values. 
n 5n^2 6n 12
1 21.74% 26.09% 52.17%
10 87.41% 10.49% 2.09%
100 98.79% 1.19% 0.02%
1000 99.88% 0.12% 0.002%

Now if we observe the above table we found that for a bigger n value 5n^2 it takes most of the time so while calculating the Time Complexity we can neglect the remaining terms because the single term gives us the approximate result and it is very near to the actual result. This approximate measure of time complexity is called Asymptotic Complexity.


What are Asymptotic Notations?

Asymptotic notations are mathematical tools to measure the space and time complexity of an algorithm. There are mainly three asymptotic notations used to show the time complexity of the algorithm.

O(n) Big O notation. (Worst Case)

Big O notation is the most used notation to measure the performance of any algorithm by defining its order of growth.

Big O notation

Assuming that the time and input are going to increase like in the above graph then what is the worst-case or upper bound for this function?
We have to find out another function in such a way that the function is greater than the given f(n), let's call it c.g(n), after some limit n=no


For any given algorithm, we should be able to find out what is its time complexity or what its f(n) in terms of input n. Now after finding out that, if we can bound that function by some another function say c.g(n) in such a way that after some input no, the value of c.g(n) is always greater than f(n).

[ f(n)<=c.g(n) ], after some n where is n>=no
c, n are real numbers, c > 0 and n >=no 

Definition: f(n)  O(g(n)) if there exists constants c > 0 and no > =1 such that 0 <= f(n) <= c.g(n) for all n >= no

Example: Is f(n) is big O of g(n) [f(n) = O(g(n))] where f(n) = 3n+2 and g(n) = n. 

Solution: At first we have to find two constants c and no such that, 
f(n)<=c.g(n), c > 0 and n >=no
3n+2 < cn. 
let's take c=4
3n+2 < 4n
=> n>=2
Therefore, f(n) = O(g(n)). 
Therefore, g(n) = n bounds the function f(n) which means f(n) is upper bounded by g(n).

So if n is bounding this f(n) then definitely n^2 will bound. It means if g(n) = n is satisfying then any value greater than n (n^2, n^3,----n^n) will also bound 3n+2, but we need to keep in mind that big O is always the upper bound, so all the answers are correct but we will always go for least bound or tightest bound and n is the tightest bound for given f(n). 

Ω(n) Omega notation. (Best Case)

Omega notation gives us a lower bound of the complexity in the best case analysis. In this notation, we analyze the minimum number of steps that need to be executed. For example, In Linear search, the best case is when your search element is present in the first place.
Omega

We have to find out another function in such a way that the function is smaller than the given f(n), let's call it c.g(n), after some limit n=no
Now after finding out that, if we can bound that function by some another function say c.g(n) in such a way that after some input no, the value of c.g(n) is always smaller than f(n).

[ f(n)>=c.g(n) ], after some n where is n>=no
c, n are real numbers, c > 0 and n >=no 

Definition: f (n) ∈ Ω(g(n)) if there exists constants c > 0 and n0 >= 1 such that 0 ≤ c ·g(n) ≤ f (n) for all n ≥ n0

Example: Is f(n) is big Omega of g(n) where f(n) = 3n+2 and g(n) = n.

Solution: 
3n+2 >= cn. is true even for c = 1 
Therefore, the condition is satisfied and 3n+2 is lower bounded by n. 
The given function f(n) can be lower bounded by any value lower than n but it's better to take the closest bound. 

Θ(n) Theta notation. (Average Case)

Theta notation gives us a tight bound of the complexity in the average case analysis. In this notation, we calculate the average by considering different inputs, including the best and worst cases.
Theta

Here we have to find out both the upper bound and lower bound, by a function by a function by varying c.
If f(n) is bounded by c1g(n) and c2g(n) then, f(n) is Î˜g(n).

Definition: f (n) ∈ Θ(g(n)) if there exists constants c1 > 0, c2 > 0 and n0 > 1 such that c1 ·g(n) ≤ f (n) ≤ c2 ·g(n) for all n ≥ n0

Example: Is f(n) is big Theta of g(n) where f(n) = 3n+2 and g(n) = n.

Solution: 
f(n)  ≤  c2 ·g(n)
3n+2 ≤ 4n, true for n0 ≥ 1.

f(n) ≥ c1 ·g(n)
3n+2 ≥ n, true for n0 ≥ 1 and c = 1

This means, that f(n) = 3n+2 is bounded by g(n) from both upper as well as lower bound, for upper bound  c2 = 4, and for lower bound c1 = 1, both the cases are valid for n0 ≥ 1.

Note: Sometimes, Î˜ is also called asymptotically equal which means if the leading term in the function is going to be 1, then we can take n as g(n) because they are asymptotically equal. 
Ex: f(n) = 3n^2+n+1 = Î˜(n^2). 
f(n) = 5n^3+n+1 = Î˜(n^3). 

👉Support Us by Sharing our post with others if you really found this useful and also share your valuable feedback in the comment section below so we can work on them and provide you best ðŸ˜Š.(alert-success) 

DON'T MISS

Nature, Health, Fitness
© all rights reserved
made with by templateszoo