Pages

Tuesday, August 12, 2025

Find Permutation using Backtracking in Java

 // Online Java Compiler

// Use this editor to write, compile and run your Java code online



class Main {

    

    public static void findPermutation(String str, String ans) {

        // base case

        if(str.length() == 0) {

            System.out.println(ans);

            return;

        }

        // recursion t.c: o(n*n)

        for(int i=0; i<str.length(); i++) { // until i to string length

            char curr = str.charAt(i); // Current char

            // "abcde" = "ab" + "de" = "abde"

            String NewStr = str.substring(0, i) + str.substring(i+1);

            findPermutation(NewStr, ans+curr);

        }

    }

    

    public static void main(String[] args) {

        String str = "abc";

        findPermutation(str, " ");

    }

}



OUTPUT: 

 abc

 acb

 bac

 bca

 cab

 cba


Find Subsets (backtracking in Java)

 import java.util.*;


public class Classroom {
    public static void findSubsets(String str, String ans, int i) {
        // base case
        if(i == str.length()) {
            if(ans.length() == 0) {
                System.out.println("null");
            } else {
                System.out.println(ans);
            }
           
            return;
        }

        // recursion
        // Yes choice
        findSubsets(str, ans+str.charAt(i), i+1);
        // No choice
        findSubsets(str, ans, i+1);
    }
   

    public static void main(String[] args) {
        String str = "abc";
        findSubsets(str, " ",  0);
    }
}

Backtracking of Arrays in Java

import java.util.*;

public class Classroom {
    public static void changeArr(int arr[], int i, int val) {
        // base case
        if(i == arr.length) {
            printArr(arr);
            return;
        }

        // recursion
        arr[i] = val;
        changeArr(arr, i+1, val+1);
        arr[i] = arr[i] - 2;

    }

    public static void printArr(int arr[]) {
        for(int i=0; i<arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }
    public static void main(String args[]) {
        int arr[] = new int[5];
        changeArr(arr, 0, 1);
        printArr(arr);
       
    }
}

Sunday, August 3, 2025

Semester 3 - Hardest to Easiest Subjects....

 Here’s the Semester 3 BCA (VGU Online) subjects ranked from hardest → easiest, based on concept depth, coding workload, and exam scoring difficulty:


1️⃣ Hardest

  1. Database Management Systems (DBMS)

    • Requires SQL mastery, ER diagrams, normalization, transactions & recovery.

    • Practical + theoretical; mistakes in queries can cost marks.

  2. Operating Systems (OS)

    • Involves heavy theory (process management, memory, scheduling).

    • Understanding OS concepts conceptually is tricky but coding part is light.


2️⃣ Medium Difficulty

  1. Computer Networks (CN)

    • Mostly theoretical with some numerical (IP addressing, subnetting).

    • Scoring is easier than OS, but memorization is required.

  2. Internet & Web Programming Lab (if taken with EL4)

    • Basic HTML, CSS, JS or PHP-based tasks; easy if you enjoy coding.

    • Slight debugging needed, but practical marks are usually lenient.


3️⃣ Easiest

  1. DBMS Lab

    • Mostly writing and running SQL queries; repeating class examples scores full marks.

  2. Discrete Mathematics (if chosen)

    • Logical and formula‑based; easier if your math is strong.

    • Low coding effort, mainly reasoning.


📊 Ranked Table (Hard → Easy)

Rank Subject Difficulty
1 Database Management Systems (Theory) 🔴 Hard
2 Operating Systems 🔴 Hard
3 Computer Networks 🟡 Medium
4 Internet & Web Programming Lab 🟡 Medium
5 DBMS Lab 🟢 Easy
6 Discrete Mathematics (Elective) 🟢 Easy

If you want, I can also label which subjects are most scoring vs risky for Sem 3 to plan your study focus.
Do you want that?

Monday, July 28, 2025

Enqueue and Dequeue operations in C++ with Full program

#include <iostream>

using namespace std;


#define SIZE 5


class Queue {

private:

    int arr[SIZE];

    int front, rear;


public:

    Queue() {

        front = -1;

        rear = -1;

    }


    void enqueue(int val) {

        if (rear == SIZE - 1) {

            cout << "Queue Overflow" << endl;

            return;

        }

        if (front == -1) front = 0;

        arr[++rear] = val;

    }


    void dequeue() {

        if (front == -1 || front > rear) {

            cout << "Queue Underflow" << endl;

            return;

        }

        cout << "Dequeued: " << arr[front++] << endl;

    }


    void display() {

        if (front == -1 || front > rear) {

            cout << "Queue is empty" << endl;

            return;

        }

        cout << "Queue elements: ";

        for (int i = front; i <= rear; i++) {

            cout << arr[i] << " ";

        }

        cout << endl;

    }

};


int main() {

    Queue q;

    q.enqueue(10);

    q.enqueue(20);

    q.display();

    q.dequeue();

    q.display();

    return 0;

}


Improvement Notes:

Abstraction = expose interface, hide details. That’s why Queue hides the array, front, rear — exposes only methods.

Runtime Polymorphism – Employee and Manager : Salary Based Problem.

 #include <iostream>
using namespace std;

class Employee {
public:
virtual void computeSalary() {
cout << "Employee salary: 500rs" << endl; 
}
};


class Manager : public Employee {
public:
void computeSalary() override {
cout << "Manager Salary: 1500rs" << endl; } };

int main() {
Employee* = emp;
Manager mgr;
emp  = &mgr;

emp->computeSalary(); // Calls Manager's version...

return 0;

}


Necessity of Templates in C++: Examples : Explain?

-> Templates enables generic programming.
-> Allow functions and classes to operate on any data type without code duplication.
-> Promotes code reusability, efficiency, and type safety.
-> Instead of writing separate functions for int, float, double, char, etc,, you can write one generic template.


#Code Example to Find Max:

#include <iostream>

using namespace std;

template<typename T>

T max(T a, T b) {
return (a > b) ? a : b;
}


#How Compiler Generates Code:

When you call max() with specific types, like:

int a = max(3, 5); // T = int
double d = max(3.5, 2.1); // T = double
char c = max('a', 'b'); // T = char

-> The compiler generates a separate versions of max for each data type during compilation(which is called template instantiation). So, it seems like as if you had written separate versions like multiple overloaded versions of the function. 

how to become red on codeforces by Errichto Algorithms | explained simply in a blog

 Yes. I found an available transcript of the video and summarized it simply. The video is “How To Become Red Coder? (codeforces.com)” by Err...