Skip to main content
Open navigation menu
Close suggestions
Search
Search
en
Change Language, English
Upload
Sign in
Sign in
0 ratings
0% found this document useful (0 votes)
20 views
13 pages
Searching Sorting Algorithm
Searching Sorting Algorithm in Data Structure
Uploaded by
zaini.iqbal761
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
Save
Save Searching Sorting Algorithm For Later
Share
0%
0% found this document useful, Mark this document as useful
0%
0% found this document not useful, Mark this document as not useful
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
20 views
13 pages
Searching Sorting Algorithm
Searching Sorting Algorithm in Data Structure
Uploaded by
zaini.iqbal761
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
Go to previous items
Download
Save
Save Searching Sorting Algorithm For Later
Share
0%
0% found this document useful, Mark this document as useful
0%
0% found this document not useful, Mark this document as not useful
Print
Embed
Report
Go to next items
Download
Save Searching Sorting Algorithm For Later
Share
More options
Fullscreen
Fae reverdins for finding specific text or word(s) in the documents such as ] inding text in MS-Word or information downloaded in the web browser window ¢ Finding records or information stored in a sequential file The sequential search method is not recommended for a large amount of data because ome more efficient search methods are available for large and complex searches. These search lnethods are binary search and hash table. \ .. ¢ come le nit y oly gal4is an algorithm that searches a value from an array ‘XYZ’ having N elements, 1 START 2 SET LOC =-1 3 INPUT N values into an array XYZ | INPUT VAL [Enter value that is to be searched) 4 REPEAT Step-5 FOR |= 1 TON 5. IFVAL=XYZ{l] THEN a - Loc=! RANA Feee PRINT "Value found at location", LOC. EXIT END IF [End of step-4 Loop] 5. IF LOC =-1 THEN PRINT "Value not found" END IF : 7. EXIT // Program to search a value in an array using sequential search |, - . | #include | #include
class seq_search private; © int xyz[5); public: ; void input(void); . ; void search(int), ~ yd . Fis main(void) 1 LeyWrite an algorithm that searches a value in an array XYZ, having N elements and replaces the searched value with a new one. Use a sequential method to search START SET LOC =-1 INPUT N values into array XYZ INPUT VAL1 {Enter a value to be searched into variable VAL1) Pens f ‘array. | : “INPUT VAL2 {Enter a value to be replaced with VAL1 inte variable VAL2} REPEAT Step-6 FOR != 1 TON Bp. 5. | 6. IFVAL1=XYZ{l] THEN | _XYZ{l] = VAL2 Loc=! PRINT “Value is modified at location’, Loc : EXIT = END IF [End of Step-5 loop] 7. IF LOC =-1 THEN: PRINT "Value not Found" EXIT ! END IF we : : 5 Wt Program to seat a value in an array and replace it with another one. #include'
#include
: \ class seq_search 3 : { Y = ‘ Bie Private: i intxyz[5;; public: . Void input(vold); ‘ Ro Vold search replaca(int, int); - » :. 2 a (malo \fe STK ‘he largest value] Write an algorithm that finds the largest value in an array ‘XYZ’ consisting of § | elements. 4, START 2. INPUT five values into array XYZ 3. [Assigns value of first element of array to MAX, and 1 to C} MAX = XYZ[0], C = 1 4. [Loop that searches maximum value in an array] REPEAT Step-5 WHILE C<=4 5. IF MAX < XYZ[C] THEN MAX = XYZ[C] c=C+1 END IF [End of loop of step- 4] 6. PRINT MAX EXIT // Program to find the largest value in‘an say using speathach method #include
EW ¢ #include > 5 class max_value "* 55 { eet A re private: pele k int xyz[5];- publi; Fe ; void input(void); ’ AS int search(int&); . } ‘ Z i any void main(void) oh ee te 3 { ’ i a esha § max_value obj; int pos, max; j elrscr(), a ot | [Link](); 4 ab “Max = [Link](pos); ~, Coutk<"The lataest valud'is: "<
» 20 pages First, we open the book from the middle. If the current page is 'e5%%4 = Swe apen ai a page to the right; otherwise, we open at a page to the left. page 6 is found. In this example, we have a sorted list of sz mpanison is with the middle page number 10. This eliminates the \ast pages. as page 6 is less than 10. The second comparison is from page | to page eliminates page | to page 5, as page 6 is greater than page 5. This 2 continues until page 6 is found. . + Searching a specific word in the ica: For searching a particular word im dictionary, we usually start from the middle in the dictionary. If the word that wea searching for comes before words on the current page, it shows that the word shoul te before this page. So we look at the first half. Otherwise, we search for the word the second half of the dictionary. Suppose the word is in the first half of dictionary, we consider the first half for looking at the word. We do not need to loot nto the second half of the dictionary. Thus the data to be searched is divided into hail of the process. Now we divide this portion into two halves and resume search for the aad Here we again have to find whether. the word is in the first half or the second half of this portion. The same step is repeated with the part that contains the required, word. Finally, we come to the page where the required word exists. We see that in the) binary search, the search process speeds up becatas of dividing the target list into) two halves repeatedly. t se | | ESE | \ Write a algorithm t that finds a value in an array ‘ABC! consisting of 10 elements, | sorted in ascending order, Assume-that § represents the first element of the array and E represents the last element of the array. { START | S=1,E=10 {Assign values to variables S & E) SETLOC=-14 | INPUT values in array ABC, in ascending order. Ob } Snes#5 LY 267 5, ° INPUT VAL [Enter value to be searched in variable VAL] [Loop that searches value in an array using Binary search} REPEAT Step-7 and Step-8 WHILE S <= E MID = (S + E)/2 IF VAL = ABC[MID] THEN LOC =MID +1 EXIT ELSE IF VAL < ABC[MID] E=MID-1 es on ELSE S=MID+1 END IF [End of Step-6 loop] IF LOC = -1 THEN PRINT "Value not found " ry ELSE PRINT. "Value found’at locatio END IF sot ee imag 1. EXT Sie ‘rogram to search arequired value from aray .y with binary search method include - - i ee 2) haga ota’ lo atp privet sor soa he ba int abc[10}; Public; 4 '. ‘void input(void); i vold,search(int); id main(void) bin_search obj; 5 : intval; f ree eee oss | clrser();.” ‘ : oa iad aAhatt ANI innit/\42% 20 4% 20 12% 20 [37 37% 20= 17 — MU RECUR Write an algorithm that inserts N integer data values into a hash table and then searches a specific value from the hash table. Take an array ARR of size N. START Initialize ARR array to NULL INPUT N values into array ARR REPEAT Step-5 to Step-7 FOR = 1 TON INPUT data value in VAL {Compute the index to-store the value [Link] table] INDEX=VAL/N : ¥. ff the calculated | ‘index hag, empty space, store the value, otherwise display “Collisicn” message) IF ARR[INDEX] = NULL THEN ARRIINDEX] = VAL ELSE “PRINT "Collision Occurs" ENDIF | {End of Step-4 loop] i 8. INPUT data value to search in X Oo hwo 9. {Search the value from hash table by re pamputiog its [Link] hash ee “INDEX =X/N 10. “IF ARR[INDEX] = NULL THEN | PRINT "Value not found”, | ~ ELSE | oe PRINT "Data value is” MARINE | ENDIF. 11. EXIT PrnEe : ; rite // program to input 10 i integer values into a hash table and search a specific value from | -I/ the hash table | #include
yoid hash_integers::search(int n) amas index = n % 10; if(hash_tablefindex) = n || hash_tablefindex} == NULL) cout<<"Value not found”. else cout<<"Value found:” <
=1) [Start of upper loop] 4 SETI=1 5. REPEAT STEP-6 TO 7 WHILE (I<=U) {Start of inner loop] 6. _IF ABC[I] > ABC[I+!] THEN [Interchange values] TEMP = ABC{I] : ABCTI] = ABCI+1] ABC[I+41] = TEMP END IF : 7.5 VSV# AS © * [End of inner loop) 3 > . USU-4 {End of Upper loop] = 9 EXT ok ‘ : Mt Progra to sort an array with 5 elements using bubble sort method. #include
; #include class bubble { ‘ Private: © * Pry tek as int abofhj, es Pt Ss public: * parece nie RE bs void input(void);). °° os oot 7+... Wold sort(void); pees ; vold print(vold);. " } h y Se ey S04 fe void main(void) PSs fee4 og *~ bubble obj; clrser(); wed : f° objinput(), yay [Link](), obj. print(); getch(), Y Pca eget143 fot 7 | 2 a a Before Swapping Aner Swapping Pass -4: The array is searched starting from the fourth element to the last element i.e. ely and S™. The clement that has the smallest value is selected. The smallest val, position 4, Since 7 is a smaller value and it is already located at location 4, y exchange the values, The array after this pass is shown below. We get the sq after the last pass. F Ceri) Llslel7] 2! Before Swapping Re After Swapping. © Write an algorithm to sort an [Link] in: ascending order using the sel method. The array consists of N elements. Puta e ae START a . “SET U=0 ~ .. [Urepresents the control variable Used. for upper loop} REPEAT STEPS 4 T0.10 WHILE (U
ABC[I] THEN » ~ : abo ee “MINI = ABC. § ISS as OS Loc =| shes gees fest : NO Ponp > ns ENDIF . ~ 18 La bean: eaNS : + [End of Step-6 loop innier Loop} 524 9. ° [interchange values) res f TEMP = ABCILOC] “ABCILOC] = ABCIU] zl *ABC[U] = TEMP 10. USUFT.. se a [End of Step-3 loop -—- upper Loop] ©." Me EAM sy es (ERIE Me ain yy Uae ae ue aay ‘.f Program to sort array with 5 elements using selection sort method." ib egg . A aesvalue of A[O] So shift the values of clemenis » . 7 TB jnsent the value of A[2] into AO] The array, before and alles paooré 15 Shown belo! I . . | CTT] U[sJe2fs) Compare the value of the fourth element of the array with the values of elements by, and insert it in the proper position. In this case, the value of A[3] is smaller thy, value of A[2]. So shift the value of element from A(2] one position to the right ang the value of A(3] into A[2]. The array, before and after pass-3 is shown below: Py dy ET Te lol EEE Pass-4: : : Compare the value of the fifth element of the array with the values of elements be and insert it in the proper position: In this case, the value of A[4] is smaller value of A[3]. So shift the value of element from A[3]} one Position to the right and the value of A[4] into A[3]. The array, before and after pass-4 is shown below Write an algorithm to sort an'array ‘ABC in, ascending order using the. int sort method, The array consists of N elements. Sa 1. START. paces : : 2 INPUT data into array ABC 3. [ Start of upper Loop ] ( REPEAT. Step-4 TO 8 FOR.U 1-TO Neter FOF Oe a 4. VAL = ABC[U] 5 teu 6. _ [Start of inner Loop ] REPEAT Step-7 WHILE(I>=0 AND VAL
boos : foot: > * #include void MergeSort(int (, int, int); void Merge(int (}, int, int, int); c
You might also like
C Programs for Search and Sort Algorithms
PDF
No ratings yet
C Programs for Search and Sort Algorithms
47 pages
Algorithms Laboratory
PDF
No ratings yet
Algorithms Laboratory
49 pages
Algorithm Lab Manual
PDF
No ratings yet
Algorithm Lab Manual
59 pages
C Program for Binary Search Implementation
PDF
No ratings yet
C Program for Binary Search Implementation
29 pages
Algorithm Laboratory Experiments Guide
PDF
No ratings yet
Algorithm Laboratory Experiments Guide
40 pages
Searching and Sorting Algorithms Explained
PDF
No ratings yet
Searching and Sorting Algorithms Explained
87 pages
ALG Lab Manual
PDF
No ratings yet
ALG Lab Manual
56 pages
CS3401 Algorithms Lab Record
PDF
No ratings yet
CS3401 Algorithms Lab Record
63 pages
Algorithm Lab Manual: Search & Sort
PDF
No ratings yet
Algorithm Lab Manual: Search & Sort
47 pages
Algorithms Laboratory Record
PDF
No ratings yet
Algorithms Laboratory Record
48 pages
C Programs for Search and Sort Algorithms
PDF
No ratings yet
C Programs for Search and Sort Algorithms
42 pages
C Programs for Search and Sort Algorithms
PDF
No ratings yet
C Programs for Search and Sort Algorithms
58 pages
Algorithms Laboratory Record 2024
PDF
No ratings yet
Algorithms Laboratory Record 2024
90 pages
Algorithm Laboratory Experiments Guide
PDF
No ratings yet
Algorithm Laboratory Experiments Guide
46 pages
DAA Lab Manual for BCS-553 Course
PDF
No ratings yet
DAA Lab Manual for BCS-553 Course
32 pages
Data Structures: Search and Sort Algorithms
PDF
No ratings yet
Data Structures: Search and Sort Algorithms
18 pages
Cs3401 Lab Manual (New)
PDF
No ratings yet
Cs3401 Lab Manual (New)
50 pages
Searching and Sorting Algorithms Overview
PDF
No ratings yet
Searching and Sorting Algorithms Overview
26 pages
DAA Lab Manual: Sorting Algorithms
PDF
No ratings yet
DAA Lab Manual: Sorting Algorithms
39 pages
Searching and Sorting Algorithms Guide
PDF
No ratings yet
Searching and Sorting Algorithms Guide
41 pages
Data Structures and Algorithms Lab Guide
PDF
No ratings yet
Data Structures and Algorithms Lab Guide
54 pages
Insertion Sort and Search Algorithms
PDF
No ratings yet
Insertion Sort and Search Algorithms
24 pages
Sorting and Searching Algorithms Guide
PDF
No ratings yet
Sorting and Searching Algorithms Guide
26 pages
Linear and Binary Search Algorithms
PDF
No ratings yet
Linear and Binary Search Algorithms
9 pages
Data Structures Assignment Solutions Guide
PDF
No ratings yet
Data Structures Assignment Solutions Guide
37 pages
Searching Algorithms in Data Structures
PDF
100% (1)
Searching Algorithms in Data Structures
50 pages
Algorithm Lab Report: Sorting & Searching
PDF
No ratings yet
Algorithm Lab Report: Sorting & Searching
23 pages
C Programs for Search and Sort Algorithms
PDF
No ratings yet
C Programs for Search and Sort Algorithms
32 pages
C++ Searching Techniques: Linear & Binary
PDF
No ratings yet
C++ Searching Techniques: Linear & Binary
9 pages
Search and Sort Algorithms Implementation
PDF
No ratings yet
Search and Sort Algorithms Implementation
51 pages
CS3401 Algorithms Lab Manual
PDF
No ratings yet
CS3401 Algorithms Lab Manual
43 pages
Searching and Sorting Algorithms in C
PDF
No ratings yet
Searching and Sorting Algorithms in C
3 pages
C Programs for Search and Sort Algorithms
PDF
No ratings yet
C Programs for Search and Sort Algorithms
99 pages
Cs3401 - Algorithms Lab Manual
PDF
No ratings yet
Cs3401 - Algorithms Lab Manual
61 pages
Data Structures: Searching Algorithms Overview
PDF
No ratings yet
Data Structures: Searching Algorithms Overview
52 pages
Algorithms A
PDF
No ratings yet
Algorithms A
61 pages
C Programming Algorithms Laboratory Record
PDF
No ratings yet
C Programming Algorithms Laboratory Record
35 pages
C Program for Search and Sort Algorithms
PDF
No ratings yet
C Program for Search and Sort Algorithms
50 pages
Insert and Delete in Sorted Arrays
PDF
No ratings yet
Insert and Delete in Sorted Arrays
99 pages
Data Structures & Algorithms Overview
PDF
No ratings yet
Data Structures & Algorithms Overview
82 pages
Unit-1 1.searching Sorting Techniques
PDF
No ratings yet
Unit-1 1.searching Sorting Techniques
19 pages
Searching and Sorting Algorithms Overview
PDF
No ratings yet
Searching and Sorting Algorithms Overview
57 pages
C Searching and Sorting Techniques
PDF
No ratings yet
C Searching and Sorting Techniques
44 pages
Algorithm Lab 115014
PDF
No ratings yet
Algorithm Lab 115014
79 pages
C Programs for Search and Sort Algorithms
PDF
No ratings yet
C Programs for Search and Sort Algorithms
55 pages
Cs3401 Manual
PDF
No ratings yet
Cs3401 Manual
26 pages
C Array Manipulation and Search Techniques
PDF
No ratings yet
C Array Manipulation and Search Techniques
95 pages
Search and Sort Algorithms Overview
PDF
No ratings yet
Search and Sort Algorithms Overview
11 pages
Binary Search and Sorting Algorithms
PDF
No ratings yet
Binary Search and Sorting Algorithms
64 pages
Design and Anal Lab Record 2023 12 20
PDF
No ratings yet
Design and Anal Lab Record 2023 12 20
58 pages
Array Algorithms: Traversal, Insertion, Deletion
PDF
No ratings yet
Array Algorithms: Traversal, Insertion, Deletion
15 pages
Searching and Sorting Algorithms Guide
PDF
No ratings yet
Searching and Sorting Algorithms Guide
84 pages
Experiment List for Search and Sort Algorithms
PDF
No ratings yet
Experiment List for Search and Sort Algorithms
72 pages
Exercise1 Array Manipulation
PDF
No ratings yet
Exercise1 Array Manipulation
21 pages
Algoritmos de Busca em Estruturas de Dados
PDF
No ratings yet
Algoritmos de Busca em Estruturas de Dados
4 pages
C Programs for Search and Sort Algorithms
PDF
No ratings yet
C Programs for Search and Sort Algorithms
37 pages
FALLSEM2025 26 VL BCSE202L 00100 TH 2025-08-08 Module 3 Searching and Sorting
PDF
No ratings yet
FALLSEM2025 26 VL BCSE202L 00100 TH 2025-08-08 Module 3 Searching and Sorting
22 pages
Android Resources Organizing
PDF
No ratings yet
Android Resources Organizing
5 pages
Freewriting Techniques for Writers
PDF
No ratings yet
Freewriting Techniques for Writers
2 pages
Animation in Android With Example
PDF
No ratings yet
Animation in Android With Example
12 pages
Classification of Psychological Disorders
PDF
No ratings yet
Classification of Psychological Disorders
11 pages
Understanding Generators and Motors
PDF
No ratings yet
Understanding Generators and Motors
15 pages