It - NM Assign 6
It - NM Assign 6
1. Analyze a website that tracks user orders, suggest appropriate data structure to be used
for efficient search of items in the website. List down the time and space complexity of the
suggestion provided.
Let’s analyze the requirements for efficiently searching user orders on a website and recommend an
appropriate data structure. We’ll consider both time and space complexities.
a) Binary Search Tree (BST):
o Description: A BST is a tree-based data structure where each node has at most two
children: a left child (with a value less than the parent) and a right child (with a value
greater than the parent).
o Efficiency:
▪ Search Time Complexity: O(log n) on average (assuming a balanced tree).
▪ Space Complexity: O(n) to store n elements.
o Advantages:
▪ Efficient search for arbitrary elements.
▪ Maintains order (useful for range queries).
o Considerations:
▪ Ensure the tree remains balanced (e.g., AVL tree or Red-Black tree) to
maintain efficiency.
b) Hash Table (HashMap):
o Description: A hash table uses a hash function to map keys to indices in an array. It
provides fast access to values based on their keys.
o Efficiency:
▪ Search Time Complexity: O(1) on average (assuming a good hash function
and minimal collisions).
▪ Space Complexity: O(n) to store n key-value pairs.
o Advantages:
▪ Extremely fast lookups.
▪ Ideal for direct key-based access.
Reg. No 313522205020 NM - Stream Design Thinking
Name HARISH.R Assignment No 6
Year & Sem II Year & IV Sem Submission Date 22.04.2024
Department B.Tech – Information Technology Module 6
Gmail ID’S [email protected] Total Pages 5
o Considerations:
▪ Handle hash collisions (e.g., using chaining or open addressing).
c) Trie (Prefix Tree):
o Description: A trie is a tree-like data structure used for efficient string matching and
retrieval.
o Efficiency:
▪ Search Time Complexity: O(m), where m is the length of the search key.
▪ Space Complexity: O(n * m), where n is the number of orders and m is the
average order length.
o Advantages:
▪ Efficient for prefix-based searches (e.g., searching for order numbers).
▪ Space-efficient for common prefixes.
o Considerations:
▪ May consume more memory due to branching.
d) Bloom Filter:
o Description: A probabilistic data structure that tests whether an element is a member
of a set.
o Efficiency:
▪ Search Time Complexity: O(1) (approximate, with a small false positive rate).
▪ Space Complexity: Depends on the desired false positive rate.
o Advantages:
▪ Extremely memory-efficient.
▪ Useful for filtering out non-existent orders.
o Considerations:
▪ May produce false positives (i.e., indicating an order exists when it doesn’t).
e) Balanced Binary Search Tree (e.g., AVL Tree):
o Description: An extension of BST that ensures the tree remains balanced.
o Efficiency:
▪ Search Time Complexity: O(log n) even in worst-case scenarios.
Reg. No 313522205020 NM - Stream Design Thinking
Name HARISH.R Assignment No 6
Year & Sem II Year & IV Sem Submission Date 22.04.2024
Department B.Tech – Information Technology Module 6
Gmail ID’S [email protected] Total Pages 5