0% found this document useful (0 votes)
46 views20 pages

Lecture 1 - Intro

The document discusses an agenda for a course on data structures and algorithms. The agenda includes introductions to data organization, common data structures and their operations, algorithms, complexity analysis, and asymptotic notations. It provides examples of using data structures to manage student data for a university, including fields like student IDs, courses, and grades. It asks students to determine data types and fields for uniquely identifying and aggregating student records.

Uploaded by

Owais Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views20 pages

Lecture 1 - Intro

The document discusses an agenda for a course on data structures and algorithms. The agenda includes introductions to data organization, common data structures and their operations, algorithms, complexity analysis, and asymptotic notations. It provides examples of using data structures to manage student data for a university, including fields like student IDs, courses, and grades. It asks students to determine data types and fields for uniquely identifying and aggregating student records.

Uploaded by

Owais Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

DATA STRUCTURES AND

ALGORITHMS (113215)

D r. O w a i s H u s s a i n
AGENDA
I n t r o d u c ti o n

D a t a o r g a n i z a ti o n

Data structures and their


o p e r a ti o n s

Algorithms

Space and Time complexity

A s y m p t o ti c n o t a ti o n s

Real life example

2
Introduction
SAMPLE 2

 Understanding data structures is the heart of all data keeping strategies in


digital and real world.

 Data structures can help you in managing your TODO lists.

 Data structures can also help you win battles, like the battle of Talafgar in
1805.

 In fact, they can help you win wars, like Alan Turing’s cracking of Enigma
code.
Data Organization
SAMPLE 2

 Real story of NADRA’s first database.


 What would you have done if you were in charge?
 We organize data for:
 Easy access
 Maintain integrity
 Faster reporting
 Scalability
 Sharing
 Security
Data Structures and their Operations
SAMPLE 2

 Data structure (Data + Structure) is simply a logical or mathematical


arrangement used to keep data. For example, in a library the books can be
organized in many structures:
 Random: any book can be found anywhere.
 Sorted: all books are arranged by their title
 Grouped: books are kept in sections, but within sections they are put randomly.
 Grouped and sorted: books are kept in sections, and in each section, they are
sorted by their titles.
 Similarly, in computer memory, we can keep data in different structures.
Data Structures and their Operations
SAMPLE 2

 The most frequent operations we perform in any data structure are:


 Insert: add new data to existing collection.
 Remove: remove an existing data point from the collection.
 Search/Find/Retrieve: find a data point in a collection.
 Get size: count the number of data points in a collection.
 Split: divide a collection into two or more subsets.
 Merge: combine multiple collections into a superset.
 Sort: rearrange a collection in ascending or descending order.
 This sound much same as the operations we generally perform in a database system.
That’s because each database is a data structure.
Data Structures and their Operations
SAMPLE 2

 There are some advanced operations performed in a data structure:


 Sort: arrange all the data by some value
 Append (or Add After): insert data at the end of collection.
 Prepend (or Add Before): insert data at the start of collection.
 Empty/Clear: remove all data from a collection.
 Update: change the value of an item in the collection.
 Pop: get top value and remove from the collection.
 Search: get one or more elements in a collection that match a criteria.
 Different data structures may use different terms, but the operation remains the
same.
Data Structures and their Operations
SAMPLE 2
Data
 Data Structures can be classified Structures

into Linear and Non-linear. Linear Non-linear

 Linear data structures are


Static Dynamic Tree
arranged sequentially.
 Static: have fixed memory size Arrays Linked List Graph
 Dynamic: have flexible memory
Stack
 Non-linear data structures do not
keep all elements sequentially. Queue
Algorithms
SAMPLE 2

 An algorithm is a way to express logic. It can be in any language and use any
symbols. It can be in plain English as well.
 A set of instructions with a clear meaning that can be performed within a finite
amount of time to solve a problem. It requires an input, a logic to perform some
operations on that input and an output.
 A pseudocode is an algorithm written in formal way using standard symbols.
 A computer program is written in a formal language to represent an algorithm.
Computers are quite inflexible compared to human mind, so programs need to
contain some more details than algorithms.
Algorithms: Example
SAMPLE 2

 Find out whether a year is a leap year or not


Algorithm Pseudocode
1. Input a year
2. Divide it by 4 and 100
3. If the first remainder is
0 and second remainder is
not 0, then the year is
leap. Otherwise not.
Algorithms: Exercise
SAMPLE 2

 Write an algorithm which inputs the number of students in your


class and tells whether they can be separated into 2 equal
groups or not.
 Present this algorithm in Pseudocode form.
 Write a console program to execute this algorithm.
Space and Time Complexity
SAMPLE 2

 Space complexity means how much memory is required to solve a


given problem.
 Space complexity is measured in computer storage units (bytes, etc.)
 Time complexity means how much time is required to solve a given
problem.
 Time complexity is measured usually in seconds/minutes, however
for simplicity, we often use the term “unit of time”.
 Both are used to measure the efficiency of an algorithm. However,
since memory is cheaper, we mainly focus on time complexity.
Asymptotic Notations
SAMPLE 2

 Best case: (Omega)


E.g., we are looking for a student with a calculator and the first student has it. It tells us the
least number of possible operations needed at least.
 Average case: (Theta)
E.g., if in a class of 10 students, only one has a calculator, then we’ll have to ask 5
students on average.
 Worst case: (Big-O)
This is the most used notation and tells us the worst-case scenario. E.g., we keep asking
students for a calculator and the last student has it. It tells us the upper bound of an
algorithm.
Real life Example
SAMPLE 2

 All examples covered in this course will be related to the following scenario:

The College of Computing and Information Sciences offers courses in all 3 campuses of
KIET. The students from various programs including CS and SE are identified by a unique
SID. Their courses have unique codes and credit hours. Each student has a grade sheet
containing his/her records of courses enrolled in and marks acquired, which aggregate to
define their grades and a Cumulative GPA.

Our objective is to design a system to manage the students’ information, which can
insert, delete, search and present their data in an efficient manner.
Real life Example
SAMPLE 2

Now that you have the example, answer the following:

1. What will be the data fields for this system?

2. What will be the data types for each field?

3. Which of the fields should be used to uniquely identify a


student?

4. Which fields should be used for aggregate operations?


Exercise
SAMPLE 2

 An algorithm inputs CGPA of students in your class. Suppose that


the algorithm take 1ms to compare two numbers, then what will
be the worst time complexity of this algorithm if we ask it to find
out highest CGPA in your class?
Exercise
SAMPLE 2

 Let’s say there are 5 students in the class; there will be following possibilities:
 Highest CGPA is 4.0 and this student is sitting in first bench. In this case the time
will be 1ms, because 4.0 is highest possible value. Therefore, the time
complexity will be 1ms.
 Highest CGPA is 4.0, but this student is on the last bench. Now, we must
compare each student’s CGPA. Therefore, the time complexity will be 5ms.
 The highest CGPA is 4.0, but this student is on 3 rd bench. Therefore, the time
complexity will be 3ms.
 The highest CGPA is 3.8, and this student is on 1 st bench. We must still compare
all other students’ CGPA. Therefore, the time complexity will be 5ms.
 After considering all cases, we see that the worst scenario is .
Assignment 1
SAMPLE 2

 Write an algorithm and its pseudocode to measure the average


number of credit hours you have earned per semester.
 Assuming each statement in your program takes 2ms to execute,
what will be the best, average and worst time complexity?
 Submit your solution on LMS.
Pre-requisites Reading
SAMPLE 2

Refer to Chapter 2 of your Textbook (Theory and Problems of Data


Structures by S. Lipschutz) and revise:
 Floor and Ceiling function
 Modulus function
 Round and Absolute functions
 Factorial
 Permutation and combination functions
 Flow charts and algorithmic notations
THANK YOU

Owais Hussain +92 345-3174270 [email protected]

h tt p s : / / w w w . r e s e a r c h g a t e . n e t / p r o fi l e / O w a i s - H u s s a i n - 3

You might also like