Solve 8-Puzzle Problem with Python and A* Search
Write a Program to Implement 8-Puzzle problem using Python
import heapq
from termcolor import colored
# Class to represent the state of the 8-puzzle
class PuzzleState:
def __init__(self, board, parent, move, depth, cost):
self.Board = board # The puzzle board configuration
self.Parent = parent # Parent state
self.Move = move # Move to reach this state
self.Depth = depth # Depth in the search tree
self.Cost = cost # Cost (depth + heuristic)
Algorithm Complexity and Data Structure Fundamentals Q&A
1. What is recurrence for worst case of QuickSort and what is the time complexity in Worst case?
Recurrence is T(n) = T(n-1) + O(n) and time complexity is O(n^2)
2. Suppose we have a O(n)
time algorithm that finds median of an unsorted array. Now consider a QuickSort implementation where we first find median using the above algorithm, then use median as pivot. What will be the worst case time complexity of this modified QuickSort.
O(nLogn)
3. Given an unsorted array. The array has this property
Read MoreSignals, Systems, and 5G Network Fundamentals
Signal Transformation for Continuous-Time Signals
Q1 (a) — Explain the signal transformation needed for transforming the independent variable for continuous-time signals.
Signal transformation changes the independent variable (usually time) to modify or analyze signals. Common transformations include:
- Time shifting: Shifts the signal by a time constant t₀.
- Time scaling: Compresses the signal (if a > 1) or expands it (if a < 1).
- Time reversal: Flips the signal around the vertical axis.
These
Read MoreEssential Data Structures and Algorithms Reference: DSA Core Concepts
Lesson 2: Object-Oriented Programming and Linked Lists
OOP Fundamentals
- Class: The blueprint for creating objects. Object: An instance of a class.
- Attribute: A variable stored within an object. Method: A function defined within a class.
- The
selfkeyword refers to the object instance.__init__is the constructor method.
OOP Example (Python)
class Car:
def __init__(self, make, model, year):
self.make = make; self.model = model; self.year = year
def info(self):
return f"{self.year} Read More
Fundamental C Algorithms: Search, Sort, Recursion, and Optimization
Fundamental C Algorithms: Search, Sort, and Optimization
This document presents implementations of several core algorithms in C, including searching, sorting, recursion, and optimization techniques like the Traveling Salesman Problem (TSP) and the Fractional Knapsack problem.
1. Linear Search Algorithm
Linear search is a straightforward method for finding an element within a list. It sequentially checks each element until a match is found or the entire list has been traversed.
C Code for Linear Search
#
Understanding Recurrent Neural Networks and Their Applications
🧠 Recurrent Neural Network (RNN)
A neural network for sequential data (time series, speech, text).
It has memory of past inputs to affect current output.
Simple: “RNN past data yaad rakh kar next output predict karta hai.”
x1 → x2 → x3 → ...
↓ ↓ ↓
h1 → h2 → h3 →
...
↓ ↓ ↓
y1 y2 y3
Stepwise:
1️⃣ Input – Sequential data (text/audio)
2️⃣ Hidden Layer – Current input + previous hidden state
Eq: hₜ = f(Wxₜ + Uhₜ₋₁ + b)
3️⃣
