pass
class Circle(Shape):
def draw(self):
print("Drawing a circle")
class Rectangle(Shape):
def draw(self):
print("Drawing a rectangle")
final int MAX_SIZE = 100; // MAX_SIZE cannot be reassigned
The time complexity of bubble sort in data structure is O(n^2), where n is the number of elements.
In this example, polymorphism allows different shapes to implement their own version of the drawing method.
Q 47. What is a binary tree, and how does it differ from a binary search tree?
A binary tree in the data structurewhere each node has at most two children, while a Binary Search Tree in Data
Structuresis a binary tree where the left child is smaller and the right child is larger than the parent node.
A linked list is a linear data structure where each element points to the next element, whereas an array stores elements in
contiguous memory locations.
The final keyword can be applied to variables, methods, and classes. It indicates that the value of a variable cannot be
changed, a method cannot be overridden, and a class cannot be subclassed.
Read More: What is Exception Handling in Java?: try, catch, throw, finally
A binary tree is a tree structure where each node can have up to two child nodes (left and right), but there are no specific
rules about the order of the nodes.
A binary search tree (BST) is a specific type of binary tree with an added rule: for each node, the left child node's value
must be smaller, and the right child node's value must be larger. This ordering allows faster searching, inserting, and
deleting of values.
In a binary tree, node values can be in any order, while in a BST, nodes are organized to support efficient data lookup.
An LRU cache is typically implemented using a hash map (for fast access) and a doubly linked list (for maintaining the order
of access). Example: When the cache reaches its limit, the least recently used element is removed. For example, in a web
browser, the most recently accessed pages are kept in memory, and the least recently accessed ones are removed when the
cache is full.
Q 50. What is the time complexity of bubble sort?
Q 51. What is the purpose of the ‘final’ keyword in Java?
Q 49. What is a linked list, and how does it differ from an array?
Q 48. How do you implement an LRU (Least Recently Used) cache?
Sample Code