We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 42
INTRO TO
DFT emia UCM el eh
4
AlgorithmsIntroduction
Data Structure
+ Data Structure is a way of collecting and organizing data in such
a way that we can perform operations on these data in an
effective way. Data Structures is about rendering data elements
in terms of some relationship, for better organization and
ole-lol sa
Data Structures are structures programmed to store ordered
data, so that various operations can be performed on it easily. It
represents the knowledge of data to be organized in memory.
+ It should be designed and implemented in such a way that it
oe reduces the complexity and increases the efficiency.
SZ DATA STRUCTURES &Characteristics of a Data Structure
Ba eked -Ces 1-1 tame Llc) VL COL Maa) cia in 1 edge aLel eM a) LACS
CM Cla lemeelitclea
* Time Complexity - Running time or the execution time of
operations of data structure must be as small as possible.
+ Space Complexity - Memory usage of a data structure operation
should be as little as possible.
2) CN aesPFET]
|s a collection of numbers, symbol or characters.
Teen oe Uc
el: veInformation
An organized collection of data, that is arranged meaningfully.Data Structures
Beer CUM uC ae ee er
RUPE Ur ee ua ere Rel erLCel
ERC MURR Reem le
ae: veeWhy Do We Need Data Structures?
SR eS Mer ett
Pena tea ah Chaos oe
el: veReal World Application
PTUs
+ Stored Categorically
Seen
a | ver errrEA ola (ew -Veye)i(et-acola)
Pelee Ina
SES OCCR creer
Dee eT
a | pry per rrEA ola few -Veye) (et acola)
Maps
PS eee ur cr
Beene)Variables
SCC Cem CMe Cn Ray UL
a: | ver errrArray / Collections
Bee ue ttt M cee RCC ey
een ee onc Earn oe
Osetia omen c 7s
Ca Ratna
easily sorted or searched.
ee: veProgramming Application
Array in C++ WITHOUT SORTING.
Assume that it takes 1 second for each element to be read
ee: vesProgramming Application
Array in C++ WITHOUT SORTING.
Te em US A Sc eC
A: ve errrProgramming Application
Array in C++ WITHOUT SORTING.
ee Rc ore us
a | rye perryProgramming Application
ON eee Ele Ce
e
Eee
Teen Mec cL Ce
a | uve errrProgramming Application
ON ane E100 oe
Eee et
Cee ne cl cme)
ae: veeCoola res(ey a)
RON COC eRe Ree aoe}
TN 4 Se TD
writing data on our System
a | ver perNeed for Data Structure
As applications are getting complex and data rich, there are three common problems that
Cae eae a ne
Be ee ap mR Cue ce ea
rec ere Ce nN use aco}
eR UE eck CM el Melee Oe ol
+ Processor Speed - Processor speed although being very high, falls limited if the data
Peter er eecacc
Sec een Rete Kaen Cu enemy
Pee ce ae en
To solve the above-mentioned problems, data structures come to rescue. Data can be organized
in a data structure in such a way that all items may not be required to be searched, and the
Eero ts Ret] Ree Bre eanWhat is an Algorithm?
EY Ce ao ee MR oe Ot eR
Cre ce M RM mete a OMe CMe Ce Mol New| en WMT aie
Cen Cem Cntm ie Diecut ecomiC meme eed uence)
in more than one programming language.
In computer programming terms, an algorithm is a set of well-defined instructions to
solve a particular problem. It takes a set of input(s) and produces the desired output.
ogc es
oe
Eee neh ary
Seem Mma
Sea ee eae h iceme org
Sees aueeest
Warayesteem cme Wa ee Os UR Cm
ee scars
1) Get the frying pan.
2) Get the oil.
Emer
eee a nud
RMN ue To zelea
Sem une net eared In
Sem Un ce
ESM ES aT
NEC Oe Cae Reus un es Un URI Uc eI)
step-by step procedure for solving it. The formal definition of an algorithm can be stated
Pee Urea isc ae urns tsute Cnr keer Nc nas eam
a: veQualities of a Good Algorithm
Mek Men MCh cone
enc MIC eee ke cue Maes ety
Treen mee ice en RMAC Soe nce
eae a eee Mee cme Me CMR Rea agro
PCRS en Mau ee eM Re race Ce Due oe
Owen treyA Basic Flowchart
4
Yes
Rt >lreeae)
t a
«
Owen taeRU mUC MEMS mmo eRe M eeu mee eos
Pelee nite
Der ese eres oe MCR ce sures
Beer enna Reus
See Seal 0 LOM CeCe Os
Oar me eer anon sees hue Recess
See ee Cen en une RC ete
ee: veeCharacteristics of an Algorithm
Nel lel cele te Uo Meme ere (ol LOO CCR SRO)
ere aCun oes
oe
Unambiguous - Algorithm should be clear and unambiguous. Each of its steps
(or phases), and their inputs/outputs should be clear and must lead to only one
Cuce
TT See eC ene MM Rm Res inne
Output - an algorithm should have 1 or more well-defined outputs, and should
match the desired output.
eae Cee Hueco
eee eerie teers RU Rue ee teleetecet ees
Te ent Cee ge en ene Meese meek eee MCCS
PEO Suen Ne mecca koe cy
WasAlgorithm 1: Add two numbers entered by the user
Se meSeid
Sera NCC Sun aes
Seeks ome ane
Step 4: Add num1 and num2 and assign the result to sum.
eT ere
Step 5: Display sum
Sense
OW eyAlgorithm 2: Find the largest number among three
Cs i ooo
SC RRS
See eR eds
Reece RUC eek
Sera eee)
fe
De ee a
Else
Pea ee aa
a
er
Dee a
Else
Pe gem
SacA good algorithm maintains a level of correctness while being
efficient. Meaning, there is little error, and it doesn’t take much time
to complete. Another important component is comprehensibility.
We wouldn't be able to use algorithms so frequently if they couldn't
be understood. Algorithmic and computational thinking is so
pervasive that it governs the simplest things in our daily lives. Here
are some examples of algorithms you interact with everyday.Recipes
Just like sorting papers and even tying your shoes, following a recipe is a type
of algorithm. The goal of course being to create a duplicated outcome. In
order to complete a recipe, you must follow a given set of steps. Say you are
making bread. You need flour, yeast and water. After you have your
ingredients, you need to combine them in a certain way that will create a
predictable outcome, in this case a loaf of bread.Sorting Papers
Asimple task and yet it uses algorithmic thinking. When you are sorting office
files or your personal documents you are implementing an algorithm. In its
most basic sense, you are following a set of tasks to achieve an outcome. The
reason why sorting papers is a great example, is because it shows the variety
of tasks and specifications algorithms can use. For instance, you can sort your
files alphabetically, by word count, by date, and countless others. The goal is
to simplify the organizational process by using small tasks.
PS
4 WarayACTIVITY TIME!
a: veWrite down at least 3
algorithms you interact with
everyday and present it in
front of the class.OA Y-ee) PLL eleva nel gy
Basically, data structures are divided into two categories:
See Smee) ne)
Se Onegai
Linear data structures
* In linear data structures, the elements are arranged in sequence one after the
CUES ee cue eicie eer mom Omens
Sea RC Cee ered
Re Mest ued eam ede etek cea Reem ier
ee: veeCeCe oa
Gece Cerra
ROA CO uC on a Ua es
EOE eee eC Res eS eee
STO tue Age Meu
Sn ee eee
Owen taePee Leela y
cee CR eM MC Le onan ge el Ree
SORES oer aC ni
Teens od Ce Sogo oa cc ee RE ne
Ina stack, operations can be performed only from one end (top here).
| yerEmeM MDE ry
OSC ean Mon ager uel ROC us
SRR oR
Tans oa eR a UR ee mC RR
Puree
Ne
“a
Ina queue, addition and removal are performed from separate ends,
a | eerver perryeM Peer C Runa o Tc
eet om Cnn Cea ec Run ee mC
each node contains the data items and address to the next node.
ema i - | 2 nox a Ez - oe
PU
ee: eeee AKL ed kd Ok ed
Ue SCM ne eC ee a Te
aC CRU ere RM ee ee hen coool
eu ale
Non-linear data structures are further divided into graph and tree-based data structures.
Dem aeceT cc
ve eae emu Mees Reese hn Coe non nCa Reena rect)
ate eee
CeCTS Tarek
Pao Rt)
Like a graph, a tree is also a collection of vertices and edges. However, in tree
et Mt eeu Re ee Rel Rs ae RR ee
ee
Sa | ver errrLinear Vs Non-linear Data
Re en ora
Pouce
dl
Te |) Te data tems are arranged in non-sequenta
reopens order herarhieal manner
Peet) the dataitems ar presen at iterent ayer
TE Ea SLs gen) requires multiple uns That fw tart from
Potitithy hata tence el) thetrst element t might not be possbleto
CEP FG) traverse all the hemerts ina sgl pass.
Diferent structures utilize merery i ferent
icint ways depending onthe need,
ee een ry
ees
Example Tee, Graph, Map
) Wan aeLinear Data Structures
BUC eR EUR ea
See
All the items are present on the single layer.
eee RE ad
SR ues kek
elements sequentially in a single pass.
BUC ue mua le
MR ee ae RN UR Eco
SC Ce Sac eget
Non-Linear Data Structures
BUR CoRR ete oUt Rees (ou
Ae Teele UC
See Cpe ene ees a ee
Tae aes
Fe earned cee
See a
Different structures utilize memory in different efficient
Reve esa eure
Mee SAC SR ec oe
Se a RC ETD
a | ver errrNel t