SlideShare a Scribd company logo
Data
Structures
AND ALGORITHMS
Data Structures is about how data can be stored in different structures.
Algorithms is about how to solve different problems, often by searching through
and manipulating data structures.
Theory about Data Structures and Algorithms (DSA) helps us to use large
amounts of data to solve problems efficiently.
Data Structures
We structure data in different ways depending on what data we
have, and what we want to do with it.
If we want to store data about people we are related to, we use
a family tree as the data structure. We choose a family tree as
the data structure because we have information about people
we are related to and how they are related, and we want an
overview so that we can easily find a specific family member,
several generations back.
With such a family tree data structure, it is easy to see, for
example, who my mother's mother is—it is 'Emma,' right? But
without the links from child to parents that this data structure
provides, it would be difficult to determine how the individuals
are related.
Data structures give us the possibility to manage large amounts
of data efficiently for uses such as large databases and internet
indexing services.
Data structures are essential ingredients in creating fast and
powerful algorithms. They help in managing and organizing
data, reduce complexity, and increase efficiency.
Two different kinds of data
structures.
Primitive Data Structures are basic data structures provided
by programming languages to represent single values, such as
integers, floating-point numbers, characters, and booleans.
Abstract Data Structures are higher-level data structures that
are built using primitive data types and provide more complex
and specialized operations. Some common examples of abstract
data structures include arrays, linked lists, stacks, queues,
trees, and graphs.
L1-Introduction for Computer Science.pptx
What are Algorithms?
An algorithm is a set of step-by-step instructions to solve a
given problem or achieve a specific goal.
A cooking recipe written on a piece of paper is an example of an
algorithm, where the goal is to make a certain dinner. The steps
needed to make a specific dinner are described exactly.
When we talk about algorithms in Computer Science, the step-
by-step instructions are written in a programming language,
and instead of food ingredients, an algorithm uses data
structures.
Algorithm – is a step-by-step
process
Algorithms are fundamental to computer programming as they
provide step-by-step instructions for executing tasks. An
efficient algorithm can help us to find the solution we are
looking for, and to transform a slow program into a faster one.
By studying algorithms, developers can write better programs.
Algorithm examples:
1. Finding the fastest route in a GPS navigation system
2. Navigating an airplane or a car (cruise control)
3. Finding what users search for (search engine)
4. Sorting, for example sorting movies by rating
The algorithms are designed to solve specific problems, and are
often made to work on specific data structures. For example,
the 'Bubble Sort' algorithm is designed to sort values, and is
made to work on arrays.
Data Structures together with
Algorithms
Data structures and algorithms (DSA) go hand in hand. A data
structure is not worth much if you cannot search through it or
manipulate it efficiently using algorithms, and the algorithms in
this tutorial are not worth much without a data structure to
work on.
Data Structures together with
Algorithms
DSA is about finding efficient ways to store and retrieve data, to
perform operations on data, and to solve specific problems.
By understanding DSA, you can:
•Decide which data structure or algorithm is best for a given
situation.
•Make programs that run faster or use less memory.
•Understand how to approach complex problems and solve them
in a systematic way.
Where is Data Structures and
Algorithms Needed?
Data Structures and Algorithms (DSA) are used in virtually every software system,
from operating systems to web applications:
•For managing large amounts of data, such as in a social network or a search engine.
•For scheduling tasks, to decide which task a computer should do first.
•For planning routes, like in a GPS system to find the shortest path from A to B.
•For optimizing processes, such as arranging tasks so they can be completed as
quickly as possible.
•For solving complex problems: From finding the best way to pack a truck to making a
computer 'learn' from data.
DSA is fundamental in nearly
every part of the software world:
•Operating Systems
•Database Systems
•Web Applications
•Machine Learning
•Video Games
•Cryptographic Systems
•Data Analysis
•Search Engines
Theory and Terminology
L1-Introduction for Computer Science.pptx
Algorithm Example
Fibonacci Numbers
The Fibonacci numbers are very useful for introducing algorithms.
The Fibonacci numbers are named after a 13th century Italian mathematician
known as Fibonacci.
The two first Fibonacci numbers are 0 and 1, and the next Fibonacci number is
always the sum of the two previous numbers, so we get 0, 1, 1, 2, 3, 5, 8, 13,
21, ...
L1-Introduction for Computer Science.pptx
The Fibonacci Number Algorithm
To generate a Fibonacci number, it must add the two previous Fibonacci numbers.
How it works:
1.Start with the two first Fibonacci numbers 0 and 1.
a. Add the two previous numbers together to create a new Fibonacci number.
b. Update the value of the two previous numbers.
2.Do point a and b above 18 times (if there are 20 numbers for the Fibonacci
numbers).
Loops vs Recursion
1. Implementation Using a For Loop
It can be a good idea to list what the code must contain or do before
programming it:
• Two variables to hold the previous two Fibonacci numbers
• A for loop that runs 18 times
• Create new Fibonacci numbers by adding the two previous ones
• Print the new Fibonacci number
• Update the variables that hold the previous two fibonacci numbers
Python
prev2 = 0
prev1 = 1
print(prev2)
print(prev1)
for fibo in range(18):
newFibo = prev1 + prev2
print(newFibo)
prev2 = prev1
prev1 = newFibo
C
#include <stdio.h>
int main() {
int prev2 = 0, prev1 = 1;
int newFibo;
printf("%dn", prev2);
printf("%dn", prev1);
for(int fibo = 0; fibo < 18; fibo++) {
newFibo = prev1 + prev2;
printf("%dn", newFibo);
prev2 = prev1;
prev1 = newFibo;
}
return 0;
Java
public class Main {
public static void main(String[] args) {
int prev2 = 0;
int prev1 = 1;
System.out.println(prev2);
System.out.println(prev1);
for(int fibo = 0; fibo < 18; fibo++) {
int newFibo = prev1 + prev2;
System.out.println(newFibo);
prev2 = prev1;
prev1 = newFibo;
}
}
}
Implementation Using Recursion
Recursion is when a function calls itself.
To implement the Fibonacci algorithm, replace the for loop with recursion.
To replace the for loop with recursion, we need to encapsulate much of the code
in a function, and we need the function to call itself to create a new Fibonacci
number as long as the produced number of Fibonacci numbers is below, or equal
to, 19.
Python
print(0)
print(1)
count = 2
def fibonacci(prev1, prev2):
global count
if count <= 19:
newFibo = prev1 + prev2
print(newFibo)
prev2 = prev1
prev1 = newFibo
count += 1
fibonacci(prev1, prev2)
else:
return
fibonacci(1,0)
C
#include <stdio.h>
int count = 2;
void fibonacci(int prev1, int prev2) {
if (count <= 19) {
int newFibo = prev1 + prev2;
printf("%dn", newFibo);
prev2 = prev1;
prev1 = newFibo;
count += 1;
fibonacci(prev1, prev2);
} else {
return;
}
}
int main() {
printf("0n");
printf("1n");
fibonacci(1, 0);
return 0;
}
Java
public class Main {
static int count = 2;
public static void fibonacci(int prev1, int prev2) {
if (count <= 19) {
int newFibo = prev1 + prev2;
System.out.println(newFibo);
prev2 = prev1;
prev1 = newFibo;
count += 1;
fibonacci(prev1, prev2);
} else {
return;
}
}
public static void main(String[] args) {
System.out.println(0);
System.out.println(1);
fibonacci(1, 0);
}
}
Finding The nth Fibonacci Number
Using Recursion
L1-Introduction for Computer Science.pptx
Python
def F(n):
if n <= 1:
return n
else:
return F(n - 1) + F(n - 2)
print(F(19))
C
#include <stdio.h>
int F(int n) {
if (n <= 1) {
return n;
} else {
return F(n - 1) + F(n - 2);
}
}
int main() {
printf("%dn", F(19));
return 0;
}
Java
public class Main {
public static int F(int n) {
if (n <= 1) {
return n;
} else {
return F(n - 1) + F(n - 2);
}
}
public static void main(String[] args) {
System.out.println(F(19));
}
}
Analysis
Notice that this recursive method calls itself two times, not just one. This makes
a huge difference in how the program will actually run on our computer. The
number of calculations will explode when we increase the number of the
Fibonacci number we want. To be more precise, the number of function calls will
double every time we increase the Fibonacci number we want by one.
Function call for F(5)
Thank you

More Related Content

PPT
Lec1
PPTX
RAJAT PROJECT.pptx
PPT
Data Structures and Algorithm Analysis
PPS
Data Structure
PPS
Lec 1 Ds
PPS
Lec 1 Ds
PPT
Lecture#1(Algorithmic Notations).ppt
Lec1
RAJAT PROJECT.pptx
Data Structures and Algorithm Analysis
Data Structure
Lec 1 Ds
Lec 1 Ds
Lecture#1(Algorithmic Notations).ppt

Similar to L1-Introduction for Computer Science.pptx (20)

PPTX
Chapter 1 - Introduction to data structure.pptx
PDF
A gentle introduction to algorithm complexity analysis
PPT
computer notes - Data Structures - 1
DOCX
3rd-Sem_CSE_Data-Structures and Applications.docx
DOCX
Data structure and algorithm.
PDF
Data structure and Alogorithm analysis unit one
PPTX
Introduction to Artificial Intelligence...pptx
PDF
DATA STRUCTURE AND ALGORITHM FULL NOTES
PDF
computer notes - Introduction to data structures
PPTX
Unit 1 -Introduction to Data Science.pptx
PDF
Chapter 1 Introduction to Data Structures and Algorithms.pdf
PDF
Zoho Interview Questions By Scholarhat.pdf
PPT
Data structures cs301 power point slides lecture 01
PPTX
data structure and algoriythm pres.pptxD
PPTX
datastructuresandalgorithm-module1-230307012644-4c895c84.pptx
DOCX
PPTX
End-to-End Machine Learning Project
PDF
IRJET- Machine Learning: Survey, Types and Challenges
DOC
e computer notes - Introduction to data structures
Chapter 1 - Introduction to data structure.pptx
A gentle introduction to algorithm complexity analysis
computer notes - Data Structures - 1
3rd-Sem_CSE_Data-Structures and Applications.docx
Data structure and algorithm.
Data structure and Alogorithm analysis unit one
Introduction to Artificial Intelligence...pptx
DATA STRUCTURE AND ALGORITHM FULL NOTES
computer notes - Introduction to data structures
Unit 1 -Introduction to Data Science.pptx
Chapter 1 Introduction to Data Structures and Algorithms.pdf
Zoho Interview Questions By Scholarhat.pdf
Data structures cs301 power point slides lecture 01
data structure and algoriythm pres.pptxD
datastructuresandalgorithm-module1-230307012644-4c895c84.pptx
End-to-End Machine Learning Project
IRJET- Machine Learning: Survey, Types and Challenges
e computer notes - Introduction to data structures
Ad

Recently uploaded (20)

PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
 
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Yogi Goddess Pres Conference Studio Updates
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PDF
Computing-Curriculum for Schools in Ghana
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
UNIT III MENTAL HEALTH NURSING ASSESSMENT
Anesthesia in Laparoscopic Surgery in India
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Supply Chain Operations Speaking Notes -ICLT Program
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Chinmaya Tiranga quiz Grand Finale.pdf
Weekly quiz Compilation Jan -July 25.pdf
Complications of Minimal Access Surgery at WLH
202450812 BayCHI UCSC-SV 20250812 v17.pptx
 
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Orientation - ARALprogram of Deped to the Parents.pptx
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Microbial diseases, their pathogenesis and prophylaxis
Yogi Goddess Pres Conference Studio Updates
LDMMIA Reiki Yoga Finals Review Spring Summer
Computing-Curriculum for Schools in Ghana
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Ad

L1-Introduction for Computer Science.pptx

  • 2. Data Structures is about how data can be stored in different structures. Algorithms is about how to solve different problems, often by searching through and manipulating data structures. Theory about Data Structures and Algorithms (DSA) helps us to use large amounts of data to solve problems efficiently.
  • 4. We structure data in different ways depending on what data we have, and what we want to do with it. If we want to store data about people we are related to, we use a family tree as the data structure. We choose a family tree as the data structure because we have information about people we are related to and how they are related, and we want an overview so that we can easily find a specific family member, several generations back.
  • 5. With such a family tree data structure, it is easy to see, for example, who my mother's mother is—it is 'Emma,' right? But without the links from child to parents that this data structure provides, it would be difficult to determine how the individuals are related.
  • 6. Data structures give us the possibility to manage large amounts of data efficiently for uses such as large databases and internet indexing services. Data structures are essential ingredients in creating fast and powerful algorithms. They help in managing and organizing data, reduce complexity, and increase efficiency.
  • 7. Two different kinds of data structures. Primitive Data Structures are basic data structures provided by programming languages to represent single values, such as integers, floating-point numbers, characters, and booleans. Abstract Data Structures are higher-level data structures that are built using primitive data types and provide more complex and specialized operations. Some common examples of abstract data structures include arrays, linked lists, stacks, queues, trees, and graphs.
  • 9. What are Algorithms? An algorithm is a set of step-by-step instructions to solve a given problem or achieve a specific goal. A cooking recipe written on a piece of paper is an example of an algorithm, where the goal is to make a certain dinner. The steps needed to make a specific dinner are described exactly. When we talk about algorithms in Computer Science, the step- by-step instructions are written in a programming language, and instead of food ingredients, an algorithm uses data structures.
  • 10. Algorithm – is a step-by-step process
  • 11. Algorithms are fundamental to computer programming as they provide step-by-step instructions for executing tasks. An efficient algorithm can help us to find the solution we are looking for, and to transform a slow program into a faster one. By studying algorithms, developers can write better programs.
  • 12. Algorithm examples: 1. Finding the fastest route in a GPS navigation system 2. Navigating an airplane or a car (cruise control) 3. Finding what users search for (search engine) 4. Sorting, for example sorting movies by rating
  • 13. The algorithms are designed to solve specific problems, and are often made to work on specific data structures. For example, the 'Bubble Sort' algorithm is designed to sort values, and is made to work on arrays.
  • 14. Data Structures together with Algorithms Data structures and algorithms (DSA) go hand in hand. A data structure is not worth much if you cannot search through it or manipulate it efficiently using algorithms, and the algorithms in this tutorial are not worth much without a data structure to work on.
  • 15. Data Structures together with Algorithms DSA is about finding efficient ways to store and retrieve data, to perform operations on data, and to solve specific problems. By understanding DSA, you can: •Decide which data structure or algorithm is best for a given situation. •Make programs that run faster or use less memory. •Understand how to approach complex problems and solve them in a systematic way.
  • 16. Where is Data Structures and Algorithms Needed? Data Structures and Algorithms (DSA) are used in virtually every software system, from operating systems to web applications: •For managing large amounts of data, such as in a social network or a search engine. •For scheduling tasks, to decide which task a computer should do first. •For planning routes, like in a GPS system to find the shortest path from A to B. •For optimizing processes, such as arranging tasks so they can be completed as quickly as possible. •For solving complex problems: From finding the best way to pack a truck to making a computer 'learn' from data.
  • 17. DSA is fundamental in nearly every part of the software world: •Operating Systems •Database Systems •Web Applications •Machine Learning •Video Games •Cryptographic Systems •Data Analysis •Search Engines
  • 20. Algorithm Example Fibonacci Numbers The Fibonacci numbers are very useful for introducing algorithms. The Fibonacci numbers are named after a 13th century Italian mathematician known as Fibonacci. The two first Fibonacci numbers are 0 and 1, and the next Fibonacci number is always the sum of the two previous numbers, so we get 0, 1, 1, 2, 3, 5, 8, 13, 21, ...
  • 22. The Fibonacci Number Algorithm To generate a Fibonacci number, it must add the two previous Fibonacci numbers. How it works: 1.Start with the two first Fibonacci numbers 0 and 1. a. Add the two previous numbers together to create a new Fibonacci number. b. Update the value of the two previous numbers. 2.Do point a and b above 18 times (if there are 20 numbers for the Fibonacci numbers).
  • 23. Loops vs Recursion 1. Implementation Using a For Loop It can be a good idea to list what the code must contain or do before programming it: • Two variables to hold the previous two Fibonacci numbers • A for loop that runs 18 times • Create new Fibonacci numbers by adding the two previous ones • Print the new Fibonacci number • Update the variables that hold the previous two fibonacci numbers
  • 24. Python prev2 = 0 prev1 = 1 print(prev2) print(prev1) for fibo in range(18): newFibo = prev1 + prev2 print(newFibo) prev2 = prev1 prev1 = newFibo
  • 25. C #include <stdio.h> int main() { int prev2 = 0, prev1 = 1; int newFibo; printf("%dn", prev2); printf("%dn", prev1); for(int fibo = 0; fibo < 18; fibo++) { newFibo = prev1 + prev2; printf("%dn", newFibo); prev2 = prev1; prev1 = newFibo; } return 0;
  • 26. Java public class Main { public static void main(String[] args) { int prev2 = 0; int prev1 = 1; System.out.println(prev2); System.out.println(prev1); for(int fibo = 0; fibo < 18; fibo++) { int newFibo = prev1 + prev2; System.out.println(newFibo); prev2 = prev1; prev1 = newFibo; } } }
  • 27. Implementation Using Recursion Recursion is when a function calls itself. To implement the Fibonacci algorithm, replace the for loop with recursion. To replace the for loop with recursion, we need to encapsulate much of the code in a function, and we need the function to call itself to create a new Fibonacci number as long as the produced number of Fibonacci numbers is below, or equal to, 19.
  • 28. Python print(0) print(1) count = 2 def fibonacci(prev1, prev2): global count if count <= 19: newFibo = prev1 + prev2 print(newFibo) prev2 = prev1 prev1 = newFibo count += 1 fibonacci(prev1, prev2) else: return fibonacci(1,0)
  • 29. C #include <stdio.h> int count = 2; void fibonacci(int prev1, int prev2) { if (count <= 19) { int newFibo = prev1 + prev2; printf("%dn", newFibo); prev2 = prev1; prev1 = newFibo; count += 1; fibonacci(prev1, prev2); } else { return; } } int main() { printf("0n"); printf("1n"); fibonacci(1, 0); return 0; }
  • 30. Java public class Main { static int count = 2; public static void fibonacci(int prev1, int prev2) { if (count <= 19) { int newFibo = prev1 + prev2; System.out.println(newFibo); prev2 = prev1; prev1 = newFibo; count += 1; fibonacci(prev1, prev2); } else { return; } } public static void main(String[] args) { System.out.println(0); System.out.println(1); fibonacci(1, 0); } }
  • 31. Finding The nth Fibonacci Number Using Recursion
  • 33. Python def F(n): if n <= 1: return n else: return F(n - 1) + F(n - 2) print(F(19))
  • 34. C #include <stdio.h> int F(int n) { if (n <= 1) { return n; } else { return F(n - 1) + F(n - 2); } } int main() { printf("%dn", F(19)); return 0; }
  • 35. Java public class Main { public static int F(int n) { if (n <= 1) { return n; } else { return F(n - 1) + F(n - 2); } } public static void main(String[] args) { System.out.println(F(19)); } }
  • 36. Analysis Notice that this recursive method calls itself two times, not just one. This makes a huge difference in how the program will actually run on our computer. The number of calculations will explode when we increase the number of the Fibonacci number we want. To be more precise, the number of function calls will double every time we increase the Fibonacci number we want by one.