You are on page 1of 24

ATRIA INSTITUE OF

TECHNOLOGY
DEPARTMENT OF
COMPUTER SCIENCE AND ENGINEERING
PRESENTATION OF CG PROJECT
DEPTH FIRST SEARCH ALGORITHM
Under the guidance of: Submitted by:
PROF. ADITI ASHOK KATTI SPOORTHI.P RANJANI.R
Dept. of CSE (1AT17CS087) (1AT17CS062)
Atria institute of technology
B.Tech , VI Sem ,CSE
Atria institute of technology
CONTENTS OF PRESENTATION

1. INTRODUCTION
2. PROPOSED PROJECT
3. ADVANTAGES/HIGHLIGHTS
4. REQUIREMENTS ANALYSIS
5. DESIGN
6. DEMO
7. CONCLUSION
8. FUTURE ENHANCEMENTS
INTRODUCTION
ABOUT DPETH FIRST SEARCH ALGORITHM
• Depth First Search (DFS) algorithm traverses a graph in a depthward
motion and uses a stack to remember to get the next vertex to start a
search, when a dead end occurs in any iteration
As in the example given above, DFS algorithm traverses from S to A to D to G
to E to B first, then to F and lastly to C. It employs the following rules.

• Rule 1 − Visit the adjacent unvisited vertex. Mark it as


visited. Display it. Push it in a stack.
• Rule 2 − If no adjacent vertex is found, pop up a vertex
from the stack. (It will pop up all the vertices from the
stack, which do not have adjacent vertices.)
• Rule 3 − Repeat Rule 1 and Rule 2 until the stack is empty.
step traversal description

1.

Initialize the stack.

2. Mark S as visited and put it onto


the stack. Explore any unvisited
adjacent node from S. We have
three nodes and we can pick any
of them. For this example, we
shall take the node in an
alphabetical order.
3. Mark A as visited and put
it onto the stack. Explore
any unvisited adjacent
node from A.
Both S and D are adjacent
to A but we are concerned
for unvisited nodes only.

4. Visit D and mark it as
visited and put onto the
stack. Here, we
have B and C nodes, which
are adjacent to D and both
are unvisited. However, we
shall again choose in an
alphabetical order.

5. We choose B, mark it as
visited and put onto the
stack. Here B does not
have any unvisited
adjacent node. So, we
pop B from the stack.
6. We check the stack top for
return to the previous node
and check if it has any
unvisited nodes. Here, we
find D to be on the top of
the stack.

7. Only unvisited adjacent


node is from D is C now. So
we visit C, mark it as visited
and put it onto the stack.

As C does not have any unvisited adjacent node so we keep popping the
stack until we find a node that has an unvisited adjacent node. In this case,
there's none and we keep popping until the stack is empty.
What is the purpose of depth first search?
• like Breadth First Search, is to visit every node of a graph and collect
some sort of information about how that node was discovered
• DFS can be used on both undirected and directed graphs. What makes
DFS different from BFS is both the method used to discover the
nodes, and the information recorded about that node.
• Instead of radiating outward from the source node (as in BFS), a DFS
explores a single route at a time. Once a "path" has been fully
discovered, DFS backtracks and searches another path. This process is
continued until all possible paths have been exhausted.
Advantages of depth first search
• DFS consumes very less memory space

• It will reach at the goal node in a less time period than BFS if it
traverses in a right path.

• It may find a solution without examining much of search because we


may get the desired solution in the very first go.
PROBLEM STATEMENT
 There are no such projects which explain depth first
search algorithm in a graphical manner
 Here is the attempt to do one and understand the
depth first algorithm
 This topic has been directly implemented in certain
topics like discovering the paths in maze ,bubble
shooter etc.
PROPOSED PROJECT
• The project depth first search shows the nodes
which are being traversed
• The nodes which are on the stage of processing
are shown in grey color
• The nodes that are achieved and no neighbor
nodes are left to traverse are shown as red in
color
ADVANTAGES
• It shows the nodes that are being processed and
nodes that are reached by different colors
• There is no restriction on the number of nodes
present in the graph
• It also show the details of the final node is reached
and print the results
REQUIREMENTS ANALYSIS
• THE SOFTWARE REQUIREMENTS
operating system like Window XP, Window 7 and Window 8 is the
platform required to develop 2D & 3D graphics applications
A Visual C++ complier is required for compiling the source code to
make the executable file which can then be directly executed.
A built-in graphics library like glut,glut32 &header file like glut.h and
DLL i.e. dynamic link libraries like glut ,glut32 are required for creating
the 3D layout
• Hardware requirements
The hardware requirements are very minimal and the solution can be made
to run on most of the machines

Processor : Above x86

Processor speed : 500 MHz and above

RAM:64 MB or above storage space 4GB and more

Monitor Resolution: A color monitor with a minimum resolution of 640*480


DESIGN
#include<bits/stdc++.h>
#include<ctime>
#include<GL/glut.h>
#include <graph-graphics.h>
GL/glut.h: This header files provides an interface with application programs that are installed on the
system.
Bits/stdc++.h: header file that includes every standard library. Using this file is a good idea,when
you want to reduce the time wasted in doing chores; especially when your rank is time sensitive.
ctime: This header file contains definition of functions to get and manipulate date and time
information.
graph-graphics.h: header file provides access to a simple graphics library that makes it possible to
draw lines rectangles, ovals ,arcs, polygon ,images ,and strings on a graphical window .
Description of OpenGL functions
main(): Execution of any program always starts with main function irrespective of where it is
written in a program.

glutInit(&argc, char **argv): glutinit will initialize the GLUT library and negotitate a session
with the window system.During this process,glutInit may cause the termination of the GLUT
program with an error message to the user if GLUT cannot be properly initialized.

glutInitDisplayMode(unsigned int mode) : the initial display mode is used when creating top
level windows, sub windows , and overlays to determine the OpenGL display mode for the
to- becreated window or overlay.

glutCreateWindow(char *title): the glutCreateWindow creates a top-level window.The name


will be provided to the window system as the window’s name .The intent is that the window
system will label the window with the name
glutReshapeFunc(): glutReshapeFunc set the reshape callback for the current window. The
reshape callback is triggered when a window is reshaped .A reshape callback is also
triggered immediately before a window’s first display callback after a window is created or
whenever an overlay for the window is established.The width and height parameters of the
callback specify the new window size in pixel.Before the callback, the current window is set
to the window that has been reshaped

glClearColor(R,G,B,A): glVClearColor specifies the red green blue and alpha values used by
glClear to clear the color buffers. Values specified by glClearColor are clamped to the range 0
to 1.

glutMouseFunc(void (*func)(int button, int state, int x, int y)): glutMouseFunc sets the
mouse callback for the current window. When a user preses and releases mouse buttons in
the window, each press and each release generates a mouse callback.The button parameter
is one of GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON, or GLUT_RIGHT_BUTTON.
Description of User-defined functions
void drawstring(float x, float y, float z , char *string): used to
display text.

void display(void): It’s user-defined DISPLAY function.

void paint(int x, int y): Used for PSINT BRUSH function.


Code snippets
drawstring():
Void drawstring(float x,float y,float z,char *string)
{
/* position the string at x,y,z location*/
/* display it on output screen using standard glut API*/
}

setFont():
Void setFont(void *font)
{
/* sets the current font*/
}
DEMO
CONCLUSION
• The project has been successfully implemented by using
openGL
• The project gives the detail of how the nodes are traversed
and order in which they are traversed
• This project provides the visual representation of graph and
the nodes and operations being performed on them
FUTURE ENHANCEMENTS
• The traversing of the node can be shown through dotted lines
• The stack representation can be done for this

You might also like