Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
In the game of Nim, an arbitrary number of chips are divided into an arbitrary number of piles. Each player can remove as many chips as desired from any single pile. The last player to remove a chip wins. Consider a limited version of this game, in which three piles contain 3, 5, and 8 chips, respectively. You can represent this game as a directed graph. Each vertex in this graph is a possible configuration of the piles (chips in each pile). The initial configuration, for example, is (3, 5, 8). Each edge in the graph represents a legal move in the game.
- Write Java statements that will construct this directed graph.
- Discuss how a computer program might use this graph to play Nim.
java program
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 3 steps with 5 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- In this task you will work with an undirected Graph G = {V, E}, where V = {f,p,s,b,l,j,t,c,d} and E = {(1,2), (1,3), (3,8), (4,8), (8,9), (1,7), (2,6), (2,3), (5,6), (6,7), (7,9), (8,1)}. Assume that the nodes are stored in an indexed linear structure (e.g., an array or a vector) numbered consecutively from 1 (node f) to 9 (node d). 1. Type up a tgf representation of the graph 2. Find a path from node l to node b with length 8, that passes through every vertex of the graph. List the nodes of that path. 3. The graph G contains cycles. What is the smallest number of vertices to remove in order to break all cycles?arrow_forwardThe clique problem is finding cliques in a diagram. A clique is a set of vertices that are adjacent to each other. The 4-clique is a set of four knots all connected. So, in this example of the 4-clique problem, we have a graph with 7 vertices. A brute force algorithm searched all possible combinations of four vertices and found a set that formed a clique. If you want to understand more about it, the problem (and if possible read on). Note that the clique problem is NP-complete, so deterministic search is not practical for large graph sizes. This makes it an ideal candidate for evolutionary exploration. In this problem, we have to assume that we are given the problem of implementing the 4-clique problem as an evolutionary algorithm for an arbitrary graph with an arbitrary number of vertices (an n-vertex graph). If 4 cliques are found, the algorithm succeeds. 1. Provide an algebraic expression, in terms of n, for the size of the phenotypic search space (the number of possible…arrow_forwardThe given inputs consist of two nodes (s, t) and a directed graph G = (V, E). In addition, each edge of the graph is either blue or red. The goal is to find a path from point s to point t such that red edges always follow blue edges. There need not be any red or blue borders on the route, but if there are, the red ones should follow the blue ones. Develop an algorithm that does the task in O(n + m) time and analyze its performance.arrow_forward
- One can manually count path lengths in a graph using adjacency matrices. Using the simple example below, produces the following adjacency matrix: A B A 1 1 B 1 0 This matrix means that given two vertices A and B in the graph above, there is a connection from A back to itself, and a two-way connection from A to B. To count the number of paths of length one, or direct connections in the graph, all one must do is count the number of 1s in the graph, three in this case, represented in letter notation as AA, AB, and BA. AA means that the connection starts and ends at A, AB means it starts at A and ends at B, and so on. However, counting the number of two-hop paths is a little more involved. The possibilities are AAA, ABA, and BAB, AAB, and BAA, making a total of five 2-hop paths. The 3-hop paths starting from A would be AAAA, AAAB, AABA, ABAA, and ABAB. Starting from B, the 3-hop paths are BAAA, BAAB, and BABA. Altogether, that would be eight 3-hop paths within this graph. Write a program…arrow_forwardConsider a graph where vertices represent intersections and edges represent roads. The company Food To Go can place a maximum of one food cart at each intersection. A food cart placed at intersection X has an income equal to the number of roads at intersection X (ie, the degree of vertex X). If two food carts share a road, the income of that road is shared equally among the two. We are interested in calculating the total profit of all food carts placed, ie, the total income minus the cost, where each food cart costs 1 unit and each road provides an income of 1 unit. More formally, the profit for a graph G = (V, E) where the set SC V represents food cart locations, is calculated by the number of edges covered by the vertices in S minus the size of S (ie. |S). A D C E B In this example, placing a food cart on each of the vertices A and C will result in a profit of ISCA P (A D(CD) (CFU VACU-5arrow_forwardIf there is an Euler path that starts at AA and ends at some other vertex, give it. Otherwise enter DNE.This should be a list of letters, from A to the other vertex: e.g. ACBDEAD (if that were even possible!). Path: Since this is a planar graph, the number of regions - arcs + nodes equals what number?arrow_forward
- Java - Consider the following directed graph.arrow_forwardIn this task you will work with an undirected Graph G = {V, E}, where V = {f,p,s,b,l,j,t,c,d} and E = {(1,2), (1,3), (3,8), (4,8), (8,9), (1,7), (2,6), (2,3), (5,6), (6,7), (7,9), (8,1)}. Assume that the nodes are stored in an indexed linear structure (e.g., an array or a vector) numbered consecutively from 1 (node f) to 9 (node d). Run, by hand, a depth-first search (DFS) traversal of the graph G, starting at node p. When choosing which node to visit next amongst the possibilities, choose the one that is next in alphabetical order. Give your answer by listing the edges in the order that DFS will select.arrow_forwardThis is a graph-based Algorithms Questionarrow_forward
- an undirected graph is called complete if every shares an edge with every other vertex.arrow_forwardI have a directed graph with N nodes. How can I tell if the graph has a cycle? Your answer should be an algorithm in English. It is nice but not essential for you to give the name of the algorithm. You should describe how the algorithm works.arrow_forwardIn a graph, two vertices are connected if there is a path between them. If all vertices are connected, we say the graph is connected. Given the Graph ADT below: class Graph { public: void addEdge (int vl, int v2); void delEdge (int vl, int v2); bool hasEdge (int v1, int v2) const; VList adj (int v) const; int v() const; int e() const; } ; Fill in the function isConnected that tells whether graph g is connected or not. Note that you can only use the above methods for g. You may assume vertex ID starts from 0 and define other helper functions if necessary. bool isConnected (const Graph &g) { // Copy this function in the answer and add code below this line. For the toolbar, press ALT+F10 (PC) or ALT+FN+F10 (Mac).arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education