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)
32 views
7 Algorithm (Searchinmg & Sorting UPDATED) (MT
Uploaded by
ahsan
AI-enhanced title
Copyright
© © All Rights Reserved
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
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)
32 views
7 Algorithm (Searchinmg & Sorting UPDATED) (MT
Uploaded by
ahsan
AI-enhanced title
Copyright
© © All Rights Reserved
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
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 | majidtahir61@gmail.com 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 | majidtahir61@gmail.com 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 | majidtahir61@gmail.com 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 | majidtahir61@gmail.com 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 & ‘majidtahir61@gmail.com 2
You might also like
4.1.2 Bubble Sort and Insertion Sort (MT-L)
PDF
No ratings yet
4.1.2 Bubble Sort and Insertion Sort (MT-L)
10 pages
19.1 Algorithm Searchinmg and sorting
PDF
No ratings yet
19.1 Algorithm Searchinmg and sorting
15 pages
Unit 2(ADS)
PDF
No ratings yet
Unit 2(ADS)
20 pages
Arrays
PDF
No ratings yet
Arrays
9 pages
Chapter 2 Simple Sorting and Searching Algorithms
PDF
No ratings yet
Chapter 2 Simple Sorting and Searching Algorithms
42 pages
Bubble Sort
PDF
No ratings yet
Bubble Sort
3 pages
Bubble n Insertion Algorithm
PDF
No ratings yet
Bubble n Insertion Algorithm
9 pages
Dsa Lab Report
PDF
No ratings yet
Dsa Lab Report
6 pages
Topic: 2.2.2 Arrays: DIM Names (4) As String
PDF
No ratings yet
Topic: 2.2.2 Arrays: DIM Names (4) As String
7 pages
Searching and Sorting Updated
PDF
No ratings yet
Searching and Sorting Updated
57 pages
CA229 Unit 06
PDF
No ratings yet
CA229 Unit 06
25 pages
Linear Search
PDF
No ratings yet
Linear Search
10 pages
Chapter 2 - Elementary Searching and Sorting Algorithms
PDF
No ratings yet
Chapter 2 - Elementary Searching and Sorting Algorithms
39 pages
Sorting Search New
PDF
No ratings yet
Sorting Search New
15 pages
Data Structures and Algorithms: Lecture 7. Basic Sorting Algorithms
PDF
No ratings yet
Data Structures and Algorithms: Lecture 7. Basic Sorting Algorithms
26 pages
Algorithms and Programs 4.0
PDF
No ratings yet
Algorithms and Programs 4.0
1 page
DS Searching Sorting (3) SLM
PDF
No ratings yet
DS Searching Sorting (3) SLM
55 pages
Chapter 2
PDF
No ratings yet
Chapter 2
30 pages
5 - Sorting and Searching Algorithm
PDF
No ratings yet
5 - Sorting and Searching Algorithm
35 pages
Pseudocode Notes
PDF
No ratings yet
Pseudocode Notes
9 pages
UNIT IV - Searching and Sorting
PDF
No ratings yet
UNIT IV - Searching and Sorting
21 pages
Data Structures Se E&Tc List of Practicals
PDF
No ratings yet
Data Structures Se E&Tc List of Practicals
23 pages
ADS P1 Corrected_merged
PDF
No ratings yet
ADS P1 Corrected_merged
18 pages
ADS Practical 1_removed
PDF
No ratings yet
ADS Practical 1_removed
5 pages
Binary Search:: Binary Search Takes Far Few Comparisons Compared To Linear Search Which Checks Each and Every
PDF
No ratings yet
Binary Search:: Binary Search Takes Far Few Comparisons Compared To Linear Search Which Checks Each and Every
6 pages
9618 Chapter 23
PDF
No ratings yet
9618 Chapter 23
18 pages
Chapter 2
PDF
No ratings yet
Chapter 2
26 pages
Unit 7
PDF
No ratings yet
Unit 7
15 pages
17 Sorting
PDF
No ratings yet
17 Sorting
77 pages
Algorithms: Finding The Smallest Element in An Array Find The Smallest and Make It The First
PDF
No ratings yet
Algorithms: Finding The Smallest Element in An Array Find The Smallest and Make It The First
5 pages
Searching: Unit-5
PDF
No ratings yet
Searching: Unit-5
21 pages
Bubble Sort
PDF
No ratings yet
Bubble Sort
16 pages
Arrays
PDF
No ratings yet
Arrays
42 pages
chapter 3
PDF
No ratings yet
chapter 3
41 pages
Searching and Sorting Algorithms
PDF
No ratings yet
Searching and Sorting Algorithms
9 pages
Unit 2 - Sorting and Divide and Conquer Approach
PDF
No ratings yet
Unit 2 - Sorting and Divide and Conquer Approach
138 pages
Sorting Algorithms: Bubble, Insertion, Selection, Quick, Merge, Bucket, Radix, Heap
PDF
No ratings yet
Sorting Algorithms: Bubble, Insertion, Selection, Quick, Merge, Bucket, Radix, Heap
24 pages
Chapter 3
PDF
No ratings yet
Chapter 3
42 pages
Chapter II Searching Sorting
PDF
No ratings yet
Chapter II Searching Sorting
12 pages
280 - DS Complete-5
PDF
No ratings yet
280 - DS Complete-5
20 pages
A7e55228 1639798147383
PDF
No ratings yet
A7e55228 1639798147383
36 pages
Sorting___Searching
PDF
No ratings yet
Sorting___Searching
20 pages
Module5 DSA
PDF
No ratings yet
Module5 DSA
68 pages
Chapter 7 - Sorting
PDF
No ratings yet
Chapter 7 - Sorting
26 pages
Sorting and Searching
PDF
No ratings yet
Sorting and Searching
15 pages
Chapter 2
PDF
No ratings yet
Chapter 2
16 pages
DS - Unit-5 - Sorting & Searching
PDF
No ratings yet
DS - Unit-5 - Sorting & Searching
38 pages
Sorting Algorithms
PDF
No ratings yet
Sorting Algorithms
165 pages
Chapter-7-Sorting_0c88671e-7bff-41c4-8fcb-85d7f01277f2
PDF
No ratings yet
Chapter-7-Sorting_0c88671e-7bff-41c4-8fcb-85d7f01277f2
26 pages
best sorting notes
PDF
No ratings yet
best sorting notes
19 pages
Algorithm ASSIGNMENT 1 Group 2
PDF
No ratings yet
Algorithm ASSIGNMENT 1 Group 2
6 pages
03 Sorting Algorithms
PDF
No ratings yet
03 Sorting Algorithms
60 pages
Topic 7.4 Linear Search & Bubble Sort
PDF
No ratings yet
Topic 7.4 Linear Search & Bubble Sort
10 pages
Sorting Algorithms - Presentation
PDF
0% (1)
Sorting Algorithms - Presentation
32 pages
LAB2
PDF
No ratings yet
LAB2
17 pages
Searching and Sorting
PDF
No ratings yet
Searching and Sorting
51 pages
DSA-ch2
PDF
No ratings yet
DSA-ch2
31 pages
Cso 102 Week 1
PDF
No ratings yet
Cso 102 Week 1
30 pages
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 2 - Hardware and Software
PDF
No ratings yet
Chapter 2 - Hardware and Software
21 pages
Chapter 7-Expert Systems
PDF
No ratings yet
Chapter 7-Expert Systems
8 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