Skip to main content

Featured Post

Salesforce Agentforce Specialist Certification: What It Takes in 2026

 With Agentforce now central to Salesforce's roadmap, demand for people who can actually configure, ground, and govern AI agents has spiked — and Salesforce's certification track has changed to match. If you're weighing whether to get certified in 2026, here's what the credential actually covers and whether it's worth your time. The Certification Landscape Changed in 2026 Salesforce retired the older AI Associate and AI Specialist certifications in early 2026. The current credential is the Salesforce Certified Agentforce Specialist (exam code AI-201 ) — a single, more practical exam replacing the older, more theory-focused ones. What the Exam Actually Tests Rather than abstract AI theory, the Agentforce Specialist exam focuses on real configuration and governance skills: Designing AI workflows using prompts, actions, data, and automation. Grounding agents with relevant, trustworthy data. Building and customizing agents for specific business needs. I...

Sorting Algorithms Explained: Bubble Sort, Merge Sort & Quick Sort

 Sorting is one of the most common problems in computer science, and interviewers love it because it's a great window into how you think about trade-offs. Here are the three sorting algorithms you'll run into most often, explained simply, with working JavaScript code.


1. Bubble Sort — The Simplest One

Bubble sort repeatedly walks through the list, comparing neighbors and swapping them if they're in the wrong order. Bigger values slowly "bubble" toward the end.

function bubbleSort(arr) {
  const a = [...arr];
  for (let i = 0; i < a.length; i++) {
    for (let j = 0; j < a.length - i - 1; j++) {
      if (a[j] > a[j + 1]) {
        [a[j], a[j + 1]] = [a[j + 1], a[j]]; // swap
      }
    }
  }
  return a;
}

console.log(bubbleSort([5, 3, 8, 1, 2])); // [1, 2, 3, 5, 8]

Time complexity: O(n²) — easy to understand, but too slow for large lists. Mostly used for teaching, not production.


2. Merge Sort — Divide and Conquer

Merge sort splits the list in half repeatedly until each piece has just one element (already "sorted" by definition), then merges those pieces back together in sorted order.

function mergeSort(arr) {
  if (arr.length <= 1) return arr;

  const mid = Math.floor(arr.length / 2);
  const left = mergeSort(arr.slice(0, mid));
  const right = mergeSort(arr.slice(mid));

  return merge(left, right);
}

function merge(left, right) {
  const result = [];
  let i = 0, j = 0;

  while (i < left.length && j < right.length) {
    if (left[i] <= right[j]) result.push(left[i++]);
    else result.push(right[j++]);
  }

  return [...result, ...left.slice(i), ...right.slice(j)];
}

console.log(mergeSort([5, 3, 8, 1, 2])); // [1, 2, 3, 5, 8]

Time complexity: O(n log n) in every case — reliably fast, and the standard example of "divide and conquer" thinking.


3. Quick Sort — Fast in Practice

Quick sort picks a "pivot" value, moves everything smaller to its left and everything bigger to its right, then repeats that process on each side.

function quickSort(arr) {
  if (arr.length <= 1) return arr;

  const [pivot, ...rest] = arr;
  const left = rest.filter(n => n < pivot);
  const right = rest.filter(n => n >= pivot);

  return [...quickSort(left), pivot, ...quickSort(right)];
}

console.log(quickSort([5, 3, 8, 1, 2])); // [1, 2, 3, 5, 8]

Time complexity: O(n log n) on average, but O(n²) in the worst case (e.g., an already-sorted array with a poorly chosen pivot). In practice it's usually the fastest general-purpose sort, which is why it backs many built-in sort() implementations.


Which One Should You Use?

  • In real JavaScript code, just use the built-in Array.prototype.sort() — modern engines use a highly-optimized hybrid algorithm under the hood.

  • Know bubble sort to explain the basic idea of comparison-based sorting.

  • Know merge sort when consistent O(n log n) performance matters, or when sorting linked lists.

  • Know quick sort as the go-to fast, in-place, general-purpose sort.


Conclusion

That wraps up this 5-part DSA series: Big O Notation, Arrays vs Linked Lists, Stacks and Queues, Binary Search, and now Sorting Algorithms. Together these cover the foundation that almost every other data structure and algorithm topic builds on — trees, graphs, dynamic programming, and more.

Image: Swfung8 / Wikimedia Commons (CC BY-SA 3.0)

Comments

Popular posts from this blog

Understanding SQL Query Execution Order

When writing SQL queries, understanding the execution order is crucial for writing efficient and optimized code. Many beginners assume that queries execute in the order they are written, but in reality, SQL follows a specific sequence of execution. SQL Execution Order SQL queries run in the following order: 1️⃣ FROM + JOIN 2️⃣ WHERE 3️⃣ GROUP BY 4️⃣ HAVING 5️⃣ SELECT (including window functions) 6️⃣ ORDER BY 7️⃣ LIMIT Let’s break down each step with examples. 1. FROM + JOIN (Data Retrieval) The SQL engine first retrieves data from the specified table(s) and applies any JOIN operations. 🔹 Example: SELECT employees.name, departments.department_name FROM employees JOIN departments ON employees.department_id = departments.id; Here, the JOIN happens before any filtering ( WHERE ) or grouping ( GROUP BY ). 2. WHERE (Filtering Data) Once data is retrieved, the WHERE clause filters rows before aggregation occurs. 🔹 Example: SELECT * FROM employees WHERE salary > 50000 ; Thi...

Top 5 React.js Performance Optimization Techniques for 2025

React.js continues to dominate the front-end development landscape due to its flexibility, component-based architecture, and performance. However, as applications grow, performance issues can emerge, affecting user experience. Here are the top five performance optimization techniques every React developer should consider in 2024. 1. Use React.memo for Component Memoization React.memo is a higher-order component that prevents unnecessary re-renders by memoizing the result. It only re-renders when props change, improving performance for functional components that rely on the same data. import React from 'react';  const ExpensiveComponent = React.memo(({ data }) => {      console.log('Rendering ExpensiveComponent');      return <div>{data}</div>;  }); export default ExpensiveComponent; 2. Implement Code Splitting with React.lazy and Suspense Code splitting reduces the initial load time by splitting the code into smaller bundles. Re...

Best Practices for Securing Personal and Business Data in 2025

In today’s digital landscape, cybersecurity is more critical than ever. With increasing cyber threats, data breaches, and privacy concerns, individuals and businesses must take proactive steps to secure their data. This guide outlines the most effective security practices for 2025. 1. Implement Strong Authentication Measures Passwords alone are no longer sufficient to protect sensitive accounts. Instead, consider: ✅ Multi-Factor Authentication (MFA): Require users to verify their identity using an additional factor, such as an SMS code, authenticator app, or biometric authentication. ✅ Passkeys & Password Managers: Use passkeys where available and store strong, unique passwords in a secure password manager. 2. Encrypt Sensitive Data Encryption ensures that even if data is stolen, it remains unreadable without the decryption key. 🔹 Use end-to-end encryption (E2EE) for messages and emails. 🔹 Encrypt stored data on cloud services, external drives, and local machines. 🔹 Consider ...