About the nature of bfs and dijkstra

can these two graphs work on both directed and undirected graphs?

A graph being directed just means that the edges connecting vertices are able to connect one way, but not the other. This means that one vertex can be adjacent to another, but that other vertex may not be adjacent to the first vertex.

In the context of Dijkstra’s algorithm and BFS, whether the graph is directed or undirected does not matter.

Yea but then why does bellman ford algo works only on directed weighted graph?

you can also apply bellman-ford algo on un-directed graph but with some conditions

the Bellman-Ford algorithm ONLY works on graphs that don’t contain any cycles with negative weights this actually means your un-directed graph mustn’t contain any edges with negative weight.

Yes now I understood. Is it necessary that a graph has to be cyclic to contain a negative cycle? How to check whether a graph is cyclic or not?

there are different ways to check graph is cyclic or not
you can use DFS
there are videos in your course