Graphs & Trees
Graphs and trees are also important data structures.
In programming, what are graphs?
In a graph, there are two elements: vertex points that are connected by "edges."
It depends on how they are used whether these edges are directed or undirected.
Graphs are useful in many situations.
GPS applications, for example, could represent roads as edges and intersections as vertices.
Using graphs is usually obvious when it comes to technical interviews.
Whether you choose one outright or the data set in question consists of vertices and edges is up to you and your interviewer.
Programming trees: what are they?
Data structures such as trees and graphs are similar. They are also widely used on a day-to-day basis by software engineers.
Technical interviews typically include questions about search and traversal.
A tree consists of a set of nodes where each node includes references to at least one child tree.
Recursive trees are defined in the same way as recursive functions.
In the face of such data structures, recursive algorithms seem logical.
Trees are similar to linked lists in that nodes are comparable.
A linked list, on the other hand, contains only one memory pointer to another node.
There is no limit to how many memory pointers a node may contain.
Technically, trees are a kind of graph. A directed acyclic graph is sometimes called a tree.
Graphs and trees are used alongside basic algorithms such as breadth-first search and depth-first search.
During your software engineering interview, remember the following things about trees:
- A leaf node is a node that has no children.
- Nodes in the tree are ordered from top to bottom. Interviewers usually provide you with when you have a coding problem.
- Heights are the distances between root nodes and leaf nodes.
- Subtree: A node under the root node that includes its children.