Question: Homework 5 Problem 1 : Consider a graph with 1 1 nodes named 0 , 1 , 2 . . . , 1 0 represented
Homework
Problem : Consider a graph with nodes named represented as adjacency lists as follows:
adjacency list :
adjacency list :
adjacency list :
adjacency list :
adjacency list :
adjacency list :
adjacency list :
adjacency list :
adjacency list :
adjacency list :
adjacency list :
Attached is the java code all classes needed application with two empty static methods in the application to be completed, namely depthfirst traversal and breadthfirst traversal. Submit the entire java file, and explain the results by drawing the respected depthfirst and breadthfirst search trees.
this is code: Here is all the code needed to build dfs and bfs methods fillin the code of the two static methods in the application. Note all the help in the main method. class Node private int data; private Node next; public Node this null; public Nodeint d thisd null; public Nodeint d Node n data d; next n; public void setDataint newData data newData; public void setNextNode newNext next newNext; public int getData return data; public Node getNext return next; public void displayNode System.out.printdata; class LinkListADT private Node first; public LinkListADT first null; public boolean empty return first null; public int size int count ; Node current first; while current null count; current current.getNext; return count; public void insertFirstint newData Node newFirst new NodenewData; newFirst.setNextfirst; first newFirst; public Node deleteFirst if empty System.out.printlnList is empty, nothing to delete."; return null; Node temp first; first first.getNext; return temp; public Node getFirst return first; public boolean searchint key Node current first; while current null if currentgetData key return true; current current.getNext; return false; public void traverse Node current first; while current null current.displayNode; System.out.print; current current.getNext; class LLQueueADT private int size; private Node front; private Node rear; public LLQueueADT size ; front null; rear null; public boolean empty return size ; public void enqueue int number Node newNode new Node ; newNode.setDatanumber; newNode.setNextnull; if thisempty front newNode; else rear.setNextnewNode; rear newNode; size; public int dequeue int i; i front.getData; front front.getNext; size; if thisempty rear null; return i; public int front return front.getData; public int size return size; class Graph private LinkListADT adjacencyList; public Graphint vertices adjacencyList new LinkListADTvertices; for int i ; i vertices; i adjacencyListi new LinkListADT; public void addEdgeint source, int destination adjacencyListsourceinsertFirstdestination; adjacencyListdestinationinsertFirstsource; public LinkListADT getAdjacencyList return adjacencyList; public void printGraph for int i ; i adjacencyList.length; i System.out.printadjacency list i : ; adjacencyListitraverse; System.out.println; public class GraphExample public static void mainString args Graph graph new Graph; graph.addEdge; graph.addEdge; graph.addEdge; graph.addEdge; graph.addEdge; graph.addEdge; graph.addEdge; graph.addEdge; graph.addEdge; graph.addEdge; graph.addEdge; graph.addEdge; graph.addEdge; graph.printGraph; System.out.println
DepthFirst Search starting from vertex :; boolean visited new booleangraphgetAdjacencyListlength; Array to track visited vertices for int i ; i visited.length ; i visitedi false; Initialize all vertices as unvisited dfsgraph visited; System.out.println
BreadthFirst Search starting from vertex :; bfsgraph; Recursive DepthFirst Search public static void dfsGraph graph, int vertex, boolean visitedadd the code BreadthFirst Search Iterative, uses a queue public static void bfsGraph graph, int startVertexadd the code
Problem : Assume that keys arrive for insertion in an initially empty tree in the following order: Build the resulting tree showing each step of the insertion process. Clearly show all splits. Repeat the same with a RedBlack tree clearly show all rotations. please draw it out on a paper so it is easy to follow
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
