HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →
Live examsInternational live exams are comingTell us which exam you want first. Timed practice papers are open now.See what is coming →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Space Science and Astronomy
  • Earth and Environmental Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Python Programming
  2. /Python Going Further
  3. /Data Structures

Data Structures

Python Programming · High School (11–12) · 1 course, 11 worked problems, 20 practice questions

A data structure is a way of organising data so that a program can use it well. Python's lists and dictionaries are data structures, and others can be built from them. A stack works last in, first out, like a pile of plates: you push onto the top and pop from the top. A queue works first in, first out, like a line at a counter. A linked list joins items by references, and a tree joins them in branches, as in a folder system. A graph joins items in a network, such as friends who know each other.

With practice you will be able to

  • Build a stack and a queue and tell them apart
  • Walk a linked list and a tree in code
  • Choose a suitable data structure for a problem

On the syllabus of

  • CBSE / State Class 12
  • IB
  • A-Level

Lessons

  • Data StructuresHow does undo remember your steps? How does a route finder find the fewest stops?High School (11–12)

Practice questions

Choose an answer, then check it. Each one shows a full explanation.

Push 1, 2 and 3 on a stack, pop once, then push 4. What does the next pop() give?

A queue gets A, B and C in that order. popleft() runs twice. Who is at the front now?

5, 2 and 8 are inserted into an empty binary search tree. Where is 8?

A linked list has 6 nodes. How many next links does a walk from the head follow to reach node 6?

s = [] and s.append(1), s.append(2), s.append(3), then s.pop(). What is s?

from collections import deque, q = deque([1, 2, 3]), then q.popleft(). What is list(q)?

A stack holds [1, 2, 3] with 3 on top. What does the loop while s: print(s.pop()) show?

A queue of A, B, C: A is served, then D joins. Who is served next?

A linked list has the nodes 1, 2, 3. A node X is pushed at the front. What is the list in order?

Values 4, 2, 6 are inserted in that order into an empty binary search tree. What does the in-order walk give?

All 20 practice questions on Data Structures →

Worked problems

Each one has a hint, the key idea and a full worked solution.

  • Use a stack to write a function reverse_words(sentence) that reverses the order of the words of a…Easy
  • Customers arrive and are served one at a time, each needing some minutes: Asha 4, Ravi 2, Meera 6…Medium
  • For each job, say whether a stack or a queue fits, and why…Easy
  • A chain of nodes holds 3, 1, 4, 1, 5, built as in the lesson…Easy
  • A chain holds 1, 2, 3, 4. Show, by following the links, what remove(head, 1) and remove(head, 3)…Medium
  • Write a function that finds the value of the middle node of a chain in one pass, without counting…Hard
  • Insert the values 50, 30, 70, 20, 40, 60, 80, 30 into an empty binary search tree, in that order…Easy
  • What is the height of the tree made by inserting 5, 3, 8, 1, 4, 7, 9 in that order, and of the one…Medium
  • From the dictionary of friends in the lesson, write a function that gives the person with the most…Easy
  • In the friends graph below, find by breadth-first search, on paper, the shortest path from Kabir to…Medium
  • A network has the links A to B, B to C, D to E, and F alone…Medium

Python labs

  • Stack tools
  • Linked list
  • Binary search tree
  • Reachable places
  • Project: finding the way

Related topics

  • Python Going Further
  • Classes and Objects
  • Inheritance and Special Methods
  • Files and Data Formats
  • Comprehensions, Iterators and Generators
  • Testing and Debugging