Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 18

Data Structure and

Algorithms
Introduction
What are Data Structures?
“In computer science, a data A way of
structure is a data organizing data
organization, management, and so that it can be
storage format that use effectively.
enables efficient access and
modification.” - Wikipedia

2
What is Algorithm?
“In mathematics and computer A process or set
science, an algorithm  is a finite of rules to be
sequence of well-defined, followed in
computer-implementable calculations or
other problem-
instructions, typically to solve a solving
class of problems or to perform a operations,
computation.” - Wikipedia especially by a
computer 3
Array K D

K D

Linked list

4
Data types and
Variables
Data type
“In computer science and  It is the type of
computer programming, a data variable that used.
type or simply type is an
attribute of data which tells the
compiler or interpreter how the
programmer intends to use the
data. ” - Wikipedia
6
Variables
“In computer programming, Variable is where
a variable or scalar is a storage the data
location (identified by a memory temporarily save
address) paired with an
associated symbolic name, which
contains some known or unknown
quantity of information referred to as
a value ” - Wikipedia
7
Data Type Size Description

byte 1 byte Stores whole numbers from -128 to 127

short 2 bytes Stores whole numbers from -32,768 to 32,767

Int 4 bytes Stores whole numbers from -2,147,483,648 to 2,147,483,647

Stores whole numbers from -9,223,372,036,854,775,808 to


Long 8 bytes 9,223,372,036,854,775,807

Float 4 bytes Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits

Double 8 bytes Stores fractional numbers. Sufficient for storing 15 decimal digits

Boolean 1 bit Stores true or false values

Stores a single character/letter or ASCII values


char 2 bytes
Store a decimal number. The maximum digits after the decimal is 30
Decimal 5-17bytes
8
9
Overview of Arrays
and Memory
Basic of Arrays
An array is a collection of items stored at
contiguous memory locations. The idea is to
store multiple items of the same type
together. This makes it easier to calculate the
position of each element by simply adding an
offset to a base value, i.e., the memory
location of the first element of the array
(generally denoted by the name of the array). 11
t s in c
sni ppe
e
Cod

Int Array[5] = { 2, 4, 6, 8, 100};

Array = 2 4 6 8 100

Int Array[0] = 20
Int Array[1] = -5
20 -5 6 8 100

12
Memory (RAM)

Data Storage 13
14
Memory (RAM)

Data Storage 15
Int a = 1; 1 -> 0000…01 A bit = 1 or 0
-> 32 bit for int
Int b = 4; 2 -> 0000…10
Integers:
Memory is a long tape of bytes 9, 11, 99, 1000, 0, -5
decimals:
2.5, 10.3, 56.9, -65.3
characters:
120 121 122 123 124 ‘R’, ‘T’, ‘U’, ‘p’, ‘c’
Arbitrary number
01010110
A byte Is a small unit of data = 8 bits
11011010
16
Int a = 1; dyna
m icall
Int array[3] = {6, 9, 23} ; y
Int c = 5;

120 124 128 132 136 140

17
18

You might also like