DS Lecture 1
DS Lecture 1
Lecture 1
What is Data?
Introduction
What
Problem, are data&type?
Questions Objectives
What is an algorithm
Data
• A collection of raw facts from which a conclusion may be drawn.
• A collection of letters, symbols, numbers, and text (unorganized,
unprocessed data)
• Example:
o Temperature is 35 degrees Celsius
o Conclusion: It is HOT!
Types of data:
Textual: for example >> Your name (Muhammad)
Numeric: for example >> Your id (090254)
Audio: for example >> Your voice
Dr. Taghreed Abdullah
What are Data Types? 4
Data Types:
Built-in construct of any programming language to manipulate
“basic types of data”
Basic Types of Data:
Character
Integer
Real or Floating point number
Example (Data Type): Short, int, long, char, double etc ;
Dr. Taghreed Abdullah
What are Data Structures? 5
Data Structure:
• A particular way of storing and organizing data in a computer so
that it can be used efficiently
• It is a group of data elements stored together under one name
• It is also referred as “Abstract Data Type (ADT)”
• Example:
• An array of integers
int examGrades[30];
Dr. Taghreed Abdullah
Data Structures 6
• Design Issue:
The challenge is to select the most appropriate data structure for the problem
• Such is one of the motivations for this course
Arrays
Linked List
Stacks Trees
Queues
Graph
• Traversing
• Accessing/visiting each data element exactly once so that
certain items in the data may be processed
• Searching
• Finding the location of a given data element (key) in the
structure
• Insertion:
• Adding a new data element to the structure
• Deletion
• Removing a data element from the structure
• Sorting
• Arrange the data elements in some logical fashion
• ascending or descending
• Merging
• Combining data elements form two or more data
structures into one
Primitive Data structures are directly supported by the language ie; any
operation is directly performed in these data items.
Ex: integer, Character, Real numbers etc.
Non-primitive data types are not defined by the programming language, but
are instead created by the programmer.
Based on Representation
• Linear representation data structures
• Arrays
• Linked lists
• Stack
• Queues
• Non-linear representation data structures
• Trees
• Graphs
Dr. Taghreed Abdullah
What is an Algorithm 16
1. Algorithms are necessary for solving complex problems efficiently and effectively.
2. They help to automate processes and make them more reliable, faster, and easier
to perform.
3. Algorithms also enable computers to perform tasks that would be difficult or
impossible for humans to do manually.
4. They are used in various fields such as mathematics, computer science,
engineering, finance, and many others to optimize processes, analyze data, make
predictions, and provide solutions to problems.
Dr. Taghreed Abdullah
18
2 Order
Algorithm Representation:
1. Flowchart:
Flowchart uses graphical elements to Visually depict that flow of logic within a
program
Flowcharts are employed to find solutions for small problems.
2. Pseudo Code:
Pseudo-code provides a way of expressing algorithms in a way that is independent of
any programming language.
It abstracts away other program details such as the type system and declaring
variables and arrays.
Pseudo code
1. Start
Flowchart 2. Read n
3. Result = n mod 2
4. If Result =0
Print n is even
else
Print n is odd
5. end
Pseudo code
1. Start
2. Initialize sum=0 and
count=0
Flowchart
3. Read n
4. Find sum + n and assign
it to sum and then
increment count by 1
5. If count < 5
Go to step 3
else
Print sum
6. end
• Time Complexity: The amount of time required for an algorithm to complete its
execution is called time complexity. An algorithm is said to be efficient if it takes the
minimum (reasonable) amount of time to complete its execution.
1. D.S. Malik, (2010). "Data Structures Using C++", 2nd Edition (or
Higher), USA, Course Technology, Cengage Learning.
2. D.S. Malik, (2018). " C++ programing: program design including Data
Structures" 8th Edition, USA, Course Technology, Cengage Learning