Posts

Showing posts from February, 2025

Word Search in Maze using Depth First Search (with python code and step by step code execution walkthrough)

  1. Introduction In this blog, we will explain how to solve the word search problem in a maze using Depth First Search (DFS) algorithm. We will use a 3x3 maze and search for the word 'the' in the maze. The word 'the' is located in the second row of the maze. 2. Algorithm Explanation The DFS algorithm is used to explore all possible paths in the maze to find the target word. We start from each cell in the maze and recursively explore its neighbors to find the word. 2.1 Steps of the Algorithm Start from each cell in the maze. Check if the current cell matches the current character of the word. Mark the current cell as visited. Recursively explore the neighboring cells (up, down, left, right). Unmark the current cell and backtrack if the word is not found. Return true if the word is found, otherwise return false. 3. Python Code def dfs(maze, word, i, j, index): if index == len(word): return True if i < 0 or i >= len(maze) or j < 0 or j >= len(...

Finding Free Slots in Two People's Calendar (with python code and step by step code execution walkthrough)

1. Sorted Merge of Two Lists of Numbers 1.1 Algorithm Explanation The sorted merge algorithm takes two sorted lists of numbers and merges them into a single sorted list. We use two pointers to keep track of the current element in each list and compare the elements to determine the order in the merged list. 1.2 Python Code def merge_sorted_lists(list1, list2): merged_list = [] i, j = 0, 0 while i < len(list1) and j < len(list2): if list1[i] < list2[j]: merged_list.append(list1[i]) i += 1 else: merged_list.append(list2[j]) j += 1 while i < len(list1): merged_list.append(list1[i]) i += 1 while j < len(list2): merged_list.append(list2[j]) j += 1 return merged_list 1.3 Example Lists: List 1: [1, 3, 5] List 2: [2, 4, 6] Merged List: merged_list = merge_sorted_lists([1, 3, 5], [2, 4, 6]) print(merge...

Understanding the grep Command in Linux for beginners (with examples)

 Understanding the grep Command in Linux The grep command in Linux is used for searching text using patterns. It stands for "Global Regular Expression Print". grep is a powerful utility that allows you to search for specific patterns within files and directories. Below, we will discuss some of the most important and frequently used grep commands with examples. 1. Basic grep Usage 1.1 grep in a Single File To search for a pattern in a single file, use the following syntax: grep "pattern" filename Example : grep "hello" example.txt This command searches for the word "hello" in the file example.txt and prints the lines containing it. 2. Case Insensitive grep 2.1 Using -i Option The -i option makes the search case insensitive. grep -i "pattern" filename Example : grep -i "hello" example.txt This command searches for "hello", ...

Printing organization hierarchy in PLSQL for beginners (with step by step code execution walkthrough)

  Understanding PL/SQL Code to Print Organization Hierarchy Introduction In this blog post, we will learn how to create and execute a PL/SQL function to print the organization hierarchy in an employee table. This example uses a loop to traverse the hierarchy from a given employee up to the CEO. We will break down each step of the code, explain its purpose, and show the values of variables at each iteration. 1. Setting Up the Employee Table Let's start by creating an example employee table with three columns: employee_id , employee_name , and manager_id . We'll insert five employees into this table. CREATE TABLE employee ( employee_id NUMBER PRIMARY KEY, employee_name VARCHAR2(50), manager_id NUMBER ); INSERT INTO employee (employee_id, employee_name, manager_id) VALUES (1, 'Alice', NULL); INSERT INTO employee (employee_id, employee_name, manager_id) VALUES (2, 'Bob', 1); INSERT INTO employee (employee_id,...