1 Intro To DSA - CS2B
1 Intro To DSA - CS2B
• Non-primitive DS
1. Linear DS
2. Non linear DS
• Data Types
• A particular kind of data item, as defined by the values it
can take, the Programming Language used, or the
operations that can be performed on it
• These are basic structure and directly operated upon by
machine instructions
• They have different representations on different computers
• Examples:
• Integers, floats, character and pointers
• Data Types are available in most programming languages as
built in type
• Integer: It is a data type which allows all values without
fraction part. We can used it for whole numbers.
• Float: It is a data type which is use for storing fraction
numbers.
• Character: It is a data type which is used for character
values.
• Pointer: A variable that hold memory address of another
variable are called pointer.
• These are more sophisticated data structures
• These are derived from primitive data structure
• The non-primitive data structures emphasize structuring of a
group of homogeneous or heterogeneous data items
• Examples: Array, List, and File
• Types: Linear and Non-Linear data structure
• Examples of Linear : Stack, Queue
• Examples of Non-Linear: Tree, Graphs
• Array: An array is a fixed size sequenced collection of
elements of the same data type.
• List: An ordered set containing variable number of elements is
called as List.
• File: A file is a collection of logically related information. It can
be viewed as a large list of records consisting of various
fields.
1. Create: This operation results in reserving memory for
program elements. This can be done by declaration
statement Creation of DS may take place either during
compile-time or run-time.
2. Destroy: This operation destroy memory space allocated for
specified data structure .
3. Selection: This operation deals with accessing a particular
data within a data structure.
4. Updating: It updates or modifies the data in the data
structure.
5. Searching: It finds the presence of desired data item in the
list of data items, it may also find locations of all elements
that satisfy certain conditions.
6. Sorting: This is a process of arranging all data items in a DS in
particular order, for example either ascending order or in
descending order.
7. Splitting: It is a process of partitioning single list to multiple
list.
8. Merging: It is a process of combining data items of two
different sorted list into single sorted list.
9. Traversing: It is a process of visiting each and every node of a
list in systematic manner.
A task to be performed.
Can be viewed as functions in the mathematical sense.
Joshua Angelo for me maam i think pseudocode is some sort of language that can help programmers create or develop
Guzman certain algorithms maam?
Ivan Lucky M.
it is an informal way of a programming description that does not require a syntax.
Aquino
Jared Kiel a code that does not require any strict syntax
Ace Pseudocode is a made-up, informal language that programmers use to create algorithms.
Yves Frank Yabes an artificial, informal language that helps programmers develop algorithms.
Ivan Dominic
a programming description that does not require a syntax or an informal way of writing a program
Hernand
Properties of Algorithm
Finite set of instructions which, if followed, will accomplish a task
Finiteness - an algorithm must terminate after a finite number of
steps
Definiteness - ensured if every step of an algorithm is precisely
defined
Input - domain of the algorithm which could be zero or more
quantities
Output - set of one or more resulting quantities; also called the
range of the algorithm
Effectiveness - ensured if all the operations in the algorithm are
sufficiently basic that they can, in principle, be done exactly and in
finite time by a person using paper and pen
Program
An instance or concrete representation of an algorithm in
some programming language.
A set of instructions for a computer.
Receives data, carry out the instructions, and
Produce useful results.
Problem Solving Process
Programming
– a problem-solving process which could be viewed in terms of the
following domains:
Problem domain
▪ input or the raw data to process
▪ output or the processed data
▪ Ex: sorting of a set of numbers
▪ raw data: set of numbers in the original order
▪ processed data: sorted numbers
Machine domain
▪ storage medium - consists of serially arranged bits that are addressable as a unit
▪ processing unit - allow us to perform basic operations (i.e. arithmetic, comparisons)
Solution domain
links the problem and machine domains
Problem Solving Process
Problem Domain
Problem Solving Process
Machine Domain
Problem Solving Process
Solution Domain
Problem Solving Process
Example: ⎣ 3.14 ⎦ = 3
⎣ 1/2 ⎦ = 0
⎣ -1/2 ⎦ = -1
Ceiling Function
• Ceil (short for ceiling) returns the least value of the integer that is
greater than or equal to the specified number
• Ceiling of x ( ⎡ x ⎤ ) is x, where x is any real number
Example: ⎡ 3.14 ⎤ = 4
⎡ 1/2 ⎤ = 1
⎡ -1/2 ⎤ = 0
Modulo Operation
• finds the remainder after division of one number by another
• sometimes called modulus
• Modulo operator (abbreviated as mod) is the remainder after
dividing a positive number by another positive number
Example: 10 mod 3 = 1
24 mod 8 = 0
-5 mod 7 = ?
Prove the following identities.
Use any value for x, y and z.
1. ⎡ x ⎤ = ⎣ x ⎦ if and only if x is an integer
2. ⎡ x ⎤ = ⎣ x ⎦ + 1 if and only if x is not an integer
3. ⎣ - x ⎦ = - ⎡ x ⎤
Prove that
⎣-x⎦=-⎡x⎤
⎣ 25.32 ⎦
⎣ -52.25 ⎦
⎡ 1/4 ⎤
⎡ -1/8⎤
-1 mod 5
⎣ ⎡7.5⎤ - (8 mod 2)⎦
⎡ ⎡(-2/4)⎤ mod ⎡ (3/-5) ⎤ *⎣ 1/-2⎦⎤
Any question?
References
• Shaffer (2013). Data Structures and Algorithm Analysis.
• Levitin, A. (2012). Introduction to the Design and Analysis of
Algorithms.