Currently browsing tag

Algorithm

BFSGraph

Breadth First Search in C++

Breadth First Search in C++ – Algorithm and Source Code Basic Theory Breadth – first searches are performed by exploring all nodes at a given depth before proceeding to the next level. This means that all immediate children of nodes are explored before any of the children’s children are considered. …

Depth First Search in C++ – Algorithm and Source Code

Basic Theory Depth – first searches are performed by diving downward into a tree as quickly as possible. It does this by always generating a child node from the most recently expanded node, then generating that child’s children, and so on until a goal is found or some cutoff depth …

3D Rotation Algorithm about arbitrary axis with CC code

3D Rotation Algorithm about arbitrary axis with C/C++ code When an object is to be rotated about an axis that is not parallel to one of the coordinate axes, we need to perform some additional transformations. In this case, we also need rotations to align the axis with a selected …

CohenSutherland Line Clipping Algorithm with CC

Cohen-Sutherland Line Clipping Algorithm with C/C++ Theory In this method, every line endpoint is assigned a four digit binary code(region code) that identifies the location of the point relative to the boundary. b1 : left  b2 : right  b3 : below  b4 : above The value 1 indicates its relative …

LiangBarsky Line Clipping Algorithm with CC

Liang-Barsky Line Clipping Algorithm with C/C++ TheoryIn Liang-Barsky algorithm, we first write the point-clipping conditions in parametric form as  Each of these for inequalities can be expressed as , k = 1, 2, 3, …..where parameter p and q are defined as Any line that is parallel to one of …

Implementation of Dijkstras Shortest Path Algorithm in C

Implementation of Dijkstra’s Shortest Path Algorithm in C++ Dijkstra’s Shortest Path Algorithm is popular algorithm for finding shortest path between different nodes. The algorithm (Pseudo Code) is as follows procedure Dijkstra (G): weighted connected simple graph, with all weights positive)[G has vertices a = v0, v1, ….. , vn = …

Drawing an Ellipse with Mid Point Ellipse Algorithm in CC

Drawing an Ellipse with Mid Point Ellipse Algorithm in C/C++ The theory for drawing Ellipse with Mid Point Algorithm is same as that of Circle drawing. But the difference is that the Ellipse is divided into two regions because it has two radii. The regions are separated from each other …

Drawing a Circle with Mid Point Circle Algorithm in CC

Drawing a Circle with Mid – Point Circle Algorithm in C/C++ As in the previous line drawing algorithm, we sample at unit intervals and determine the closest pixel position to the specified circle path at each step. For a given radius r and screen center position (xc, yc), we can …

Implementing Bresenhams Line Drawing Algorithm in CC

Implementing Bresenham’s Line Drawing Algorithm in C/C++ Bresenham’s Line Drawing Algorithm is an accurate and efficient raster line-generating algorithm developed by Bresenham. In this algorithm, we first consider the scan – conversion process for lines with positive slope less than 1. Pixel positions along a line path are then determined …

Drawing Straight Line using DDA Algorithm in CC

Drawing Straight Line using DDA Algorithm in C/C++ The digital differentia analyzer (DDA) is a scan-conversion line algorithm. In this algorithm, we sample the line at unit intervals in one coordinate and determine corresponding integer values nearest the line path of the other coordinate and plot those coordinate (pixel) in …

Binary tree Implementation on C Algorithm and Source Code

Binary tree Implementation on C++ – Algorithm and Source Code Algorithm for inserting a node in a binary tree: 1. Declare and initialize necessary variables2. Read the data item to be inserted in the tree say x.3. Create a new node with its left and right pointers to null.4. Assign …