







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Complete Data Structures study notes for BCA 3rd Semester students at Tribhuvan University (TU), Nepal. Topics covered: - Introduction to Data Structures & ADT - Arrays (operations, types, complexity) - Linked Lists (singly, doubly, circular) - Stacks (LIFO, applications, expressions) - Queues (FIFO, circular queue, types) - Trees & Binary Search Tree (BST) - Sorting Algorithms (Bubble, Merge, Quick) - Searching Algorithms (Linear, Binary) Features: - Visual diagrams for every topic - Color-coded chapters - Time complexity tables - Important exam questions with answers - Easy to understand language Perfect for exam preparation and last-minute revision! Academic Year: 2025/2026
Typology: Study notes
1 / 13
This page cannot be seen from the preview
Don't miss anything!








BCA 3rd Semester · Tribhuvan University · Nepal
n 8 Chapters n Visual Diagrams n Exam Q&A n Color-coded n Complete Syllabus
n TIP: These notes cover the complete BCA 3rd Semester Data Structures syllabus with visual diagrams, examples, and exa
n Table of Contents
n EXAM: Always aim for O(1) or O(log n) algorithms. O(n²) is fine for small data but terrible for large inputs!
n Chapter 2: Arrays n DEF: An Array is a collection of elements of the same data type stored in CONTIGUOUS memory locations, accessed usin Index: 0 1 2 3 4 5 6 Value: 10 25 8 42 17 33 5 n Each box = one memory cell | Index starts at 0 | Access any element in O(1)!
Array Operations & Time Complexity Operation Time Complexity Reason Access (read/write) O(1) n FAST Direct index calculation Search (unsorted) O(n) Must check each element Insert at end O(1) No shifting needed Insert at beginning O(n) n SLOW Must shift all elements right Delete from end O(1) Just reduce size Delete from middle O(n) n SLOW Must shift elements left Traversal O(n) Visit every element once n EXAM: Arrays are BEST when: you know the size in advance & need fast random access. Use Linked Lists when: frequent
n Chapter 4: Stacks n DEF: A Stack is a linear data structure following LIFO — Last In, First Out. Think of a stack of plates: you can only add/rem
<-- BOTTOM
Operation Action Time push(x) Add x to top O(1) pop() Remove top O(1) peek() View top O(1) isEmpty() Check empty O(1) isFull() Check full O(1)
Applications of Stack
n
Infix / Prefix / Postfix Expressions Type Operator Position Example Evaluation Infix Between operands A + B * C Use rules of precedence Prefix Before operands + A * B C Right to left scan Postfix After operands A B C * + Left to right with stack n EXAM: Infix to Postfix conversion using Stack is a VERY common exam question. Practice tracing it step by step!
n Chapter 5: Queues n DEF: A Queue follows FIFO — First In, First Out. Think of a ticket counter line: first person in line is served first.
Visual Diagram: Queue
10 25 8 42 17 FRONT REAR
DEQ ENQ
Queue Operations Operation Description Where Time enqueue(x) Add element x At REAR end O(1) dequeue() Remove element From FRONT end O(1) front() View front element At FRONT O(1) isEmpty() Check if empty Whole queue O(1) isFull() Check if full Whole queue O(1)
Types of Queues Type Key Feature Problem Solved Simple Queue Basic FIFO Basic ordering Circular Queue Rear wraps around to front Solves wasted space in linear queue Deque Insert/delete from both ends Flexible: acts as both stack and queue Priority Queue Highest priority served first CPU scheduling, Dijkstra algorithm
Stack vs Queue — Know the Difference! Feature n Stack n Queue Principle LIFO — Last In First Out FIFO — First In First Out Insert push() — at TOP enqueue() — at REAR Delete pop() — from TOP dequeue() — from FRONT Pointers One: top Two: front & rear Real-life Stack of plates Bank/ticket queue Use case Expression eval, DFS CPU scheduling, BFS n EXAM: Stack vs Queue difference is asked in EVERY exam. Memorize: Stack=LIFO, Queue=FIFO. One uses top pointer,
Operation Average Case Worst Case When worst happens Insert O(log n) O(n) Inserting sorted data (e.g., 1,2,3,4,5) Delete O(log n) O(n) Same — skewed tree
n Chapter 7: Sorting Algorithms n DEF: Sorting = arranging elements in order (ascending/descending). Different algorithms have very different speeds — cho
Bubble Sort — Step by Step Visual Original: 64 34 25 12 22 Pass 1: 34 25 12 22 64 Pass 2: 25 12 22 34 64 Sorted: 12 22 25 34 64 Bubble Sort: Compare adjacent pairs, swap if wrong order. Largest element "bubbles up" to end each pass. All Sorting Algorithms Comparison Algorithm Best Average Worst Space Stable? Method Bubble Sort O(n) O(n²) O(n²) O(1) YES Comparison Selection Sort O(n²) O(n²) O(n²) O(1) NO Comparison Insertion Sort O(n) O(n²) O(n²) O(1) YES Comparison Merge Sort O(n log n) O(n log n) O(n log n) O(n) YES Divide & Conquer Quick Sort O(n log n) O(n log n) O(n²) O(log n) NO Divide & Conquer Heap Sort O(n log n) O(n log n) O(n log n) O(1) NO Heap-based
Which Algorithm to Use? Situation Best Choice Why Small data (n < 20) Insertion Sort Fast in practice, simple code General purpose Quick Sort Best average case, in-place Need guaranteed O(n log n) Merge Sort Always O(n log n), stable Nearly sorted data Insertion Sort Near O(n) for almost-sorted Memory is limited Heap Sort O(1) extra space n EXAM: Know TIME COMPLEXITY of all 6 sorting algorithms by heart — this appears in EVERY exam. Also: Merge Sort alw
n Important Exam Questions & Answers
Ans: A Data Structure is a way of organizing and storing data so it can be accessed and modified efficiently. It is importa
Ans: LIFO (Last In First Out): The last inserted element is the first to be removed. Used by STACK. FIFO (First In First O
Ans: 1. Memory: Array=contiguous, Linked List=non-contiguous. 2. Size: Array=fixed, Linked List=dynamic. 3. Access: A
Ans: Tree traversal = visiting each node exactly once. For BST with root=50, left=30, right=70: Inorder (LNR): 20,30,40,
Ans: A Circular Queue connects the last position back to the first (rear = (rear+1) % size). Problem with linear queue: Aft
Ans: Bubble Sort: Best=O(n), Average=O(n²), Worst=O(n²), Space=O(1), Stable=Yes. Simple but slow for large data. Me
Ans: Binary Search finds an element in a sorted array by repeatedly dividing the search space in half. Algorithm: (1) Find
Ans: Abstract Data Type (ADT) = defines data + operations WITHOUT specifying implementation. Example 1 — Stack A
n Best of Luck in Your Exams! | Study Hard, Score High! n