0% found this document useful (0 votes)
13 views50 pages

1 Intro To DSA - CS2B

The document provides an introduction to data structures and algorithms, outlining their importance in computer programming for organizing, processing, and storing data efficiently. It covers various types of data structures, operations performed on them, and the mathematical functions related to algorithms. Additionally, it discusses the problem-solving process in programming and the significance of algorithms as a method for solving structured problems.

Uploaded by

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

1 Intro To DSA - CS2B

The document provides an introduction to data structures and algorithms, outlining their importance in computer programming for organizing, processing, and storing data efficiently. It covers various types of data structures, operations performed on them, and the mathematical functions related to algorithms. Additionally, it discusses the problem-solving process in programming and the significance of algorithms as a method for solving structured problems.

Uploaded by

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

Introduction to Data

Structures and Algorithms


Maribel T. Tacla
Join My Class
What is your mood today?

A. Happy B. Sad C. Sleepy D. Bored


Multiple Choice Submissions

Details can be found in the Notes section below


Content
• Data Structure (Introduction, Types, Operations)
• Problems, Programs, Algorithms
• Mathematical Functions
• Floor
• Ceiling
• Modulo
Introduction to Data Structures
• Computer is an electronic machine which is used for data
processing and manipulation
• When programmer collects such type of data for processing, he
would require to store all of them in computers main memory
• In order to make how computer work we need to know
• Representation of data in computer
• Accessing of data
• How to solve problem step by step

• For doing all of these tasks we used Data Structure!


 A data structure is a
specialized format for
organizing, processing,
retrieving and storing
data
 In computer
programming
 a data structure
may be selected or
designed to store
data for the
purpose of working
on it with various
algorithms
 The group of data elements which provides an efficient way
of storing and organizing data in the computer so that it can
be used efficiently
 Examples: Arrays, Linked List, Stack, Queue, Graph, Trees
 Used in almost every aspect of Computer Science
 Operating System
 Compiler Design
 Artificial Intelligence
 Graphics and many more
 The main part of many computer science algorithms as they
enable the programmers to handle the data in an efficient way
 It plays a vital role in enhancing the performance of a
software or a program as the main function of the software is
to store and retrieve the user’s data as fast as possible
 The representation of particular DS in the main memory of a
computer

 The storage structure representation in auxiliary memory


1. Primitive Data Structures
2. Non-primitive Data Structures

• 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.

 Function - a matching between inputs (domain) and the


outputs (range).
input - a single value or a collection of information
Algorithm
 A method or a process followed to solve a problem.
 A list of instructions for carrying out some process step by
step.
 A method for solving a well-structured problem.
 A recipe for solving a problem whose steps are concrete and
unambiguous.
 A finite set of instructions that specify a sequence of
operations to be carried out.
Algorithm cont.
• It is written in order.
• It is the core logic (solution) of a problem.
• An algorithm is not a program.
• It has two types: pseudocode and flowchart.
What is pseudocode?
Short Answer Submissions (all)

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

Renon, Welsley V. A language that helps programmers create algorithm.

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.

Honeylette Yagin it is expressed by words formally


Short Answer Submissions (all)

Israel Batoon used as a detailed step in the process of developing a program

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

 NOTE: Data Structures and Algorithms are the building


blocks of computer programs
Mathematical Functions
Floor Function
• gets the greatest value that is less than or equal to the specified
number
• Floor of x ( ⎣ x ⎦ ) is x, where x is any real number

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 ⎦ if and only if x is an integer


Prove that

⎡ x ⎤ = ⎣ x ⎦ + 1 if and only if x is not an integer


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.

You might also like