Advert

Kruskal’s Algorithm

Last edited by . Total of no comments in the discussion.

An algorithm which is used to create a minimum spanning tree is attributed to Kruskal’s algorithm. The nodes of the graph are initially considered as n distinct partial trees with one node each. At each step of the algorithm, two distinct partial trees are connected into a single partial tree by an edge of the graph. When only one partial tree exists (after n-1 such steps), it is a minimum spanning tree. The concern is what connecting arc to use at each step. The answer is to use the arc Read More

Share on:

Insertion Sort

Last edited by . Total of no comments in the discussion.

This algorithm is very popular with bridge players when they sort their cards. In this procedure, we pick up a particular value and then insert it at the appropriate place in the sorted sub list. This algorithm requires n-1 passes. Pass1: a[1] is inserted either before or after a[0] so that a[0] and a[1] are sorted. Pass2: a[2] is inserted either before a[0] or between a[0] and a[1] or after a[1] so that the elements a[0], a[1], a[2] are sorted. Pass3: a[3] is inserted either before a[0] or between a[0] Read More

Share on:

Copy Constructor

Last edited by . Total of no comments in the discussion.

A copy constructor is a class constructor that can be used to initialize one object with the values of another object of the same class during the declaration statement. In simple words, we can say that, if we have an object called myObject1 and we want to create a new object called myObject2, initialized with the contents of myObject1 then the copy constructor should be used. Consider the declaration given below: myClass myObject1; … (1) myClass myObject2(myObject1); … (2) The declaration (1) declares an object myObject1 of class myClass. The Read More

Share on:

Shell Sort

Last edited by . Total of 2 comments in the discussion.

Invented by Donald Shell in 1959, Shell sort is the most efficient of the O(n2) class of sorting algorithms. It is also the most complex of the O(n2) algorithms. This algorithm is similar to bubble sort in the sense that it also moves elements by exchanges. Shell sort begins by comparing elements that are at distance d. With this, the elements that are quite away from their place will move more rapidly than the simple bubble sort. In each pass, the value of d is reduced to half. In each Read More

Share on:

Function Template Overloading

Last edited by . Total of no comments in the discussion.

A template function may be overloaded either by template functions or ordinary functions. In such cases, the overloading resolution is accomplished using following steps: Call an ordinary function that has an exact match. If a match for an ordinary function is not found, call a template function that could be created with an exact match. An error is generated if no match is found. Note that no automatic conversions are applied to arguments on the template functions. The program shows how a template function is overloaded with an explicit function. Read More

Share on:

Prim Algorithm

Last edited by . Total of no comments in the discussion.

Given a connected weighted graph G, it is often desired to create a spanning tree T for G such that the sum of the weights of the tree edges in T is as small as possible. Such a tree is called as minimum spanning tree and represents the most inexpensive way of connecting all the nodes in G. There are a number of techniques for creating a minimum spanning tree for a weighted graph. The first of these, Prim’s algorithm, discovered independently by Prim and Dijkstra, is very much like Read More

Share on:

Bucket/Radix Sort

Last edited by . Total of no comments in the discussion.

Most people use the bucket sort method when sorting a list of names in alphabetical order. The procedure is: First, the names are grouped according to the first letter, thus the names are arranged in 26 classes, one for each letter of the alphabet. The first class consists of those names that begin with letter A, the second class consists of those names that begin with letter B, and so on. Next, the names are grouped according to the second letter. After this step, the list of names will be Read More

Share on:

Function Templates

Last edited by . Total of no comments in the discussion.

Like class templates, we can also define function templates that could be used to create a family of functions with different argument types. The general format of a function template is as follows: template <class T> return-type function-name( argument of type T ) { // body of function with Type T } The function template syntax is similar to that of the class template except that we are defining functions instead of classes. We must use the template parameter T as and when necessary in the function body and in Read More

Share on:

Error Lnk2019

Last edited by . Total of 1 comment in the discussion.

The C++ programming language has become one of the most popular general purpose programming languages taught in schools and used in industry. Its ability to allow programmers to create object oriented programs and tie in to low level constructs, has made it one of the most powerful languages available to developers over the past several decades. An error that can be encountered while building C++ projects is the “Error Lnk2019,” which is displayed when an unresolved external symbol is referenced in a function. In order to resolve the error, a Read More

Share on:

Deleting an Element from a Linear Linked List

Last edited by . Total of no comments in the discussion.

To delete an element from the list, first the pointers are set properly and then the memory occupied by the node to be deleted is deallocated (freed). This tutorial covers the deletion of a node from the following three positions: At the beginning of the list At the end of the list After a given element Deleting from the Beginning of the List An element from the beginning of the list can be deleted by performing the following steps: Assign the value of head (address of the first element of Read More

Share on: