0
0
DynamoDBquery~20 mins

Adjacency list pattern in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Adjacency List Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Retrieve all direct children of a parent node

Given a DynamoDB table using the adjacency list pattern where each item has a NodeId and a ParentId, which query will return all direct children of the node with NodeId = 'A1'?

DynamoDB
Table: Nodes
Attributes: NodeId (PK), ParentId
Sample data:
{NodeId: 'A1', ParentId: null}
{NodeId: 'B1', ParentId: 'A1'}
{NodeId: 'B2', ParentId: 'A1'}
{NodeId: 'C1', ParentId: 'B1'}
AQuery with KeyConditionExpression: ParentId = 'A1' using ParentId as partition key
BQuery with KeyConditionExpression: NodeId = 'A1'
CScan with FilterExpression: ParentId = 'A1'
DScan with FilterExpression: NodeId = 'A1'
Attempts:
2 left
💡 Hint

Remember that in DynamoDB, Query works only on the partition key. If ParentId is not the partition key, you cannot query by it directly.

🧠 Conceptual
intermediate
1:30remaining
Understanding adjacency list pattern in DynamoDB

In the adjacency list pattern, how is the parent-child relationship typically represented in a DynamoDB table?

AEach item stores its own <code>NodeId</code> and the <code>ParentId</code> of its parent node
BEach item stores a list of all its children <code>NodeIds</code> in an attribute
CEach item stores only its <code>NodeId</code> without any reference to parent or children
DEach item stores the entire path from root to itself as a string
Attempts:
2 left
💡 Hint

Think about how you can find a node's parent or children by looking at attributes.

📝 Syntax
advanced
2:00remaining
Identify the syntax error in this DynamoDB query expression

Which option contains a syntax error in the DynamoDB query expression to find children nodes?

DynamoDB
Query parameters example:
{
  TableName: 'Nodes',
  KeyConditionExpression: 'ParentId = :pid',
  ExpressionAttributeValues: { ':pid': 'A1' }
}
AKeyConditionExpression: 'ParentId = :pid', ExpressionAttributeValues: { ':pid': 'A1' }
B} '1A' :'dip:' { :seulaVetubirttAnoisserpxE ,'dip: = dItneraP' :noisserpxEnoitidnoCyeK
CKeyConditionExpression: 'ParentId = :pid', ExpressionAttributeValues: { ':pid': { S: 'A1' } }
DKeyConditionExpression: 'ParentId == :pid', ExpressionAttributeValues: { ':pid': 'A1' }
Attempts:
2 left
💡 Hint

Check the operator used in the KeyConditionExpression.

optimization
advanced
2:30remaining
Optimize adjacency list queries for children nodes

You want to efficiently query all children of a node by ParentId in DynamoDB. Which table design improves query performance?

AUse <code>ParentId</code> as the partition key and <code>NodeId</code> as the sort key
BUse <code>NodeId</code> as the partition key and <code>ParentId</code> as a regular attribute
CUse a composite key with <code>NodeId</code> and a timestamp
DUse a global secondary index with <code>NodeId</code> as partition key
Attempts:
2 left
💡 Hint

Think about which key allows you to query all children by parent efficiently.

🔧 Debug
expert
3:00remaining
Why does this recursive adjacency list traversal fail in DynamoDB?

A developer tries to recursively fetch all descendants of a node by repeatedly querying children using ParentId. The code runs but returns incomplete results. What is the most likely cause?

AThe developer used Scan instead of Query, causing inconsistent results
BDynamoDB Query only returns up to 1MB of data per request, so pagination is needed to get all children
CThe table does not have a <code>ParentId</code> attribute, so queries fail silently
DRecursive queries are not supported in DynamoDB and cause runtime errors
Attempts:
2 left
💡 Hint

Consider DynamoDB limits on query results and how to handle large datasets.