Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
17 views
Searching and Sorting ClassIV Notes
Okiwiwj
Uploaded by
Sisir
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Searching_and_Sorting_ClassIV_Notes For Later
Download
Save
Save Searching_and_Sorting_ClassIV_Notes For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
17 views
Searching and Sorting ClassIV Notes
Okiwiwj
Uploaded by
Sisir
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Searching_and_Sorting_ClassIV_Notes For Later
Carousel Previous
Carousel Next
Save
Save Searching_and_Sorting_ClassIV_Notes For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 11
Search
Fullscreen
4102/Q02B lection. Sort Sortn etth 13 913 5J4 > ihe & -7) These el In So ex os n Si Vd exe ec by eX Scanned with Cam| _____3n. celechon sort »an element is picked | Ik then Is placed at correct place Sn “thi {we _frave to eee aie ale ep lox the aright place. Algorithm. of Selechon Sort io i + & Ss 7 a i Steb=l| ET jnnan semen fee the — osinay & place at t=0. Imin = 2 it wap (ax Co), axx CminIndex]) 5 aoe) SHB aEe a 5 pa eta at Index= | to y- ise ist inte tee a = follies ab : p—t—timins fo eee wap faux CI, wor CrninTndex)) a L 4 To | Steb-3| Find minim, i eta SES ay ta jor Place Ot and Unde min = Sosa Wap (orn (27 a (min Index — seanncu win CaM| Viel \ yt Find paininoum. ub= Paar = = Asma Ss bane {rem |_index= 3 te n-| & tia ee a min =7 wap Casur (33, asur CminIndex]) 5 A a Hey Ee lo & § Find minimum in sub-anxay Staw - x= 4 te n=! & place at 4th - index — = mins & Sees fspeeECEeee EEE [Tipit TTL Swap Carve C4], a Cmin Index) ) 5 y vvamiicu win val= <= Code. ——~J Ivor celechon Sort (vector
axx){~- int n= ann -sizeC)o for (int reo; L
4 a jth mn Comnkagung_a ith roinimum ome T Index] > cyt 4 M Placing min_element ak correck_posihian —— Index), avn iJ) 3 eae $a ee (ae te-h nn hie lady Taken s fa at £n_min Index as In _& does not make ibselp: te compart — \Ttme_complescity OCn*) ay tha Lo ~ a st neta a ee vvuannicu wit am= [Bubble Sort fi th_be placed at the right pdsthon. aoe ie at — TAigoxith m for bubble soxt =i lo a 3 é L4 so Re —— * [10 >1 > swap a L 10 1 Creeley 3 xlio77 3 Swab Ht 1 = lo 6 14 g — lo» 6 = swap i a € to 14 3 —~# Ho? 144 ny a Pere eee ~K|1479 4 swap SEE ee {a = 6 bo is 3 th se Ss swap o eee ees [35 Sho swap pe Seti Tiing ett ate eeeiete eee Afi eis no swap - H2>9 > Swap lt € 7 3 fo ~ vvuamnicu winrarRound 3 1 € Ive ) - be fk 627 F_No_swap Le ae aera 129 Round= + g lo lt é pasties Sorted 6>7 — Rond3 I fecha 3 lo feted, boundary L276 = po swap 7 Now we don’t fave te go in round -6 ab one_element 2 hence = ovamicu wet Oh{\\\\ Code —_ |void bubble Sort (vec or
& ann) f ID n= aw.sizeC)i for (int f=05 Cen-1j r++) TP bool_swap| for (int 4= 12 7
oer Cj3) T Wapped = truss Swap Cann Cj- 13, as Cj) [Best case Tima Complexity (Rest case occurs when the arnay is __ orted+ Here the hime_complex: by His O(n')-as only n=! combaxasions. wilt be idehercsstesssoecer WNormal case” Time complexity — On» eecauay cose Time complexity saree IWwoust cone occurs When the annay_is Pfeuense_soxted 1 Renee hime eee there js © Cp?) ase By optimiyahon > best cone hime comples'ty PHL vvuamnicu wiur var)veduus te O(n) ee Space_complextey _——__—_— OC) as iy abalone jc ete Fe coas_ofaelechion sort is-incase sp incose et smal areas = _____— Use cane of bubble sort is wher [th Longest elements te be put ot correct place —— Loneenting Serf oo \ [This means te insext thi element at right t place : \ = zl] [= z 2 1 2)) - oa b thot 1] 7 2] Algovithm. for insexton cort_ lo 1 7 ¢ 14 9g is_alneady ok rig hk 4 fa eee tie ee i at a a | a) ||Pick element at index = 1 — t I
hifi lo, then shift 7 A then copy 6at the empty pla: _ L 6 “Sorted Pick clement ak index =4 l4>lo = nothing te co L 6 7 Lo 14 9 oO Sortek Pick element_at index = $ 9<14 3 < jo 927 Isnige 14, then shige lo & then copy J te- seannicu wit vaioid insenbna Soxt Cveckor
axa)f [ int ne ann. sizeC)3 for(int velo cens cea) te int vat= ann (623 //Fick clement ink j=0-ls sSeEREEECE fesesecneansnesee eee seat pte ge a ee | UCoropaxs element Elam Ci) > volt — Joo CF Con Ci > vob) |__ Wshifting. opexahen mn C4 +1) = val 4 else 1 break > 4 1] Goby step ann Ci +1) =vahs 4 3 [Time_cora| C(t) in’ neemal_kwmst case O(n) in the best case tre e a z alncady— oxted Space complexity, nae lo() os only vomables ora imeated. Z vvuaiiicu win rdam4 classmate | Use case ef insexhbn sorted Is _(n case é 4 — : | a Smet Cando when asrast Is pantiatiy— Inbutt sort _funchen ~ |sovt Cann begin), ans-endO) 2 3 18 Used te soy +t the vector We need te Include algorithm header _ pe te wise this inbult funchion = Scanned with Cam
You might also like
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Mark Manson
4/5 (6387)
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
4/5 (634)
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Brené Brown
4/5 (1160)
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
Chris Voss
4.5/5 (983)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
4/5 (8302)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
4/5 (633)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
4/5 (1254)
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Phil Knight
4.5/5 (933)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
4/5 (10337)
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Carmen Maria Machado
4/5 (887)
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Ben Horowitz
4.5/5 (361)
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Margot Lee Shetterly
4/5 (1007)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
4/5 (3237)
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
Ashlee Vance
4.5/5 (581)
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Siddhartha Mukherjee
4.5/5 (297)
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Fredrik Backman
4.5/5 (5058)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
4.5/5 (943)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
4/5 (4346)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Meik Wiking
3.5/5 (458)
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
Sarah M. Broom
4/5 (100)
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
Colm Toibin
3.5/5 (2091)
Yes Please
From Everand
Yes Please
Amy Poehler
4/5 (1993)
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Gilbert King
4.5/5 (278)
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Thomas L. Friedman
3.5/5 (2283)
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Roxane Gay
4/5 (1077)
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
Ruth Ware
3.5/5 (2780)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
4.5/5 (2032)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
4/5 (2838)
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
Viet Thanh Nguyen
4.5/5 (141)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Dave Eggers
3.5/5 (692)
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Doris Kearns Goodwin
4.5/5 (1912)
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Hilary Mantel
4/5 (4086)
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Naomi Klein
4/5 (76)
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Bob Woodward
3.5/5 (830)
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Jennifer Egan
3.5/5 (906)
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Jay Sekulow
3.5/5 (143)
John Adams
From Everand
John Adams
David McCullough
4.5/5 (2544)
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
M L Stedman
4.5/5 (813)
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
George Packer
4/5 (45)
Little Women
From Everand
Little Women
Louisa May Alcott
4.5/5 (2369)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carré
4/5 (277)