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)
24 views
7 Algorithm (Searchinmg & Sorting UPDATED) (MT
Uploaded by
ahsan
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save 7 Algorithm( Searchinmg & sorting UPDATED)(MT- For Later
Download
Save
Save 7 Algorithm( Searchinmg & sorting UPDATED)(MT- For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
24 views
7 Algorithm (Searchinmg & Sorting UPDATED) (MT
Uploaded by
ahsan
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save 7 Algorithm( Searchinmg & sorting UPDATED)(MT- For Later
Carousel Previous
Carousel Next
Save
Save 7 Algorithm( Searchinmg & sorting UPDATED)(MT- For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 5
Search
Fullscreen
Syllabus Content: 7 Algorithm design and problem-solving © Show understanding of linear searching method Linear Search: Linear search is a method of searching a list in which each element of an array is checked in order, from the lower bound to the upper bound, until the item is found, or the upper bound is reached. The pseudocode linear search algorithm and identifier table to find if an item is in the 1D array(myList) is given below. DECLARE count, num As Integer DECLARE found As Boolean = False //Creating array to search intem (Free notes @ www.majidtahir.com) DECLARE Mylist() As Integer = {4, 2, 8, 17, 9, 3, 7, 12, 34, 21) OUTPUT (“Please enter any integer to be checked in List") INPUT num For count = @ To 9 If item = Mylist(count) Then found = True End If Next If found = True Then OUTPUT ("Item Found = ", num) Else ‘OUTPUT ("Item Found is unsuccessful") End If Sample VB program of linear search: Dim count, num As Integer Website: www.majidtahir.com || Contact: 03004003666 |
[email protected]
aDim found As Boolean = False Dim Mylist() As Integer = {4, 2, 8, 17, 9, 3, 7, 12, 34, 21) ‘Create array to search iten Console.WriteLine("please enter an integer to be found") num = Console.ReadLine() For index = @ To 9 ‘If item = Mylist(count) Then found = True End If Next If found = True Then Console-WriteLine("Iten Found = * & item) Else Console.WriteLine("Item Found is Unsucessful") End If Bubble Sort [Compare] [Compare] [Compare] [Compare] [Compare] [Compare] ‘Sorted * baie] [SMB] a Bae par| — | "fa ist ‘by | es 25 25 25 25 25 eee wo | 34 4 34. 4 34 98 mm 7 im = 7 z 7 7 a 41 al a a 41 swap | 99 19 BC) 19 19 19 oo 5 5 5 5 5 Figure 11.12 Swapping values working down the array When we have completed the first pass through the entire array, the largest value is in the correct position at the end of the array. The other values may or may not be in the correct order. We need to work through the array again and again. After each pass through the array the next largest value will be in its correct position, as shown in Figure below. @ Website: www.majidtahir.com || Contact: 03004003666 |
[email protected]
a@ original | [ after | { after | [ after | [after | [ after | [ after list passa | | pass2| | pass3 | | passa | | passs | | passe 25 25 25 7 7 7 5 34 u 7 25 19 5 we || 7 3 19 5 7 41 19 5 a 19 5 19 5 : | Favre 11.12 Ctatac af the arrav aftaraach nace In effect we perform a loop within a loop, a nested loop. This method is known as a bubblesort. The name comes from the fact that smaller values slowly rise to the top, like bubbles in a liquid. | Bubble sort: a sort method where adjacent pairs of values are compared and swapped Bubble Sort Algorithm: BEGIN DECLARE MyList [10] : INTEGER = {4, 2,8,17,9,3,7,12,34,21} DECLARE count, temp, top : INTEGER DECLARE swap : BOOLEAN = False top = LENGTH (MyList()) WHILE top <> 0. FOR count = 1 to (top-1) IF Mylist(count) > Mylist(count + 1) THEN temp = Mylist(count) Mylist(count) = Mylist(count + 1) Mylist(count + 1) = temp swap = True End if top = top- NEXT END WHILE END Website: www.majidtahir.com || Contact: 03004003666 |
[email protected]
a@ Or another sample Program DECLARE myList : ARRAYS[0:8] OF INTEGER = {4, 2,8,17,9,3,7,12,34,21} DECLARE upperBound, lowerbound, count, temp, top : INTEGER DECLARE swap + BOOLEAN Uuppersound €— 10 loverBound <€— 0 top <== _upperBound REPEAT FOR index = lowerBound TO (top - 1) Swap €~ FALSE ‘IF MyList [count] > MyList [count + 1] THEN Temp =m HyList[count] WyList[eount] m= MyList{count + 1] MyList[count +1] <== Temp swaps €— TRUE END IF Next topq— top - 2 UNTIL (NOT swap) OR (top = @) Bubble Sort Algorithm using VB Console Mode: In this tutorial, i will teach you how to create a program for bubble sorting using vb.net console. We all know that bubble sort is a sorting algorithm that is repeatedly searching through lists that need to be sorted, comparing each pair of items and swapping them if they are in the wrong order. Module Module1 ‘Sub Main() Dim myList() As Integer= New Integer() {70, 46, 43, 27, 57, 41, 45, 21, 14) Dim index, top, temp As Integer Dim Swap As Boolean top = myList.Length = 1 Do swap = False "LOOP can work fine without STEP also For index = @ To top - 1 Step 1 ‘STEP is a keyword to increment in loop If myList(index) > myList(index + 1) Then ‘temp = myList (index) mylist(index) = myList(index + 1) mylist(index + 1) = temp swap = True end If Next top = top - 2 Loop Until (Not Swap) Or (top = 0) “Outpout The Sorted Array For index = @ To mylist.Length - 1 Console.WriteLine(myList(index) & " “ Next Console. Readkey() End Sub End Module Website: www.majidtahir.com || Contact: 03004003666 |
[email protected]
aReferences: Computer Science AS & A Level Coursebook by Sylvia Langfield & Dave Duddell Computer Science Teacher's Resource Computer Science AS & A level by HODDER EDUCATION https://www. youtube.com/watch 2v=I-kosUrt ft https:/Awww.dotnetperis.com/dictionary-vonet http://www. woridbestlearningcenter,com/index.files/vb.net-example-insertion-sort.htm wz Website: www.majidtahir.com & ‘
[email protected]
2
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 (6134)
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
4/5 (627)
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
Brene Brown
4/5 (1148)
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 (935)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
4/5 (8215)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
4/5 (631)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
4/5 (1253)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
4/5 (8365)
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 (860)
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Carmen Maria Machado
4/5 (877)
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 (954)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
4/5 (2923)
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 (484)
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 (277)
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Fredrik Backman
4.5/5 (4973)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
4.5/5 (444)
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
Colm Toibin
3.5/5 (2061)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
4/5 (4281)
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)
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 (447)
Yes Please
From Everand
Yes Please
Amy Poehler
4/5 (1988)
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 (1068)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
4/5 (1993)
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
Ruth Ware
3.5/5 (2641)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
4.5/5 (1936)
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
Viet Thanh Nguyen
4.5/5 (125)
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 (4074)
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 (75)
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 (901)
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 (790)
Chemistry File 2
PDF
No ratings yet
Chemistry File 2
16 pages
8.1 Procedures and Functions UPDATED (MT-L)
PDF
No ratings yet
8.1 Procedures and Functions UPDATED (MT-L)
9 pages
Chapter 7-Expert Systems
PDF
No ratings yet
Chapter 7-Expert Systems
8 pages
Chapter 2 - Hardware and Software
PDF
No ratings yet
Chapter 2 - Hardware and Software
21 pages
2.08 IP Addressing
PDF
No ratings yet
2.08 IP Addressing
6 pages
2.07 Applications That Make Use of The Internet
PDF
No ratings yet
2.07 Applications That Make Use of The Internet
4 pages
2.04 LAN Hardware
PDF
No ratings yet
2.04 LAN Hardware
2 pages
Mydocument
PDF
No ratings yet
Mydocument
12 pages
Computer Science: Paper 2210/11 Paper 1
PDF
No ratings yet
Computer Science: Paper 2210/11 Paper 1
11 pages
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 (105)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carré
3.5/5 (109)