Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
You're offline
Unit 3 MCQsUsing RDD for Creating Applications in Spark and Graph Analytics
RDD stands for Resilient Distributed Dataset, Spark's fault-tolerant collection of distributed data.
Question 2 of 60 · Features of RDD · Easy
Which property means that an RDD cannot be changed after it is created?
Not quite. Try another option.
Answer: Immutability
RDDs are immutable. An operation creates a new RDD instead of modifying the existing one.
Question 3 of 60 · Creating RDDs · Easy
Which Spark method creates an RDD from a local collection?
Not quite. Try another option.
Answer: parallelize()
The parallelize() method distributes a local collection and creates an RDD.
Question 4 of 60 · Creating RDDs · Easy
Which method is commonly used to create an RDD by reading a text file?
Not quite. Try another option.
Answer: textFile()
The textFile() method reads a text file and creates an RDD whose elements are lines from the file.
Question 5 of 60 · RDD functions · Easy
Which RDD function applies a given function to every element?
Not quite. Try another option.
Answer: map()
The map() function applies the supplied function to each RDD element and returns a new RDD.
Question 6 of 60 · RDD functions · Easy
Which RDD function keeps only the elements that satisfy a condition?
Not quite. Try another option.
Answer: filter()
The filter() function returns a new RDD containing only elements for which the condition is true.
Question 7 of 60 · RDD operations and methods · Easy
Which of the following is an RDD action?
Not quite. Try another option.
Answer: collect()
The collect() action returns all RDD elements to the driver program.
Question 8 of 60 · RDD operations and methods · Easy
What is lazy evaluation in Spark?
Not quite. Try another option.
Answer: Transformations run only when an action is called
Spark records transformations and evaluates them when an action requests a result.
Question 9 of 60 · Invoking the Spark shell · Easy
Which command normally starts the Spark shell for Scala?
Not quite. Try another option.
Answer: spark-shell
The spark-shell command starts Spark's interactive Scala shell.
Question 10 of 60 · Invoking the Spark shell · Easy
Which command normally starts the interactive Spark shell for Python?
Not quite. Try another option.
Answer: pyspark
The pyspark command starts an interactive Python shell configured for Apache Spark.
Question 11 of 60 · Shared variables · Easy
Which shared variable efficiently sends a read-only value to all worker nodes?
Not quite. Try another option.
Answer: Broadcast variable
A broadcast variable distributes a read-only value to workers and allows it to be reused across tasks.
Question 12 of 60 · Shared variables · Easy
Which Spark shared variable is commonly used to add values across tasks?
Not quite. Try another option.
Answer: Accumulator
An accumulator supports associative additions from tasks and is often used for counters or sums.
Question 13 of 60 · Introduction to Spark GraphX · Easy
What type of data is Spark GraphX designed to process?
Not quite. Try another option.
Answer: Graph data
GraphX is Spark's API for representing and processing graph data made of vertices and edges.
Question 14 of 60 · Introduction to Spark GraphX · Easy
What are the two basic components of a graph in GraphX?
Not quite. Try another option.
Answer: Vertices and edges
A graph consists of vertices representing entities and edges representing relationships between them.
Question 15 of 60 · Spark GraphX features · Easy
Which Spark capability can GraphX use for distributed graph processing?
Not quite. Try another option.
Answer: RDD-based computation
GraphX builds on Spark's distributed RDD model to process graph vertices and edges across a cluster.
Question 16 of 60 · Spark GraphX features · Easy
Which built-in GraphX algorithm ranks important vertices in a graph?
Not quite. Try another option.
Answer: PageRank
PageRank assigns scores to vertices based on the structure and links of the graph.
Question 17 of 60 · Spark GraphX operations · Easy
Which GraphX operation creates a new graph by changing vertex attributes?
Not quite. Try another option.
Answer: mapVertices()
The mapVertices() operation applies a function to each vertex attribute and returns a new graph.
Question 18 of 60 · Spark GraphX operations · Easy
Which GraphX operation produces a graph with the direction of every edge reversed?
Not quite. Try another option.
Answer: reverse()
The reverse() operation swaps the source and destination of each edge.
Question 19 of 60 · Feature extraction and transformation · Easy
What is the main purpose of feature extraction in machine learning?
Not quite. Try another option.
Answer: Convert raw data into useful features
Feature extraction turns raw input into numerical or structured features that a machine-learning model can use.
Question 20 of 60 · Feature extraction and transformation · Easy
Which Spark ML transformer converts a text document into a vector of token counts?
Not quite. Try another option.
Answer: CountVectorizer
CountVectorizer creates feature vectors containing vocabulary-based token counts from text documents.
Question 21 of 60 · Features of RDD · Medium
A Spark application applies several transformations to an RDD and then executes an action. Which RDD feature allows Spark to recompute only lost partitions instead of copying all data?
Not quite. Try another option.
Answer: Partition-level lineage
RDD lineage records how each partition was derived, allowing Spark to recompute only the missing partition after a failure.
Question 22 of 60 · Features of RDD · Medium
Why are RDDs particularly useful for iterative machine-learning algorithms?
Not quite. Try another option.
Answer: They cache intermediate data in memory
Iterative algorithms reuse intermediate datasets, and RDD persistence can avoid repeatedly reading and recomputing the same data.
Question 23 of 60 · Creating RDDs · Medium
Which expression creates an RDD from a local collection in PySpark?
Not quite. Try another option.
Answer: sc.parallelize([1, 2, 3])
parallelize distributes elements from a driver-side collection to create an RDD.
Question 24 of 60 · Creating RDDs · Medium
A text file is stored in HDFS at /data/logs.txt. Which PySpark statement creates an RDD whose records normally represent lines from the file?
Not quite. Try another option.
Answer: sc.textFile("/data/logs.txt")
textFile reads a text file or directory and creates an RDD with one record per line in the usual case.
Question 25 of 60 · RDD functions · Medium
Given rdd = sc.parallelize([1, 2, 3, 4]), which expression returns [2, 4, 6, 8] as an RDD?
Not quite. Try another option.
Answer: rdd.map(lambda x: x * 2)
map applies a function independently to every element while preserving one output element for each input element.
Question 26 of 60 · RDD functions · Medium
An RDD contains sentences, and the goal is to produce one record for every word. Which transformation is most appropriate?
Not quite. Try another option.
Answer: flatMap(lambda line: line.split())
flatMap maps each sentence to a collection of words and flattens all resulting collections into one RDD.
Question 27 of 60 · RDD functions · Medium
Given pair RDD records such as ("A", 3) and ("A", 5), which transformation produces the total value for each key?
Not quite. Try another option.
Answer: reduceByKey(lambda a, b: a + b)
reduceByKey combines values associated with the same key using the supplied associative and commutative function.
Question 28 of 60 · RDD operations and methods · Medium
What is the result of calling rdd.count() on an RDD containing five records?
Not quite. Try another option.
Answer: The integer 5
count is an action that returns the total number of records as a numeric value.
Question 29 of 60 · RDD operations and methods · Medium
Why does rdd.map(lambda x: x * 2) usually not execute immediately?
Not quite. Try another option.
Answer: It is a lazy transformation
Spark records transformations in a lineage graph and evaluates them only when an action requires a result.
Question 30 of 60 · RDD operations and methods · Medium
Which method should be used when an RDD will be reused by multiple actions and should remain available in memory when possible?
Not quite. Try another option.
Answer: persist()
persist marks an RDD for caching, using the selected storage level after its first computation.
Question 31 of 60 · RDD operations and methods · Medium
A developer wants to inspect all elements of a small RDD on the driver. Which action is appropriate?
Not quite. Try another option.
Answer: collect()
collect returns all RDD elements to the driver, so it should be used only when the result is small enough for driver memory.
Question 32 of 60 · Invoking the Spark shell · Medium
Which command starts the Scala-based Spark shell with the Spark context commonly available as sc?
Not quite. Try another option.
Answer: spark-shell
spark-shell launches an interactive Scala environment configured for Spark and provides common Spark objects such as sc.
Question 33 of 60 · Invoking the Spark shell · Medium
Which command is normally used to start the Python version of the Spark interactive shell?
Not quite. Try another option.
Answer: pyspark
pyspark starts the interactive Python shell with Spark functionality configured.
Question 34 of 60 · Shared variables · Medium
A large read-only lookup table is needed by tasks on many executors. Which shared variable avoids sending a separate copy with every task?
Not quite. Try another option.
Answer: Broadcast variable
A broadcast variable distributes a read-only value efficiently to executors for reuse across tasks.
Question 35 of 60 · Shared variables · Medium
Which shared variable is appropriate for counting invalid records across tasks?
Not quite. Try another option.
Answer: Accumulator
Accumulators support associative updates from tasks and allow the driver to read the aggregated value.
Question 36 of 60 · Introduction to Spark GraphX · Medium
In GraphX, a graph is primarily represented as which combination of distributed datasets?
Not quite. Try another option.
Answer: Vertex and edge RDDs
A GraphX graph contains vertices with vertex attributes and directed edges with edge attributes, distributed through RDD-based structures.
Question 37 of 60 · Spark GraphX features · Medium
Which GraphX feature allows graph algorithms to combine graph structure with distributed data processing?
Not quite. Try another option.
Answer: Integration with Spark RDDs
GraphX builds on Spark's distributed execution model and RDD abstractions, enabling graph and data-processing workflows together.
Question 38 of 60 · Spark GraphX operations · Medium
Which GraphX operation creates a new graph by retaining only vertices and edges that satisfy a predicate?
Not quite. Try another option.
Answer: subgraph
subgraph filters vertices and edges according to supplied predicates and returns the resulting graph.
Question 39 of 60 · Spark GraphX operations · Medium
Which GraphX operation is designed to send messages along edges and aggregate messages at destination vertices?
Not quite. Try another option.
Answer: aggregateMessages
aggregateMessages supports the message-passing pattern used by many graph algorithms by combining messages at vertices.
Question 40 of 60 · Feature extraction and transformation · Medium
A dataset contains the categorical values red, blue, and green. Which transformation is commonly used before applying a machine-learning algorithm that requires numeric input?
Not quite. Try another option.
Answer: One-hot encoding
One-hot encoding transforms categorical values into numeric indicator features suitable for many machine-learning algorithms.
Question 41 of 60 · Features of RDD · Hard
An RDD is persisted using MEMORY_ONLY. After several partitions are cached, an executor holding one cached partition fails. The original data is still available in HDFS. What occurs when an action next requires the lost partition?
Not quite. Try another option.
Answer: Spark recomputes only the lost partition using the RDD lineage.
RDDs are fault-tolerant through lineage. A lost cached partition can be reconstructed from its dependencies without recomputing unaffected cached partitions.
Question 42 of 60 · Features of RDD · Hard
A pair RDD already has a HashPartitioner named p. Which transformation sequence preserves that partitioner, allowing a subsequent reduceByKey(p, f) to avoid an unnecessary reshuffle?
Not quite. Try another option.
Answer: rdd.mapValues(g).filter(predicate)
mapValues preserves the parent pair RDD's partitioner, and filter also preserves partitioning. General map, keyBy, or a non-preserving mapPartitions drops it.
Question 43 of 60 · Creating RDDs · Hard
A directory contains thousands of small UTF-8 files. An application must create an RDD in which each record contains one file's path and its complete contents, rather than one record per line. Which creation method directly provides this representation?
Not quite. Try another option.
Answer: sc.wholeTextFiles(path)
wholeTextFiles produces (filename, contents) pairs, with each file represented as a single logical record.
Question 44 of 60 · Creating RDDs · Hard
Two ordinary RDDs without partitioners are created as a = sc.parallelize(dataA, 3) and b = sc.parallelize(dataB, 5). What is normally true of a.union(b) before any later repartitioning?
Not quite. Try another option.
Answer: It has eight partitions and narrow dependencies on both parents.
For ordinary unpartitioned RDDs, union preserves the parent partitions, so the counts are added. Each output partition reads one parent partition without a shuffle.
Question 45 of 60 · RDD functions · Hard
An RDD has exactly two partitions containing [1, 2] and [3, 4]. What does rdd.aggregate(10)((x, y) => x + y, (x, y) => x + y) return?
Not quite. Try another option.
Answer: 40
The zero value is applied once in each partition and once during result combination: (10+1+2) + (10+3+4) + 10 = 40. A non-neutral zero value therefore affects the result multiple times.
Question 46 of 60 · RDD functions · Hard
Suppose empty is an RDD with no elements but several empty partitions. Which statement correctly distinguishes empty.fold(0)(_ + _) from empty.reduce(_ + _)?
Not quite. Try another option.
Answer: fold returns 0, whereas reduce fails because no element exists.
fold has an explicit zero value and can return it for an empty RDD. reduce requires at least one RDD element from which to initialize its aggregation.
Question 47 of 60 · RDD operations and methods · Hard
Two RDDs have the same total element count and the same number of partitions, but corresponding partitions contain different numbers of elements. What happens when left.zip(right) is evaluated?
Not quite. Try another option.
Answer: It fails because corresponding partitions must have equal element counts.
zip requires both the same number of partitions and the same number of elements in each corresponding partition. Equal global counts alone are insufficient.
Question 48 of 60 · RDD operations and methods · Hard
An RDD currently has four partitions. The application executes rdd.coalesce(8, shuffle = false) and, separately, rdd.repartition(8). What partition counts should be expected?
Not quite. Try another option.
Answer: coalesce keeps four, while repartition creates eight.
A non-shuffling coalesce is intended to reduce partitions and cannot effectively increase them. repartition performs a shuffle and can create eight partitions.
Question 49 of 60 · Invoking the Spark shell · Hard
A developer launches spark-shell --master local[2]. Assuming tasks are otherwise runnable and each task uses one CPU, what does the master setting primarily permit?
Not quite. Try another option.
Answer: Up to two tasks to execute concurrently in one local JVM.
local[2] runs Spark locally with two worker threads. It limits local task concurrency, not the partition count of every RDD.
Question 50 of 60 · Invoking the Spark shell · Hard
A Spark shell requires an GB driver heap. Which approach configures this reliably?
Not quite. Try another option.
Answer: Launch it using spark-shell --driver-memory 8g.
The driver's JVM heap must be configured before that JVM starts. Changing the property from inside an already running shell cannot resize its heap.
Question 51 of 60 · Shared variables · Hard
An accumulator is incremented inside a lazy map transformation, and the transformed RDD is evaluated by two separate actions without persistence. Why is the accumulator unsuitable for reporting an exact number of input records?
Not quite. Try another option.
Answer: Each action may recompute the transformation and increment the accumulator again.
Transformations are lazy and may be recomputed for multiple actions or task attempts. Accumulator updates in transformations therefore should not be used for exact application logic.
Question 52 of 60 · Shared variables · Hard
A large lookup table is distributed using a broadcast variable. The driver later creates a substantially updated version that future tasks must use. What is the appropriate design?
Not quite. Try another option.
Answer: Create a new broadcast and release the old broadcast when it is no longer used.
Broadcast variables are intended as read-only serialized snapshots. Updated data should be distributed through a new broadcast; the old one can be unpersisted or destroyed when safe.
Question 53 of 60 · Introduction to Spark GraphX · Hard
A GraphX graph is constructed with a vertex RDD containing only vertex 1, an edge from vertex 1 to vertex 2, and "unknown" as the default vertex attribute. How is vertex 2 represented?
Not quite. Try another option.
Answer: It is added to the graph with the attribute "unknown".
GraphX uses the supplied default vertex attribute for edge endpoints missing from the provided vertex RDD.
Question 54 of 60 · Introduction to Spark GraphX · Hard
Which information is available directly from each element of a GraphX graph's triplets view?
Not quite. Try another option.
Answer: Source ID and attribute, destination ID and attribute, and edge attribute.
An EdgeTriplet joins an edge with the attributes of its source and destination vertices. Global graph metrics are not automatically included.
Question 55 of 60 · Spark GraphX features · Hard
A graph contains many parallel edges in both directions between the same pairs of vertices. Which GraphX partition strategy hashes the canonicalized endpoint pair so that direction-reversed edges for a pair are assigned consistently?
Not quite. Try another option.
Answer: CanonicalRandomVertexCut
CanonicalRandomVertexCut hashes the ordered form of the endpoint pair, using the smaller and larger vertex IDs. Thus, opposite-direction edges between the same vertices are colocated.
Question 56 of 60 · Spark GraphX features · Hard
A GraphX subgraph operation receives both a vertex predicate and an edge-triplet predicate. Which statement describes the resulting graph?
Not quite. Try another option.
Answer: It retains accepted vertices and accepted edges whose two endpoints are retained.
subgraph filters vertices and edges. An edge remains only if its edge predicate passes and both endpoint vertices survive; accepted isolated vertices may remain.
Question 57 of 60 · Spark GraphX operations · Hard
A graph has weighted edges (1,2,3), (3,2,5), and (2,3,7), where each tuple is (source, destination, weight). aggregateMessages sends each edge's weight only to its destination and merges messages using addition. Which result is produced?
Not quite. Try another option.
Answer: Vertex 2 receives 8, vertex 3 receives 7, and vertex 1 is absent.
Vertex 2 receives , and vertex 3 receives . The returned VertexRDD contains only vertices that received at least one message.
Question 58 of 60 · Spark GraphX operations · Hard
An auxiliary RDD[(VertexId, U)] has data for only some graph vertices. Which operation invokes an update function for every graph vertex while representing a missing auxiliary value with None?
Not quite. Try another option.
Answer: outerJoinVertices
outerJoinVertices passes an Option[U] to the update function for every vertex. joinVertices applies its update only where the auxiliary RDD has a matching vertex ID.
Question 59 of 60 · Feature extraction and transformation · Hard
A text pipeline applies HashingTF with a small numFeatures value and then fits IDF. Two frequent terms collide into the same hash index. What is the consequence?
Not quite. Try another option.
Answer: Their counts and document-frequency evidence share one feature and cannot be separated by IDF.
Hash collisions combine terms into the same vector coordinate. IDF operates on coordinates, so it cannot recover the original separate terms or their individual document frequencies.
Question 60 of 60 · Feature extraction and transformation · Hard
A dataset contains million-dimensional vectors with only a few nonzero entries per row. What is the principal risk of applying StandardScaler with withMean = true?
Not quite. Try another option.
Answer: Mean centering can convert sparse vectors into dense vectors and exhaust memory.
Subtracting a nonzero mean from originally zero entries introduces many nonzero values. Spark therefore produces dense output when centering, which can be prohibitively expensive for high-dimensional sparse data.
That's unit 3
Answer a few questions and your score shows up here.
Nearly through. Did unit 3 of INT315 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 3 of INT315 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.