Thursday, 23 April 2020

Primitive Operations on Binary Tree


The main primitive operations of a binary search tree are:
  • Add:  adds a new node
  • Get:  retrieves a specified node
  • Remove:  removes a node
  • Traversal:  moves through the structure
Additional primitives can be defined:
  • IsEmpty:  reports whether the tree empty
  • IsFull:  reports whether the tree is full
  • Initialise:  creates/initializes the tree
  • Destroy:  deletes the contents of the tree (may be implemented by reinitializing the tree)
The basic operations on a binary search tree take time proportional to the height of the tree. For a complete binary tree with node n, such operations run in thetaBig(lg n) worst-case time. If the tree is a linear chain of n nodes, however, the same operations takes (n) worst-case time.
The basic operations on a binary search tree take time proportional to the height of the tree. For a complete binary tree with node n, such operations run in thetaBig(lg n) worst-case time. If the tree is a linear chain of n nodes, however, the same operations takes (n) worst-case time.
Height of Tree

1.Searching


Searching a binary tree for a specific value is a recursive process that we can perform due to the ordering it imposes. We begin by examining the root. If the value equals the root, the value exists in the tree. If it is less than the root, then it must be in the left subtree, so we recursively search the left subtree in the same manner. Similarly, if it is greater than the root, then it must be in the right subtree, so we recursively search the right subtree in the same manner. If we reach an external node, then the item is not where it would be if it were present, so it does not lie in the tree at all. A comparison may be made with binary search, which operates in nearly the same way but using random access on an array instead of following links.

The Algorithm pseudo-code is:
TREE_SEARCH(x,k)
1. if x=Null or k=key[x]
2.         then return x
3. if k < key[x]
4.         then return TREE_SEARCH(left[x],k)
5.         else return TREE_SEARCH(right[x],k)
6. exit
 
SEARCH_BINARY_TREE(treenode, value):
1. if treenode is None: return None  # failure
    left, nodevalue, right = treenode.left, treenode.value, treenode.right
2. if nodevalue > value:
               return search_binary_tree(left, value)
    elif value > nodevalue:
               return search_binary_tree(right, value)
    else:
               return nodevalue
3. exit
 
This operation requires O(log n) time in the average case, but needs Ω(n) time in the worst-case, when the unbalanced tree resembles a linked list.

2. Insertion

Insertion begins with a search; we search for the value, but if we do not find it, we search the left or right subtrees as before. Eventually, we will reach an external node, and we add the value at that position. In other words, we examine the root and recursively insert the new node to the left subtree if the new value is less than or equal the root, or the right subtree if the new value is greater than the root.

The insertion algorithm is:
TREE_INSERT(T,x)
1. y <- Null
2. z <- root[T]
3. while z != Null
4.      do y <- z 
5.         if key[x] < key[z]
6.            then z <- left[z]
7.            else z <- right[z]
8. p[x] <- y
9. if y = Null
10.       then root[T] <- x
11.       else if key[x] < key[y]
12.       then left[y] <- x
13.       else right[y] <- x            
14. exit.
 
BINARY_TREE_INSERT(treenode, value):
1. if treenode is None: return (None, value, None)
               left, nodevalue, right = treenode.left, treenode.value, treenode.right
2. if nodevalue > value:
               return TreeNode(binary_tree_insert(left, value), nodevalue, right)
    else:
               return TreeNode(left, nodevalue, binary_tree_insert(right, value))
3. exit.
 
This operation requires O(log n) time in the average case, but needs Ω(n) time in the worst case.

Another way to explain insertion is that in order to insert a new node in the tree, its value is first compared with the value of the root. If its value is less than the root's, it is then compared with the value of the root's left child. If its value is greater, it is compared with the root's right child. This process continues until the new node is compared with a leaf node, and then it is added as this node's right or left child, depending on its value.

3. Deletion

There are several cases to be considered:
  • Deleting a leaf: Deleting a node with no children is easy, as we can simply remove it from the tree.
  • Deleting a node with one child: Delete it and replace it with its child.
  • Deleting a node with two children: Suppose the node to be deleted is called N. We replace the value of N with either its in-order successor (the left-most child of the right subtree) or the in-order predecessor (the right-most child of the left subtree). 
Deletion


Once we find either the in-order successor or predecessor, swap it with N, and then delete it. Since either of these nodes must have less than two children (otherwise it cannot be the in-order successor or predecessor), it can be deleted using the previous two cases.
In a good implementation, it is generally recommended to avoid consistently using one of these nodes, because this can unbalance the tree.
 
BINARY_TREE_DELETE(treenode, value):
1. if treenode is None: return None # Value not found
               left, nodevalue, right = treenode.left, treenode.value, treenode.right
2. if nodevalue == value:
        if   left  is None: 
            return right
        elif right is None: 
            return left
        else:
            maxvalue, newleft = find_remove_max(left)
            return TreeNode(newleft, maxvalue, right)
    elif value < nodevalue:
        return TreeNode(binary_tree_delete(left, value), nodevalue, right)
    else:
        return TreeNode(left, nodevalue, binary_tree_delete(right, value))
3. exit
 
FIND_REMOVE_MAX(treenode):
1. left, nodevalue, right = treenode.left, treenode.value, treenode.right
2. if right is None: return (nodevalue, left)
    else:
        (maxvalue, newright) = find_remove_max(right)
        return (maxvalue, (left, nodevalue, newright))
3. exit.

Although this operation does not always traverse the tree down to a leaf, this is always a possibility; thus in the worst case, it requires time proportional to the height of the tree. It does not require more even when the node has two children, since it still follows a single path and visits no node twice.

Deletion in binary search trees: An example

Deletion in binary search trees: An example



Delete 4 (delete leaf node)


Delete 10 (Node with no left subtree)
Delete 10 (Node with no left subtree)


Delete 13 (node with both right and left subtrees)
Delete 13 (node with both right and left subtrees)


4. Traversal

Once the binary search tree has been created, its elements can be retrieved in order by recursively traversing the left subtree, visiting the root, then recursively traversing the right subtree. The tree may also be traversed in pre order or post order traversals.

TRAVERSE_BINARY_TREE(treenode):
1. if treenode is None: return
2. left, nodevalue, right = treenode
3. traverse_binary_tree(left)
4. visit(nodevalue)
5. traverse_binary_tree(right)
6. exit.

Traversal requires Ω(n) time, since it must visit every node. This algorithm is also O(n), and so asymptotically optimal.

 

5. Sort

A binary search tree can be used to implement a simple but inefficient sort algorithm. Similar to insertion sort, we insert all the values we wish to sort into a new ordered data structure, in this case a binary search tree, then traverse it in order, building our result:
 
BUILD_BINARY_TREE(values):
1. tree = None
2. for v in values:
               tree = binary_tree_insert(tree, v)
3. return tree
 
TRAVERSE_BINARY_TREE(treenode):
1. if treenode is None: return []
    else:
        left, value, right = treenode
2. return (traverse_binary_tree(left) + [value] + traverse_binary_tree(right))

The worst-case time of build_binary_tree is Ω(n2) — if you feed it a sorted list of values, it chains them into a linked list with no left subtrees. For example, build_binary_tree([1, 2, 3, 4, 5]) yields the tree (None, 1, (None, 2, (None, 3, (None, 4, (None, 5, None))))). There are a variety of schemes for overcoming this flaw with simple binary trees; the most common is the self-balancing binary search tree. If this same procedure is done using such a tree, the overall worst-case time is O(nlog n), which is asymptotically optimal for a comparison sort.




Friday, 17 April 2020

Dynamic Implementation of Binary Tree


Implementation of Binary Trees
A node of a binary tree can be represented as:

Binary Tree in Data Structure


What is Binary Tree? 
A binary tree is a tree data structure in which each node has at most two children. Typically the child nodes are called left and right. One common use of binary trees is binary search trees; another is binary heaps.

Tree in Data Structure


What is a tree in Data Structure? 
A tree is often used to represent a hierarchy. This is because the relationships between the items in the hierarchy suggest the branches of a botanical tree.

Monday, 13 April 2020

STATIC AND DYNAMIC DATA IMPLEMENTATIONS


In computer science, a static data structure is a data structure created for an input data set which is not supposed to change within the scope of the problem. When a single element is to be added or deleted, the update of a static data structure incurs significant costs, often comparable with the construction of the data structure from scratch. In real applications, dynamic data structures are used, which allow for efficient updates when data elements are inserted or deleted.There exist methods, called dynamization, to convert static data structures into dynamic ones.

What is ABSTRACT DATA TYPE?

ABSTRACT DATA TYPE

Sunday, 12 April 2020

Data Structure


A data structure is a way of organizing data that considers not only the items stored, but also their relationship to each other. Advance knowledge about the relationship between data items allows designing of efficient algorithms for the manipulation of data.

Thursday, 9 April 2020

Operators


What is the operator? Explain its types.
An operator is a symbol that tells the computer to perform certain mathematical or logical manipulation on data stored in variables. The variables that are operated are termed as operands.
Operators can be classified into a number of categories. They include:

Increment and Decrement Operators


C++ has two very useful operators ++ and -- called increment and decrement operators respectively. These are generally not found in other languages. These operators are called unary operators as they require only one operand. This operand should necessarily be a variable not a constant.

Conditional Operator


A ternary operator is one which contains three operands. The only ternary operator available in C language is conditional operator pair "?:". It is the form of C++ Conditional ? : Operator:
exp1 ? exp2 : exp3 ;

Bitwise Operators


Bitwise operators are used for manipulation of data at bit level. These operators are used for testing the bits, or shifting them right or left. Bitwise operators may not be applied to float or double data type. It is applicable to integer data types data only. Following are some bitwise operators.

C++ Special Operators


Special Operators in C++
C++ language supports some special operators such as comma operator, sizeof operator, pointer operators (& and *), and member selection operators (. and ->). pointer operators will be discussed while introducing pointers and member selection operators will be discussed with structures and union. Right now, we will discuss comma operator and sizeof operator.

Wednesday, 8 April 2020

Microsoft PowerPoint

INTRODUCTION TO MICROSOFT POWERPOINT
MS PowerPoint is powerful presentation software, used to create professional quality presentations. These can be reproduced on the Transparency, Paper, slide, Photo print etc. This allows you to easily publish presentations on the Internet. In Microsoft PowerPoint, as in most other presentation software, text, graphics, movies, and other objects are positioned on individual pages or "slides". The Microsoft PowerPoint helps you to create and organize presentations by assisting in developing presentation outlines and selecting various slide layouts. It   is the component of Microsoft Office that is used to create professional quality presentations. Teachers, professors, politicians, and sales representatives make presentations to sell their concepts. They use graphics, text, movies, sounds, and the Internet to share information on any topic.
Using PowerPoint templates, you can quickly and easily create presentations for many purposes, including lectures, research reports, meeting handouts and agendas templates, you can quickly and easily create presentations for many purposes, including lectures, research reports, meeting handouts and agendas. A MS Power Point presentation is a collection of your slides, handouts, speaker’s notes etc, and all these are kept in a single file called ‘Presentation Files’, with an extension .PPT. As you create slides, you are creating a presentation that you design. You can give your presentation any look and format.

FEATURES OF MICROSOFT POWER POINT
1. Templates - Define what your text will look like and where it will appear, and they offer a complete color scheme to make your presentation more attractive.

2. Wizards - tools that are incorporated into several Microsoft applications to help you accomplish specific tasks. Wizards are PowerPoint’s way of making it easy for you to quickly and efficiently create professional looking presentations.

3. Power Point Central- connects you with the resources like the templates, sounds and the animation clips on the CD-ROM and the sites on the Internet.

4. Slide Finder- allows the previewing and the insertion of slides from the other presentations.

5. Quick Start Tutorial – helps to introduce the features of Power Point.

6. Graphs-improved charting module for the Power Point has the following features:
(a) ADDITIONAL CHART TYPES- MS-POWER POINT gives new chart types such as bubble, pie of pie and the bar of pie . It also offers additional 3-D and 2-D chart types such as cylinder, pyramid and cone.
(b) CHART DATA TABLES-enhances the chart by adding explanatory details by attaching the data table that contains the numbers represented diagrammatically.
 (c) ROTATED TEXTS ON THE CHART AXES-to display all the necessary data proportionately for easier viewing, the fonts can be scaled and the text rotated along the chart axes.
(d) PICTURE, TEXT AND GRADIENT FILLS- to graphically represent data, you can fill the chart elements such as the bars, areas and the surfaces with texture, imported pictures or gradient fills.

7. Multiple Undo Feature-displays an Undo List on the standard tool bar from which you can select the change you want to reverse.

8. Active Web service is used – shared by all Microsoft Office programs- to browse rich webs of the presentations and documents on the local computer, any server, an Intranet or the Web.
Power Point has a set of built in buttons for the actions such as Forward, Back, Home, Help, Information, sound and Movie. By clicking on any of these buttons another program can be started.

9. CD-Audio tracks can be played during the presentation.

10. Auto Content Wizard- guides user to pick from the set of pre-built templates. It also provides ideas and the starter text for the presentations.

11. Summary slide-is used to create a summary slide based on the titles of the slides created.

12. Office Art is a drawing tool shared by Microsoft Office programs and provides:
(a) AutoShapes-includes six new auto shapes.
(b) Bezier Curves-used to draw exact curves with point positions.
(c) Transparent Background- inserts a bit map as a part of design of the slides.

13. Animation Effects and Multimedia capabilities include-
(a) Custom Animation-an easier way to define and preview animated effects.
(b) Voice narration-to add a presenter’s voice to the self-running documentation.
(c) Music tracks- to add background music and the sound effects to the presentations.
(d) Animated templates- animation effects can be added to the slide master and will be automatically added when the slides are created.


Next Topic: Microsoft Power Point Controls




Microsoft Power Point Controls



1. Menu BarUsed to access the Power Point menus and the Office Assistant (Help). Includes buttons to perform the most frequently used file, editing, insert, Design, animation, slideshow.

Tuesday, 7 April 2020

Starting PowerPoint Presentation from scratch


One way to start your presentation is to start from scratch. In this way, you are starting out with a blank presentation. You can then design your own background choices. You would not be using a template design. To start a presentation from scratch follow these steps:

Sunday, 5 April 2020

FLOWCHART AND ITS SYMBOLS


What is a flowchart?
Flow chart is the diagrammatic representation of problem and algorithm to its solution that uses the symbols connected by flow lines.
The different symbols denote different types of instruction. And flow lines represent process and the direction of the flow within the program. It is called flowchart because it charts the flow of program. The flowchart is basically used as an aid in expressing and understanding algorithm. The flowchart is quite useful for the programmer and the systems analyst.

ALGORITHM

What is algorithm?
An algorithm may be defined as the step-by-step procedure or method that can be carried out for solving programming problems. Or an algorithm consists of a set of explicit and clear (only one meaning) finite steps, which when carried out for a given set of initial conditions, produce the corresponding output, and terminate in a fixed amount of time.

CHARACTER SET


A character that appears on your computer screen, whether it's a number, a letter, or a symbol, is the graphical interpretation of a number. For a computer to know what characters to display, it refers to a database that associates a single character with each number. This database is called a character set.

Saturday, 4 April 2020

PSEUDOCODE


Pseudocode is a compact and informal high-level description of a computer programming algorithm that uses the structural conventions of programming languages, but omits detailed subroutines, variable declarations or language-specific syntax. The programming language is augmented with natural language descriptions of the details, where convenient.

DECISION TABLE

Decision tables are a precise yet compact way to model complicated logic. Decision tables, like if-then-else and switch-case statements, associate conditions with actions to perform. But, unlike the control structures found in traditional programming languages, decision tables can associate many independent conditions with several actions in an elegant way.

Expressions in C++


An expression is a combination of variables, constants and operators arranged according to syntax of the language. Some examples of expressions are:
c = (m + n) * (a - b);
temp = (a + b + c) / (d - c);

Control Statements in C++


Control Statements in C++
The control statements enable us to specify the order in which the various instructions in a program are to be executed by the computer. They determine the flow of control in a program.
There are 4 types of control statements in C. They are:

Nesting of if_else Statement in C++


When a series of decisions are involved in the statement, we may have to use more than one if_else statement in nested form. This can be described by the flowchart in the following figure:

If else Statement in C++

The if_else statement is a powerful decision making tool. It allows the computer to evaluate the expression. Depending on whether the value of expression is 'True' or 'False' certain group of statements are executed.

if statement in C++


It is used to execute an instruction or block of instructions only if a condition is fulfilled. Its form is:
if (condition
statement;

where condition is the expression that is being evaluated. If this condition is true, statement is executed. If it is false, statement is ignored (not executed) and the program continues on the next instruction after the conditional structure.

For example, the following code fragment prints out x is 100 only if the value stored in variable x is indeed 100:
if (x == 100)
  cout << "x is 100";

If we want more than a single instruction to be executed in case that condition is true we can specify a block of instructions using curly brackets { }:

if (x == 100)
 {
  cout << "x is ";
  cout << x;
 }

Loops and Iteration in C++


What are the Loops in C++? 
Loops in C++  allow a set of instructions to be performed until a certain condition is reached. Or Loops have as objective to repeat a statement a certain number of times or while a condition is fulfilled. There are three types of loops in C++:
1.         for loop
2.         while loop
3.         do-while loop


Loop in C++


Type Modifiers in C++


Type Modifiers
The Basic Data Types may have modifiers preceding them to indicate special properties of the objects being declared. These modifiers change the meaning of the Basic data types to suit the specific needs.
These modifiers are unsigned, signed, long and short. It is also possible to give these modifiers in combination, e.g., unsigned log int.

Declaration of Variables in C++


How to Declare the Variables in C++? or What is the Declaration of Variables?
C++ allows the declaration of a variable anywhere in the scope. This means that a variable can be declared right at the place of its first use.  This makes the program much easier to write and reduce the errors. 

Dynamic Initialization of Variables in C++


How to Initialization of Variables in C++?
Initialization of variables during the run time is called dynamic initialization of variables. In C++, a variable can be initialized at run time using expressions at the place of declaration. For example, the following are valid initialization statements.

Reference Variables in C++



Reference Variables

A reference variable is a name that acts as an alternative name for a previously defined variable.  A reference variable is created as follows:

                        Data-type & reference-name = variable-name

Symbolic Constants in C++


Symbolic Constants
There are two ways to create symbolic constants in C++:
  1. Using the qualifier constant and
  2. Defining a set of integer constants using enum keyword.

Tokens in C++


Tokens in C++
The smallest individual units in a program are known as tokens. More than one token can appear in a single line separated by white spaces.  White space may be blank, carriage return or tab.  C++ has the following tokens.

Switch Statement in C++: The selective Structure


Switch Statement in C++

The syntax of the switch instruction is a bit peculiar. Its objective is to check several possible constant values for an expression, something similar to what we did at the beginning of this section with the linking of several if and else if sentences. Its form is the following:

while loop in C++


while loop in C++
Its function is simply to repeat statement while expression is true.
Syntax:
while (expression) statement;

do-while loop in C++


do-while loop in C++
Its functionality is exactly the same as the while loop except that condition in the do-while is evaluated after the execution of statement instead of before, granting at least one execution of statement even if condition is never fulfilled.

for loop in C++


for loop in C++
Its main function is to repeat a statement while the condition remains true, like the while loop. But in addition, for providing places to specify an initialization instruction and an increase instruction. So this loop is specially designed to perform a repetitive action with a counter.

goto Statement in C++


It allows making an absolute jump to another point in the program. You should use this feature carefully since its execution ignores any type of nesting limitation.
The destination point is identified by a label, which is then used as an argument for the goto instruction. A label is made of a valid identifier followed by a colon (:).
This instruction does not have a concrete utility in structured or object oriented programming aside from those that low-level programming fans may find for it. For example, here is our countdown loop using goto: