SlideShare a Scribd company logo
PRELIMINARIES
NURJAHAN NIPA
LECTURER, DEPT OF ICT, BDU
Lecture Outlines
■ Mathematical Notation
■ Algorithm Complexity ofAlgorithms
■ Control Structures
■ Sieve Method (Cross Out Algorithm)
■ Largest Element Algorithm.
■ Linear SearchAlgorithm.
Floor & Ceiling Functions
■ The floor of x denotes the greatest integer that does not exceed x.
■ The ceiling of x denotes the least integer that is not less than x.
x Floor Ceiling
3.14 3 4
√5 2 3
-8.5 -9 -8
7 7 7
-18 -18 -18
π 3 4
3
30 3 4
log2 100 6 7
Integer & Absolute value Function
Value Integer Function AbsoluteValue
Function
3.14 INT(3.14)=3 |3.14|=3.14
-15 INT(-15)=-15 |-15|=15
7 INT(7)=7 |7|=7
-8.5 INT(-8.5)=-8 |-8.5|=8.5
√5 INT(√5)=2 |√5|=2.236
Exponent & Logarithms
■ How many 2s do we multiply to get 8?
Answer: 2 × 2 × 2 = 8, so we had to multiply 3 of the 2 s to get 8
So, log2 8=3 since 23
.
So these two things are the same:
Exponent & Logarithms
■ Exponents and Logarithms are related, let's find out how ...
Control Structures
Algorithms and their equivalent computer programs are more easily understood if they
mainly use self contained modules and three types of logic or flow of control-
 Sequence Logic or Sequential Flow
 Selection Logic or Conditional Flow
 Iteration Logic or Repetitive Flow
Sequence Logic or Sequential Flow
■ Sequential logic as the name suggests follows a serial or sequential flow in which the
flow depends on the series of instructions given to the computer. Unless new
instructions are given, the modules are executed in the obvious sequence.
■ Sequential execution of code statements (one line after another) -- like following a
recipe
Selection Logic or Conditional Flow
Selection Logic simply involves a number of conditions or parameters which decides one out of several
written modules.The structures which use these type of logic are known as Conditional Structures.
This logic is used for decisions, branching -- choosing between 2 or more alternative paths. In C, these
are the types of selection statements:
 if
 if/else
 Switch
These structures can be of three types:
 Single Alternative
 Double Alternative
 Multiple Alternative
Single Alternative:
This structure has the form----
If (condition) then:
[Module A]
[End of If structure]
if(condition)
{
// Statements to execute if condition is
true
}
// C program to illustrate If statement
#include <stdio.h>
int main()
{
int i = 10;
if (i > 15) {
printf("10 is greater than 15 n");
}
printf("I am Not in if");
}
// C program to illustrate If statement
#include <stdio.h>
int main()
{
int i = 10;
if (i < 15) {
printf("10 is less than 15 n");
}
printf("I am Not in if");
}
Double Alternative:
This structure has the form----
If (Condition), then:
[Module A]
Else:
[Module B]
[End if structure]
if (condition){
// Executes this block if condition is true
}
else{
// Executes this block if condition is false
}
// C program to illustrate If else statement
#include <stdio.h>
int main() {
int i = 25;
if (i > 15)
printf("i is greater than 15");
else
printf("i is smaller than 15");
}
// C program to illustrate If else statement
#include <stdio.h>
int main()
{
int i = 20;
if (i == 10)
printf("i is 10");
else
printf("i is 20");
printf("Outside if-else block");
}
If (condition A), then:
[Module A]
Else if (condition B), then:
[Module B]
..
..
Else if (condition N), then:
[Module N]
[End If structure]]
if (condition)
statement 1;
else if (condition)
statement 2;
.
.
else
statement;
■ This structure has the form----
Multiple Alternative:
#include<stdio.h>
int main()
{
char ch;
printf("Enter any character: ");
scanf("%c",&ch);
switch(ch)
{
case 'A' ... 'Z':
printf("%c is alphabetn", ch);
break;
case 'a' ... 'z':
printf("%c is alphabetn",ch);
break;
case '0' ... '9':
printf("%c is digitn",ch);
break;
default:
printf("%c is special charactern",ch);
}
}
#include <stdio.h>
int main()
{
char ch;
printf("Enter any character: ");
scanf("%c", &ch);
if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
printf("%c is alphabetn", ch);
}
else if(ch >= '0' && ch <= '9')
{
printf("%c is digitn", ch);
}
else
{
printf("%c is special charactern", ch);
}
}
Iteration Logic or Repetitive Flow
Generally used for looping, i.e. repeating a piece of code multiple times in a row.The Iteration
logic employs a loop which involves a repeat statement followed by a module known as the
body of a loop.
In C, there are three types of loops:
■ while
■ do/while
■ for
Repeat While Loop
Repeat while condition:
[Module]
[End of Loop]
//Infinite loop
while (true) {
print("Hello,World!") }
Or
while (1) { print("Hello,World!") }
#include <stdio.h>
int main()
{
int i = 1;
while (i < 6) {
printf("HelloWorldn");
i++;
}
}
#include <stdio.h>
int main()
{
int i = 0;
for (i = 1; i <= 5; i++) {
printf("HelloWorldn");
}
}
Repeat for i = A to N by I:
[Module]
[End of loop]
Repeat For Loop
//Infinite loop
#include<stdio.h>
int main()
{
for( ; ; )
printf("Hello world.t");
}
// infinite do...while loop
int count = 1;
do {
// body of loop
}
while(count == 1);
Repeat Do/While Loop
#include <stdio.h>
int main()
{
int x;
x = 0;
do {
printf( "Hello, world!n" );
} while ( x != 0 );
}
Largest Element in an Array
Algorithm 2.1: (Largest element in an array) A nonempty array DATA with N numerical values is
given.The algorithm finds the location LOC and the value MAX of the largest element of DATA.
The variable K is used as a counter.
Step-1: [Initialize] SET K:=1, LOC:=1 and MAX:=DATA[1];
Step-2: [Increment Counter] Set K:=K+1
Step-3: [Test Counter] if K>N then
Write: LOC, MAX, EXIT
Step-4: [Compare and Update] If MAX<DATA[K], then:
Set LOC:=K and MAX:=DATA[K]
Step-5: [Repeat Loop]Go to step 2.
Largest Element in an Array(Using RepeatWhile
Loop)
■ Algorithm 2.3: (Largest element in an array using repeat while) A nonempty array DATA with N
numerical values is given. The algorithm finds the location LOC and the value MAX of the largest
element of DATA.The variable K is used as a counter.
Step-1: [Initialize] SET K:=1, LOC:=1 and MAX:=DATA[1];
Step-2: Repeat steps 3 and 4 while k<=N
Step-3: [Compare and Update] If MAX<DATA[K], then:
Set LOC:=K and MAX:=DATA[K]
[End of If structure]
Step-4: Set K:=K+1
[End of step 2 loop]
Step-5:Write: LOC, MAX
Step-6: EXIT
Searching
Searching is the process of finding some particular element in the list. If the element is present in
the list, then the process is called successful and the process returns the location of that element,
otherwise the search is called unsuccessful.
There are two popular search methods –
 Linear Search
 Binary Search
 Linear search is the simplest search algorithm and often called sequential search. In this type of
searching, we simply traverse the list completely and match each element of the list with the
item whose location is to be found. If the match found then location of the item is returned
otherwise the algorithm return NULL.
 Linear search is mostly used to search an unordered list in which the items are not sorted.
■ Find the number 13 in the given list.
■ You just look at the list and there it is!
■ A computer cannot look at more than the value at a given instant of time. So it takes one item
from the array and checks if it is the same as what you are looking for.
■ The first item did not match. So move onto the next one.
■ And so on.This is done till a match is found or until all the items have been checked.
Linear Search
■ Algorithm 2.4: A linear array DATA
with N elements and a specific ITEM of
information are given.The algorithm
finds the location LOC of ITEM in an
array DATA or sets LOC=0.
1. [Initialize] Set K:=1 and LOC:=0
2. Repeat steps 3 and 4 while LOC=0 and K<=N
3. If ITEM= DATA[K], then: Set LOC:=K
4. Set K:=K+1.[Increments counter]
[End of Step 2 loop]
5. [Successful?]
If LOC=0, then
Write: Item is not in the array DATA.
Else:
Write: LOC is the location of ITEM.
[End of If structure]
6. Exit
Finding Prime number using Sieve
Method
1. [Initialize array A] Repeat for k=1 to N:
Set A[K]:=K
2. [Eliminate multiples of K] Repeat for K=2 to √N
Call CROSSOUT(A,N,K)
3. [Print the primes] Repeat for K=2 to N
IfA[K]≠1 then:WRITE:A[K]
4. Exit
CROSSOUT(A,N,K)
1. If A[K]=1, then Return.
2. Repeat for L=2K to N by K:
Set A[L]:=1
[End of Loop]
3. Return.
Explanation with Example:
Let us take an example when n = 50. So we need to print all prime numbers smaller than or equal to 50.
We create a list of all numbers from 2 to 50.
According to the algorithm we will mark all the numbers which are divisible by 2 and are greater than or equal
to the square of it.
Explanation with Example:
Now we move to our next unmarked number 3 and mark all the numbers which are multiples of 3 and are
greater than or equal to the square of it.
We move to our next unmarked number 5 and mark all multiples of 5 and are greater than or equal to the
square of it.
We continue this process and our final table will look like below:
So the prime numbers are the unmarked ones: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47.
THANKYOU!

More Related Content

What's hot

Arrays
ArraysArrays
Operating System Operations ppt.pptx
Operating System Operations ppt.pptxOperating System Operations ppt.pptx
Operating System Operations ppt.pptx
MSivani
 
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHIBCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
Sowmya Jyothi
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal language
Rabia Khalid
 
Nested Queries Lecture
Nested Queries LectureNested Queries Lecture
Nested Queries Lecture
Felipe Costa
 
Stack data structure
Stack data structureStack data structure
Stack data structureTech_MX
 
Sql queries presentation
Sql queries presentationSql queries presentation
Sql queries presentation
NITISH KUMAR
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra ppt
GirdharRatne
 
Data structure ppt
Data structure pptData structure ppt
Data structure ppt
Prof. Dr. K. Adisesha
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
Ch2: Computer System Structure (OS)
Ch2: Computer System Structure (OS)Ch2: Computer System Structure (OS)
Ch2: Computer System Structure (OS)
Ahmar Hashmi
 
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
Ritwik Das
 
Database language
Database languageDatabase language
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION
OPERATING SYSTEMSDESIGN AND IMPLEMENTATIONOPERATING SYSTEMSDESIGN AND IMPLEMENTATION
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION
sathish sak
 
Stack project
Stack projectStack project
Stack project
Amr Aboelgood
 
Java package
Java packageJava package
Java package
CS_GDRCST
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite Automata
Ratnakar Mikkili
 
Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)
swapnac12
 

What's hot (20)

Arrays
ArraysArrays
Arrays
 
Operating System Operations ppt.pptx
Operating System Operations ppt.pptxOperating System Operations ppt.pptx
Operating System Operations ppt.pptx
 
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHIBCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
 
Theory of automata and formal language
Theory of automata and formal languageTheory of automata and formal language
Theory of automata and formal language
 
Nested Queries Lecture
Nested Queries LectureNested Queries Lecture
Nested Queries Lecture
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Sql queries presentation
Sql queries presentationSql queries presentation
Sql queries presentation
 
trigger dbms
trigger dbmstrigger dbms
trigger dbms
 
Trigger
TriggerTrigger
Trigger
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra ppt
 
Data structure ppt
Data structure pptData structure ppt
Data structure ppt
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Ch2: Computer System Structure (OS)
Ch2: Computer System Structure (OS)Ch2: Computer System Structure (OS)
Ch2: Computer System Structure (OS)
 
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
 
Database language
Database languageDatabase language
Database language
 
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION
OPERATING SYSTEMSDESIGN AND IMPLEMENTATIONOPERATING SYSTEMSDESIGN AND IMPLEMENTATION
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION
 
Stack project
Stack projectStack project
Stack project
 
Java package
Java packageJava package
Java package
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite Automata
 
Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)
 

Similar to Lecture 02: Preliminaries of Data structure

CP PPT_Unit IV computer programming in c.pdf
CP PPT_Unit IV computer programming in c.pdfCP PPT_Unit IV computer programming in c.pdf
CP PPT_Unit IV computer programming in c.pdf
saneshgamerz
 
Csci101 lect03 algorithms_i
Csci101 lect03 algorithms_iCsci101 lect03 algorithms_i
Csci101 lect03 algorithms_i
Elsayed Hemayed
 
Data structures arrays
Data structures   arraysData structures   arrays
Data structures arrays
maamir farooq
 
Data structure using c module 1
Data structure using c module 1Data structure using c module 1
Data structure using c module 1
smruti sarangi
 
Array 31.8.2020 updated
Array 31.8.2020 updatedArray 31.8.2020 updated
Array 31.8.2020 updated
vrgokila
 
data structure and algorithm Array.pptx btech 2nd year
data structure and algorithm  Array.pptx btech 2nd yeardata structure and algorithm  Array.pptx btech 2nd year
data structure and algorithm Array.pptx btech 2nd year
palhimanshi999
 
Classical programming interview questions
Classical programming interview questionsClassical programming interview questions
Classical programming interview questions
Gradeup
 
Visual Programing basic lectures 7.pptx
Visual Programing basic lectures  7.pptxVisual Programing basic lectures  7.pptx
Visual Programing basic lectures 7.pptx
Mrhaider4
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
pppepito86
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
raghav415187
 
Array assignment
Array assignmentArray assignment
Array assignment
Ahmad Kamal
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
Rakotoarison Louis Frederick
 
Advance data structure & algorithm
Advance data structure & algorithmAdvance data structure & algorithm
Advance data structure & algorithm
K Hari Shankar
 
The what over the how (another way on android development with kotlin)
The what over the how (another way on android development with kotlin)The what over the how (another way on android development with kotlin)
The what over the how (another way on android development with kotlin)
Jose Manuel Pereira Garcia
 
Insersion & Bubble Sort in Algoritm
Insersion & Bubble Sort in AlgoritmInsersion & Bubble Sort in Algoritm
Insersion & Bubble Sort in Algoritm
Ehsan Ehrari
 
10. Recursion
10. Recursion10. Recursion
10. Recursion
Intro C# Book
 
ARRAY in python and c with examples .pptx
ARRAY  in python and c with examples .pptxARRAY  in python and c with examples .pptx
ARRAY in python and c with examples .pptx
abhishekmaurya102515
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
pinakspatel
 

Similar to Lecture 02: Preliminaries of Data structure (20)

CP PPT_Unit IV computer programming in c.pdf
CP PPT_Unit IV computer programming in c.pdfCP PPT_Unit IV computer programming in c.pdf
CP PPT_Unit IV computer programming in c.pdf
 
Csci101 lect03 algorithms_i
Csci101 lect03 algorithms_iCsci101 lect03 algorithms_i
Csci101 lect03 algorithms_i
 
Data structures arrays
Data structures   arraysData structures   arrays
Data structures arrays
 
Data structure using c module 1
Data structure using c module 1Data structure using c module 1
Data structure using c module 1
 
Array 31.8.2020 updated
Array 31.8.2020 updatedArray 31.8.2020 updated
Array 31.8.2020 updated
 
data structure and algorithm Array.pptx btech 2nd year
data structure and algorithm  Array.pptx btech 2nd yeardata structure and algorithm  Array.pptx btech 2nd year
data structure and algorithm Array.pptx btech 2nd year
 
Classical programming interview questions
Classical programming interview questionsClassical programming interview questions
Classical programming interview questions
 
Visual Programing basic lectures 7.pptx
Visual Programing basic lectures  7.pptxVisual Programing basic lectures  7.pptx
Visual Programing basic lectures 7.pptx
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
 
9 Arrays
9 Arrays9 Arrays
9 Arrays
 
Array assignment
Array assignmentArray assignment
Array assignment
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
Advance data structure & algorithm
Advance data structure & algorithmAdvance data structure & algorithm
Advance data structure & algorithm
 
The what over the how (another way on android development with kotlin)
The what over the how (another way on android development with kotlin)The what over the how (another way on android development with kotlin)
The what over the how (another way on android development with kotlin)
 
Insersion & Bubble Sort in Algoritm
Insersion & Bubble Sort in AlgoritmInsersion & Bubble Sort in Algoritm
Insersion & Bubble Sort in Algoritm
 
10. Recursion
10. Recursion10. Recursion
10. Recursion
 
Matlab1
Matlab1Matlab1
Matlab1
 
ARRAY in python and c with examples .pptx
ARRAY  in python and c with examples .pptxARRAY  in python and c with examples .pptx
ARRAY in python and c with examples .pptx
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
 

Recently uploaded

Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
ssuser7dcef0
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
aqil azizi
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
ChristineTorrepenida1
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 

Recently uploaded (20)

Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 

Lecture 02: Preliminaries of Data structure

  • 2. Lecture Outlines ■ Mathematical Notation ■ Algorithm Complexity ofAlgorithms ■ Control Structures ■ Sieve Method (Cross Out Algorithm) ■ Largest Element Algorithm. ■ Linear SearchAlgorithm.
  • 3. Floor & Ceiling Functions ■ The floor of x denotes the greatest integer that does not exceed x. ■ The ceiling of x denotes the least integer that is not less than x. x Floor Ceiling 3.14 3 4 √5 2 3 -8.5 -9 -8 7 7 7 -18 -18 -18 π 3 4 3 30 3 4 log2 100 6 7
  • 4. Integer & Absolute value Function Value Integer Function AbsoluteValue Function 3.14 INT(3.14)=3 |3.14|=3.14 -15 INT(-15)=-15 |-15|=15 7 INT(7)=7 |7|=7 -8.5 INT(-8.5)=-8 |-8.5|=8.5 √5 INT(√5)=2 |√5|=2.236
  • 5. Exponent & Logarithms ■ How many 2s do we multiply to get 8? Answer: 2 × 2 × 2 = 8, so we had to multiply 3 of the 2 s to get 8 So, log2 8=3 since 23 . So these two things are the same:
  • 6. Exponent & Logarithms ■ Exponents and Logarithms are related, let's find out how ...
  • 7.
  • 8. Control Structures Algorithms and their equivalent computer programs are more easily understood if they mainly use self contained modules and three types of logic or flow of control-  Sequence Logic or Sequential Flow  Selection Logic or Conditional Flow  Iteration Logic or Repetitive Flow
  • 9. Sequence Logic or Sequential Flow ■ Sequential logic as the name suggests follows a serial or sequential flow in which the flow depends on the series of instructions given to the computer. Unless new instructions are given, the modules are executed in the obvious sequence. ■ Sequential execution of code statements (one line after another) -- like following a recipe
  • 10. Selection Logic or Conditional Flow Selection Logic simply involves a number of conditions or parameters which decides one out of several written modules.The structures which use these type of logic are known as Conditional Structures. This logic is used for decisions, branching -- choosing between 2 or more alternative paths. In C, these are the types of selection statements:  if  if/else  Switch These structures can be of three types:  Single Alternative  Double Alternative  Multiple Alternative
  • 11. Single Alternative: This structure has the form---- If (condition) then: [Module A] [End of If structure] if(condition) { // Statements to execute if condition is true } // C program to illustrate If statement #include <stdio.h> int main() { int i = 10; if (i > 15) { printf("10 is greater than 15 n"); } printf("I am Not in if"); } // C program to illustrate If statement #include <stdio.h> int main() { int i = 10; if (i < 15) { printf("10 is less than 15 n"); } printf("I am Not in if"); }
  • 12. Double Alternative: This structure has the form---- If (Condition), then: [Module A] Else: [Module B] [End if structure] if (condition){ // Executes this block if condition is true } else{ // Executes this block if condition is false } // C program to illustrate If else statement #include <stdio.h> int main() { int i = 25; if (i > 15) printf("i is greater than 15"); else printf("i is smaller than 15"); } // C program to illustrate If else statement #include <stdio.h> int main() { int i = 20; if (i == 10) printf("i is 10"); else printf("i is 20"); printf("Outside if-else block"); }
  • 13. If (condition A), then: [Module A] Else if (condition B), then: [Module B] .. .. Else if (condition N), then: [Module N] [End If structure]] if (condition) statement 1; else if (condition) statement 2; . . else statement; ■ This structure has the form---- Multiple Alternative:
  • 14. #include<stdio.h> int main() { char ch; printf("Enter any character: "); scanf("%c",&ch); switch(ch) { case 'A' ... 'Z': printf("%c is alphabetn", ch); break; case 'a' ... 'z': printf("%c is alphabetn",ch); break; case '0' ... '9': printf("%c is digitn",ch); break; default: printf("%c is special charactern",ch); } } #include <stdio.h> int main() { char ch; printf("Enter any character: "); scanf("%c", &ch); if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) { printf("%c is alphabetn", ch); } else if(ch >= '0' && ch <= '9') { printf("%c is digitn", ch); } else { printf("%c is special charactern", ch); } }
  • 15. Iteration Logic or Repetitive Flow Generally used for looping, i.e. repeating a piece of code multiple times in a row.The Iteration logic employs a loop which involves a repeat statement followed by a module known as the body of a loop. In C, there are three types of loops: ■ while ■ do/while ■ for
  • 16. Repeat While Loop Repeat while condition: [Module] [End of Loop] //Infinite loop while (true) { print("Hello,World!") } Or while (1) { print("Hello,World!") } #include <stdio.h> int main() { int i = 1; while (i < 6) { printf("HelloWorldn"); i++; } }
  • 17. #include <stdio.h> int main() { int i = 0; for (i = 1; i <= 5; i++) { printf("HelloWorldn"); } } Repeat for i = A to N by I: [Module] [End of loop] Repeat For Loop //Infinite loop #include<stdio.h> int main() { for( ; ; ) printf("Hello world.t"); }
  • 18. // infinite do...while loop int count = 1; do { // body of loop } while(count == 1); Repeat Do/While Loop #include <stdio.h> int main() { int x; x = 0; do { printf( "Hello, world!n" ); } while ( x != 0 ); }
  • 19. Largest Element in an Array Algorithm 2.1: (Largest element in an array) A nonempty array DATA with N numerical values is given.The algorithm finds the location LOC and the value MAX of the largest element of DATA. The variable K is used as a counter. Step-1: [Initialize] SET K:=1, LOC:=1 and MAX:=DATA[1]; Step-2: [Increment Counter] Set K:=K+1 Step-3: [Test Counter] if K>N then Write: LOC, MAX, EXIT Step-4: [Compare and Update] If MAX<DATA[K], then: Set LOC:=K and MAX:=DATA[K] Step-5: [Repeat Loop]Go to step 2.
  • 20.
  • 21.
  • 22. Largest Element in an Array(Using RepeatWhile Loop) ■ Algorithm 2.3: (Largest element in an array using repeat while) A nonempty array DATA with N numerical values is given. The algorithm finds the location LOC and the value MAX of the largest element of DATA.The variable K is used as a counter. Step-1: [Initialize] SET K:=1, LOC:=1 and MAX:=DATA[1]; Step-2: Repeat steps 3 and 4 while k<=N Step-3: [Compare and Update] If MAX<DATA[K], then: Set LOC:=K and MAX:=DATA[K] [End of If structure] Step-4: Set K:=K+1 [End of step 2 loop] Step-5:Write: LOC, MAX Step-6: EXIT
  • 23. Searching Searching is the process of finding some particular element in the list. If the element is present in the list, then the process is called successful and the process returns the location of that element, otherwise the search is called unsuccessful. There are two popular search methods –  Linear Search  Binary Search  Linear search is the simplest search algorithm and often called sequential search. In this type of searching, we simply traverse the list completely and match each element of the list with the item whose location is to be found. If the match found then location of the item is returned otherwise the algorithm return NULL.  Linear search is mostly used to search an unordered list in which the items are not sorted.
  • 24. ■ Find the number 13 in the given list. ■ You just look at the list and there it is! ■ A computer cannot look at more than the value at a given instant of time. So it takes one item from the array and checks if it is the same as what you are looking for. ■ The first item did not match. So move onto the next one. ■ And so on.This is done till a match is found or until all the items have been checked.
  • 25. Linear Search ■ Algorithm 2.4: A linear array DATA with N elements and a specific ITEM of information are given.The algorithm finds the location LOC of ITEM in an array DATA or sets LOC=0. 1. [Initialize] Set K:=1 and LOC:=0 2. Repeat steps 3 and 4 while LOC=0 and K<=N 3. If ITEM= DATA[K], then: Set LOC:=K 4. Set K:=K+1.[Increments counter] [End of Step 2 loop] 5. [Successful?] If LOC=0, then Write: Item is not in the array DATA. Else: Write: LOC is the location of ITEM. [End of If structure] 6. Exit
  • 26. Finding Prime number using Sieve Method 1. [Initialize array A] Repeat for k=1 to N: Set A[K]:=K 2. [Eliminate multiples of K] Repeat for K=2 to √N Call CROSSOUT(A,N,K) 3. [Print the primes] Repeat for K=2 to N IfA[K]≠1 then:WRITE:A[K] 4. Exit CROSSOUT(A,N,K) 1. If A[K]=1, then Return. 2. Repeat for L=2K to N by K: Set A[L]:=1 [End of Loop] 3. Return.
  • 27. Explanation with Example: Let us take an example when n = 50. So we need to print all prime numbers smaller than or equal to 50. We create a list of all numbers from 2 to 50. According to the algorithm we will mark all the numbers which are divisible by 2 and are greater than or equal to the square of it.
  • 28. Explanation with Example: Now we move to our next unmarked number 3 and mark all the numbers which are multiples of 3 and are greater than or equal to the square of it. We move to our next unmarked number 5 and mark all multiples of 5 and are greater than or equal to the square of it.
  • 29. We continue this process and our final table will look like below: So the prime numbers are the unmarked ones: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47.

Editor's Notes

  1. Question 1:--- Assume 10,000 contestants participated in a programming contest. A person will be selected as winner from the competition. In each round, 10% contestants will be go to the next round. Then, how many rounds are needed to find out the winner. Question 2:---Assume 1024 contestants participated in a IOT system presentation contest. In each round, Number of contestants are decreasing in this format: 1024, 512, 256, 128…Then after how many round we can get the winner.
  2. URI Online Judge | 1038, 1052,
  3. https://www.freecodecamp.org/news/linear-search/