← TCS questions

Write Python code to implement neural network backpropagation

Filed under TCS

Free read 3 of 3

Compute weighted sums and apply activation functions (e.g., Sigmoid) to get predictions.

The question

Implement the backpropagation algorithm for a simple neural network in Python.

Constraints

  • Use standard Python libraries only
  • Implement forward pass and gradient calculation
  • Assume a simple 2-layer network

Approach

  1. Compute weighted sums and apply activation functions (e.g., Sigmoid) to get predictions.

Tips

  • What they are testing: Verify gradients against numerical differentiation.
  • Common mistake: Forgetting the chain rule or incorrectly applying the derivative of the activation function.

Related TCS questions

Collected from public candidate posts and coding forums. Updated Nov 2026.