Backtracking Algorithms (OCR A-Level Computer Science): Flashcards

📚Flashcards
Backtracking Algorithms
Sign up to keep revising.Create a free account to study more flashcards and track your progress.

Practise the cards

15 cards from this deck

Show

Backtracking definition

Technique to systematically search solutions; abandons invalid paths to try alternatives

Main use cases of backtracking

Decision trees, combinatorial optimisation, constraint satisfaction

What happens when constraint violated in backtracking

Abandons path and tries different one

First step in backtracking

Choose a path/start with initial partial solution

Action after checking constraints

Expand if valid, backtrack if invalid

N-Queens problem

Place NN queens on N×NN \times N board, none threaten each other

Benefit: systematic search

Explores all possibilities in organised manner

Benefit: pruning invalid paths

Quickly eliminates paths not meeting constraints

Benefit: implementation

Simple to implement using recursion

Drawback for large problems

Inefficient, may explore many possibilities

Worst case time complexity

O(2n)O(2^n) for certain problems

Mistake: not restoring state

Leads to incorrect solutions

Mistake: incorrect base case

Causes infinite recursion

Problems suited for backtracking

Combinatorial and constraint satisfaction problems

Drawback: recursive overhead

Can lead to stack overflow for deep recursive calls

Explore OCR A-Level Computer Science Revision Notes by Topics

Explore OCR A-Level Computer Science Model Answers by Topics

Explore OCR A-Level Computer Science Quizzes by Topics

Explore OCR A-Level Computer Science Exam Questions by Topics

Join 100,000+ A-Level students studying Flashcards with us.

Select your subjects, and get access to A+ resources today.