All Week Advanced Data Structures in Java Coursera Quiz Answers
Table of Contents
Advanced Data Structures in Java Week 01 Quiz Answers
Quiz 1: Pre-course quiz
Q1. If you took the second course in the specialization (Data Structures: Measuring and Optimizing Performance), feel free to skip this quiz! If not, continue on….
Hold on, isn’t it a bit too early for a quiz?
Because this isn’t an introductory programming course and is, in fact, the third course in an intermediate programming specialization, one of the most common questions we’ve gotten is “Am I ready for this course?” To help you answer this question, we encourage you to work through this quiz. About two-thirds of these questions ask about your experience, while the other third are technical questions that involve programming in Java.
If you score 60% or greater, you’re in the right place.
If you score between 35 and 60%, we recommend you look into either the first course in our specialization “Object Oriented Programming in Java” or the second course in our specialization “Data Structures: Measuring and Optimizing Performance” or both and come back to this course after you finish the first.
If you score less than 35%, we recommend you start with this Coursera Introduction Java Programming Specialization and come back to our specialization when you complete those courses.
However, you are very welcome to stick with this course instead if you prefer, and if you don’t mind brushing up on your Java programming as needed along the way.
So let’s begin:
Have you written code in Java?
- Yes
- No
Q2. Have you written code that uses conditional statements (if-statements), including using compound boolean expressions (e.g. x < 5 && x > 0) and multiple if-else clauses (e.g. if… else if… else), to solve problems?
- Yes
- No, or I’m not sure
Q3. Have you implemented code that uses for-loops and while-loops, including nested for-loops?
- Yes
- No or I’m not sure
Q4. Have you written methods that take parameters, both with and without return values?
- Yes
- No, or I’m not sure
Q5. Have you authored classes (or methods in classes) that were part of a specific inheritance hierarchy? In other words, have you worked with classes which “extend” other classes or classes which “implement” an interface?
- Yes
- No, or I’m not sure
Q6. Have you written code that manipulates (i.e. accesses and/or changes the values in) arrays in Java? E.g.
// Assume arr is an array of ints
int sum = 0;
for (int i = 0; i < arr.length; i++) {
sum += arr[i];
arr[i] += 1;
}
- Yes
- No
Q7. Have you analyzed the running time of code or algorithms using Big-O (asymptotic) notation?
- Yes
- I think so, but I can’t really remember how
- No
Q8. Have you authored a linked data structure (e.g. a Linked List or a Tree) in Java or another language?
- Yes
- No, but I am comfortable with how they are implemented
- No
Q9. What is the output of the following Java code (assume the code is in main)?
int x = 7;
int y = x;
x = 2;
System.out.println(x + ", " + y);
- 2, 7
- 2, 2
Q10. Consider the following code:
public class MyClass
{
private int a;
public double b;
public MyClass(int first, double second)
{
this.a = first;
this.b = second;
}
What would this code print? Hint – draw a memory model!
Note that this might seem like a compiler error to be accessing c1.a and c1.b from main, but because the method main is defined in the class “MyClass”, it will compile just fine (feel free to check it for yourself).
- 2
- 10
Q11.
public class Question11 {
public static void main(String[] args) {
int[] array = {20, -10, 15, -7, -8, 45};
int sum = 0;
for(int i = 0; i<array.length;i++) {
// MISSING IF STATEMENT //
sum+=array[i];
}
}
System.out.println(sum);
}
}
In the code above, which if statement below would make it so only the positive values in the array are summed? In other words, once the missing if statement is included, the program will print the value 80.
if( i>= 0) { if(array[i] > 0) { if( i > 0) { if(array[i] < 0) {
Q12. What is the big-O class of the number of operations executed when running the method below, where n is the size of arr? Remember, when we’re talking about Big-O analysis, we only care what happens when n is very large, so don’t worry that this method might have problems on small array sizes.
int sumTheMiddle(int[] arr) {
int range = 100;
int start = arr.length/2 - range/2;
int sum = 0;
for (int i=start; i< start+range; i++)
{
sum += arr[i];
}
return sum;
} O(2^n2
n
) O(n^2n
2
) O(nn) O(11)
- O(2^n2n)
- O(n^2n2)
- O(nn)
- O(11)
Q13. Based on your score of this quiz, what do we recommend you do?
- If you score 60% or greater, go on to the next video.
- If you score between 35 and 60%, we recommend you look into our first course in this specialization: Object Oriented Programming in Java.
- If you score less than 35%, we recommend you start with this Coursera Introduction Java Programming Specialization and come back to our specialization when you complete those courses.
- Regardless of my score, just go onto the next video.
Quiz 2: Survey: Your goals for the course
Q1. What is/are your reasons for taking this course? We recognize that
you probably don’t know exactly what this course is about, specifically,
but take your best guess. Please select all that apply.
- To brush up on material I already learned
- To learn this material for the first time
- To earn the course certificate
- To complete the specialization
- To learn Java
- I’m not sure. I’m just browsing.
- Some other reason (please let us know in the last question)
Q2. How much of the course do you intend to complete?
- The videos and readings, and all of the required assessments, including the programming assignments.
- Most of the videos, some of the quizzes, and I might try some of the programming assignments.
- Some of the videos and readings, probably no assessments.
- I might watch a few more videos. I’m still figuring out what this course is about.
- I probably won’t continue after this survey.
Q3. How did you discover this course? Please select all that apply.
- A general internet search (please tell us your search terms in the last question)
- A search on Coursera (please tell us your search terms in the last question)
- Browsing Coursera’s catalog
- I’m continuing from Course 2 in the specialization
- An email from Coursera
- A personal contact (e.g., friend, teacher, parent, etc.)
- Other (please tell us in the last question)
Q4. If applicable, please provide more information about any of the
questions above. Specifically, what search terms did you use to find
this course, or what other reasons do you have for taking this course?
What do you think?
Your answer cannot be more than 10000 characters.
Quiz 3: Course Structure and Starter Code Quiz (make sure you can run the starter code first)
Q1. Which of the following are among the things that you will learn in this course? Select all that apply.
- How to implement the Graph data structure
- The basics of creating classes in Java
- Algorithms for searching a graph.
- How to build a Web crawler
Q2. Which video series in this course will present the fundamental concepts and skills you need to complete the assignments?
- The Core series
- The Support series
- The Concept Challenges
- The “In the Real World” series
Q3. Next week you will be working with the files in the basicgraph package. Open this package in the Eclipse Package Explorer. Then select all of the files from the list below that are included in that package.
- BasicGraph.java
- Graph.java
- GraphAdjList.java
- GraphAdjMatrix.java
- MapGraph.java
Q4. Which of the following is a correct statement about the classes in the basic graph package?
- Graph is an abstract class and its subclasses are GraphAdjList and GraphAdjMatrix
- GraphAdjList is an abstract class and its subclass is Graph
- Graph, GraphAdjList and GraphAdjMatrix are all abstract classes.
Q5. Run the main method in the class Graph. You will see the following information printed out:
Loading graphs based on real data…
Goal: use degree sequence to analyse graphs.
Roads/intersections:
Graph with _ vertices and _ edges.
…
We have replaced the numbers in the statement above with blanks. What is the actual statement that is printed?
- Graph with 5 vertices and 14 edges.
- Graph with 8 vertices and 20 edges
- Graph with 10 vertices and 35 edges
- Graph with 9 vertices and 22 edges
Q6. Which data folder contains the street data in a format suitable for loading into Roadgraph.MapGraph objects?
- mazes
- intersections
- maps
Advanced Data Structures in Java Week 02 Quiz Answers
Quiz 1: Graphs
Q1. What’s the maximum number of edges in a directed graph with n vertices?
- Assume there are no self-loops (i.e. edges from a node back to itself).
- Assume there there is at most one edge from a given start vertex to a given end vertex.
NOTE: you might wonder why we’re asking you a math question. It turns out that the relationship between the number of vertices and the number of edges in our graph data structure will have a huge impact on the performance of our code. In order to analyze our algorithms and predict which problems we’ll be able to feasibly solve, we need to get through some calculations.
Even though we haven’t done the calculation in the slides, try it out yourself. If you don’t get it right the first time, we have some hints to help you out.
One more note: the answer to this question is a math expression. Use the input tool to make sure your syntax matches up with the expected format. The syntax checker treats ‘n’ differently from ‘N’. Also, please simplify your formula.
Preview will appear here…
Enter math expression here
Q2. What’s the maximum number of edges in an undirected graph with n vertices?
- Assume there are no self-loops.
- Assume there there is at most one edge from a given start vertex to a given end vertex.
Again, please simplify your formula.
Preview will appear here…
Enter math expression here
Quiz 2: Where to next?
Q1. Now that you’ve seen the basics of graph representation, what do you want to do next?
- Learn how these ideas are used in the real world and get more practice
- Learn a little more about ideas that will help me with the project in the next Core video
- I’m ready to get started. Take me to the project!
Quiz 3: Graph definitions and implementation
Q1. Consider the following adjacency matrix representation of a directed graph (represented as code for nicer formatting):
1 0 0 1
0 1 0 1
0 0 1 0
0 1 1 1
How many edges are in this graph? Hint: Self-loops should be counted as edges.
Answer: 9
Q2. Consider the same adjacency matrix representation of a directed graph (represented as code for nicer formatting):
1 0 0 1
0 1 0 1
0 0 1 0
0 1 1 1
How many vertices in this graph have a self-loop, i.e. an edge that starts in a vertex and ends at the same vertex it started at?
Answer: 2
Q3. If you have a graph with 5 vertices and 2 edges, how many total entries (not just non-zero entries) are there in the matrix with an adjacency matrix representation of this graph?
Answer: 25
Q4. Consider the following adjacency list representation of a directed graph:
0 -> {}
1 -> {2, 3}
2 -> {1}
3 -> {0, 2, 3}
4 -> {0, 1, 3, 4}
How many edges does this graph have?
Answer: 9
Q5. Consider the following adjacency list representation of a directed graph:
0 -> {} 1 -> {2, 3} 2 -> {1} 3 -> {0, 2, 3} 4 -> {0, 1, 3, 4} Which vertex in this graph has the highest in-degree?
Answer: 1
Q6. Consider the following adjacency list representation of a directed graph (note: this graph is slightly different from the graph in the previous two questions):
0 -> {} 1 -> {2, 3} 2 -> {1, 3} 3 -> {0, 2, 3} 4 -> {0, 1, 3, 4}
What is the degree sequence for this graph? Make sure you put a single space between each number in the sequence. There should be no commas or additional spaces in the sequence.
Note: make sure you list the degrees in the correct order.
Answer: 02234
Q7. Consider the following adjacency list representation of a directed graph:
0 -> {} 1 -> {2, 3} 2 -> {1} 3 -> {0, 2, 3} 4 -> {0, 1, 3, 4}
Which of the following pairs of vertices have paths from the first vertex to the second? Select all that apply.
- From 4 to 0
- From 3 to 4
- From 1 to 4
- From 1 to 0
- From 0 to 1
Advanced Data Structures in Java Week 03 Quiz Answers
Quiz 1: Where to next?
Q1. Now that you’ve seen basic graph search, where do you want to go next?
- More practice with these search algorithms, please (note that you’ll be asked to analyze the running time of these algorithms on the end of week quiz).
- Take me to the next core videos on class design and refactoring.
Quiz 2: End of Week Quiz (complete project and peer review first)
Q1. What is the running time of the breadth-first search (BFS) algorithm in the worst case?
- O(V^2)
- O(V)
- O(E + V)
Q2. Which of the following is true about code refactoring? Select all that apply.
- It is common during code development
- It should be avoided unless absolutely necessary
- It refers to the process of changing the structure of the code without changing its functionality
- It generally changes the code’s public interface.
Q3. Which of the following is/are true about Depth First Search (DFS)?
- In the worst case, depth-first search is more efficient than breadth-first search.
- DFS usually finds a shorter path (in terms of number of nodes) than BFS.
- DFS uses a Stack to hold the list of unexplored nodes.
- DFS has a straightforward recursive solution.
- DFS will always find a path from Start to Goal if there is one.
Q4. Which of the following is the better representation for the MapGraph graph that you implemented in the programming project this week?
- Adjacency List
- Adjacency Matrix
Advanced Data Structures in Java Week 05 Quiz Answers
Quiz 1: End of Week Quiz
Q1. What is the tightest bound Big-O running time of the brute force solution to the traveling salesperson problem (TSP), where nn is the number of nodes in the graph?
- O(2^n)O(2 n )
- O(n^k)O(n k )
- O(n!)O(n!)
- O(n^2)O(n 2 )
Q2. If you know that a problem is considered NP-Hard, that means:
- You can be sure there is a polynomial time – O(n^k)O(n k ) – solution.
- You can be sure there is no polynomial time – O(n^k)O(nk ) – solution.
- You can be sure that the problem is at least as hard as a set of problems where there is no known polynomial – O(n^k)O(n k ) – solution.
Q3. For which of the graphs below would the greedy algorithm (nearest neighbor) NOT find the best solution to the Travelling Salesperson Problem assuming A is the start vertex? Again, each node must be visited once and you must return back to A.
Q4. Which of the following is true about the 2-opt heuristic as explained this week?
- 2-opt is an approach that may improve a non-optimal solution to the TSP problem but may end up producing a solution worse than the original non-optimal solution
- 2-opt is an approach that may improve a non-optimal solution to the TSP problem and is guaranteed to do no worse than the original non-optimal solution
- 2-opt is an approach that is guaranteed to improve a non-optimal solution to the TSP problem to create an optimal solution for the TSP problem
Q5. A Hamiltonian graph is one where there’s some path through the graph that visits every vertex exactly once. An Eulerian graph is one where there’s some path through the graph that traverses every edge exactly once.
Which of the following is true about Hamiltonian and Eulerian graphs?
(Select all that apply.)
- Every Hamiltonian graph is Eulerian because every Hamiltonian path uses each edge at most once.
- Each graph is either Hamiltonian or Eulerian.
- There can be a graph that is Hamiltonian but not Eulerian.
Week 6: Project Quiz (Complete your project extension first)
Q2. In one paragraph, describe what you did with your extension to someone who will just be using your application and doesn’t know anything about programming. (Keep this answer, and copy-paste to another document- if you want to submit it for the optional peer review.)
Answer: To someone who will be using the application without programming knowledge, I added an extension that enhances the user experience. This extension provides a feature that allows users to customize the appearance of the interface, change color themes, and adjust text sizes to make the application more visually appealing and user-friendly. Users can access these options through simple menu settings, making it easy to personalize the application to suit their preferences, without needing any programming skills.
Q3. In one paragraph, describe what you did with your extension to someone else on the same project team. What problems did you encounter and how did you fix them? (Keep this answer, and copy-paste to another document- if you want to submit it for the optional peer review.)
Answer: Within the project team, while implementing the extension, I encountered some challenges related to compatibility with the existing codebase. The main problem was ensuring that the new customization features integrated seamlessly with the existing functionality. We had to carefully coordinate the user interface changes to avoid conflicts with other components. We tackled this by conducting thorough testing and iterating on the design to ensure a harmonious integration. Additionally, we provided clear documentation to assist team members in understanding the extension's implementation and how it interacts with the core application, facilitating a smoother collaboration within the team.
Get All Course Quiz Answers of Object Oriented Java Programming: Data Structures and Beyond Specialization
Object-Oriented Programming in Java Coursera Quiz Answers
Data Structures and Performance Coursera Quiz Answers
Advanced Data Structures in Java Coursera Quiz Answers
Mastering the Software Engineering Interview Coursera Quiz Answers