start()
and run ()
interface ()
public boolean binarySearch(int[] arr, int low, int high, key){
//base case returns false when index is out of bound
if(low > high)
return false;
int mid = (low+high)/2
//Searching on mid if key found then return true
if(arr[mid] == key)
return true
//Searching on right sub array if key exist there
else if(arr[mid] < key)
return binarySearch(arr, mid+1, high, key);
//Searching on left sub-array of key exist there.
else
return binarySearch(arr, low, mid-1, key);
}
The difference between LEFT JOIN and RIGHT JOIN in SQL lies in which table's data is fully retained when there is no matching row in the other table.
Returns all records from the left table, and the matched records from the right table.
If there is no match, the result is NULL
on the right side.
SELECT *
FROM A
LEFT JOIN B ON A.id = B.id;
Table A (left) Table B (right)
+----+-------+ +----+--------+
| id | name | | id | dept |
+----+-------+ +----+--------+
| 1 | Alice | | 1 | HR |
| 2 | Bob | | 3 | Sales |
| 3 | Carol |
+----+-------+
Result of LEFT JOIN A and B:
+----+-------+--------+
| id | name | dept |
+----+-------+--------+
| 1 | Alice | HR |
| 2 | Bob | NULL |
| 3 | Carol | Sales |
+----+-------+--------+
Returns all records from the right table, and the matched records from the left table.
If there is no match, the result is NULL
on the left side.
SELECT *
FROM A
RIGHT JOIN B ON A.id = B.id;
Result of RIGHT JOIN A and B:
+----+-------+--------+
| id | name | dept |
+----+-------+--------+
| 1 | Alice | HR |
| 3 | Carol | Sales |
+----+-------+--------+
The classical Waterfall model is a linear and sequential software development methodology. While it was one of the first structured approaches to software development, it has several notable drawbacks, especially for complex or rapidly changing projects:
Once a phase is completed (e.g., design), it's very difficult and costly to go back and make changes.
This rigidity makes it unsuitable for projects where requirements may evolve.
Testing is done at the end, which means bugs and issues are discovered late in the cycle.
Fixing defects late in the process is more expensive and time-consuming.
Assumes all requirements can be gathered up front, which is unrealistic for many real-world projects.
Does not accommodate feedback or requirement changes mid-project.
A working product is delivered only at the end of the development cycle.
This delays customer feedback and increases the risk of the final product not meeting user expectations.
Progress depends on the completion of the previous stage.
A delay or flaw in one phase can cause a domino effect, delaying the entire project.
Clients are typically involved only at the beginning (requirements phase) and end (delivery).
This can result in a product that doesn’t align with actual customer needs or market trends.
Since testing happens after implementation, integrating and verifying all components at once can be difficult and error-prone.
Despite its limitations, Waterfall can be useful for small, simple, or highly regulated projects where:
Requirements are well-understood and unlikely to change.
There is a clear path from start to finish.
Documentation and traceability are essential.
Paging | Segmentation |
---|---|
In paging, the program is divided into fixed or mounted-size pages. | In segmentation, the program is divided into variable-size sections. |
The paging operating system is accountable. | For segmentation compiler is accountable. |
Page size is determined by hardware. | Here, the section size is given by the user. |
It is faster in comparison to segmentation. | Segmentation is slow. |
Paging could result in internal fragmentation. | Segmentation could result in external fragmentation. |
minJumps(start, end) = 1 + Min(minJumps(k, end))
for all k reachable from start.
List |
Set |
Map |
---|---|---|
The list interface allows duplicate elements |
Set does not allow duplicate elements. |
The map does not allow duplicate elements |
The list maintains insertion order. |
Set do not maintain any insertion order. |
The map also does not maintain any insertion order. |
We can add any number of null values. |
But in set almost only one null value. |
The map allows a single null key at most and any number of null values. |
List implementation classes are Array List, LinkedList. |
Set implementation classes are HashSet, LinkedHashSet, and TreeSet. |
Map implementation classes are HashMap, HashTable, TreeMap, ConcurrentHashMap, and LinkedHashMap. |
The list provides get() method to get the element at a specified index. |
Set does not provide get method to get the elements at a specified index |
The map does not provide get method to get the elements at a specified index |
//Method that returns the boolean if element found duplicate or not
public boolean containsDuplicate(int[] arr) {
//LENGTH OF THE ARRAY
int n = arr.length;
//IF ONLY ONE ELEMENT RETURN FALSE
if(n == 1){return false;}
//FOR STORING THE ELEMENTS
HashSet<Integer> set = new HashSet<>();
//O OT N IF ANY ELEMENT ALREADY PRESENT
//RETURN TRUE
for(int i =0; i<n; i++)
{
if(set.contains(arr[i])){return true;}
set.add(arr[i]);
}
//IF NO DUPLICATES PRESENT RETURN FALSE
return false;
}
//Method that returns the boolean if element found duplicate or not
public boolean containsDuplicate(int[] arr) {
//LENGTH OF THE ARRAY
int n = arr.length;
//IF ONLY ONE ELEMENT RETURN FALSE
if(n == 1){return false;}
//FOR STORING THE ELEMENTS
HashSet<Integer> set = new HashSet<>();
//O OT N IF ANY ELEMENT ALREADY PRESENT
//RETURN TRUE
for(int i =0; i<n; i++)
{
if(set.contains(arr[i])){return true;}
set.add(arr[i]);
}
//IF NO DUPLICATES PRESENT RETURN FALSE
return false;
}
class Solution {
public ListNode deleteDuplicates(ListNode head) {
// if LL is empty or contains only 1 element then return LL.
if(head==null || head.next==null) {
return head;
}
// creating a dummy Head for traversing the LinkedList.
ListNode node = head;
while(node.next!=null) {
if(node.val!=node.next.val) {
// if value of current node is same as value of next node then
// traverse the node forward.
node = node.next;
} else {
// if value of current node is same as value of next node then
//connect current with next to next node.
node.next = node.next.next;
}
}
return head;
}
}