Introduction
Introduction
STRUCTURES
AND
ALGORITHMS
Hafiz Ahsan Arshad
Course Introduction
■ Course Outline.
■ Evaluation Scheme.
Quizzes 10%
Assignments 20%
Project 15%
Mid Term 25%
Final Term 40%
■ Rules:
– Raise your hand before asking any question and then WAIT for
the permission.
– Never ever miss a class.
– Never ever “sleep” in the class.
– Never use mobile phones in the class.
What is Data?
Point to Ponder:
The choice of efficient data structure makes the
difference between a program running in a few
seconds or many days
What is Data Structure
Efficiency?
■ A solution is said to be efficient if it solves the problem within its
resource constraints.
– Space
– Time
■ The cost of a solution is the amount of resources that the solution
consumes.
– Each data structure has costs and benefits.
■ It is very difficult to find a data structure that is better than others in all
situations.
■ A data structure requires:
– space for each data item it stores.
– time to perform each basic operation.
– programming effort.
Why are Data Structures
Important?
■ Efficient Data Handling:
– Data structures are designed to optimize data access and manipulation.
■ Memory Management:
– Data structures help manage memory effectively.
– They can allocate and deallocate memory dynamically, reducing memory wastage and
fragmentation.
– This is especially crucial in systems with limited memory resources.
■ Algorithm Efficiency:
– Many algorithms require specific data structures to operate efficiently.
– Choosing the right data structure can significantly impact the performance of an
algorithm.
■ Complex Problem Solving:
– Data structures allow for the representation and manipulation of complex data in a
structured way.
– They are essential for solving complex problems like databases, network routing, and
artificial intelligence.
Real-Life Examples:
■ Phone Contacts:
– May use Array, Link-list, BST or combination of Data Structures.
■ Social Media Applications:
– Combination of Data Structures like Queue, Graph etc.
■ Online Shopping Cart:
– Combination of Data Structures like Array, Link-list, Queue, Graph
etc.
■ GPS Navigation:
– May use Graph or combination of Data Structures.
Types of Data Structures
Primitive Data Structures
■ In linear data
structures, data elements are organized in a
sequential manner, where each element has a unique
predecessor and successor, except for the first and last elements.
■ Accessing elements in linear data structures is straightforward, as you
can traverse from one element to the next in a linear fashion.
■ Examples:
– Arrays
– linked lists
– queues.
– Stacks
Non-Linear Data Structures