Location via proxy:
[ UP ]
[Report a bug]
[Manage cookies]
No cookies
No scripts
No ads
No referrer
Show this form
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)
13 views
Searching Sorting Algorithm
Searching Sorting Algorithm in Data Structure
Uploaded by
zaini.iqbal761
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Searching Sorting Algorithm For Later
Download
Save
Save Searching Sorting Algorithm For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
13 views
Searching Sorting Algorithm
Searching Sorting Algorithm in Data Structure
Uploaded by
zaini.iqbal761
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Searching Sorting Algorithm For Later
Carousel Previous
Carousel Next
Save
Save Searching Sorting Algorithm For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 13
Search
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 | 0bj.Input(); 4 ab “Max = obj.search(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 into.hash 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 index.in 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 obj.son(), 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 array.ABC 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:
; Sa ‘4 : _ #include
: quicksori(intQ, int int); r int partition(int 4, int, ‘int y “void main(void) Wa ce:change their order PE) EE) © 36 41 | 45 2 In the second step, we compare lists of two data values and merge them into another of data Values placing all in sorted order 19°) 45 | 29 | 34 17 ] 36 | a1 45 3. In the third step, we compare lists of four data values, and merge them into another lis date values We get the sorted list of data values. 15/17 | 29 | 34 | 36 | 41 | 45 A os RS LULL ‘ Write an algorithm that sorts an array ARR which consists of N elememes merge sort. + START rank 2 \F array ARR has only one element, itis already sorted, THEN EXIT : ‘. * ELSE ' ee Dividé the array recursively into two halves until it cannot be * divided ’ END IF a 3. Merge the smaller sub-arrays into a new array in sorted order : 4 EXIT ey, : When an array of an odd number of elements is divided into two sub-arrays. them second sub-array will have one more element than the first sub-array. For example, the array clements 8 is divided into two sub-arrays of equal lengths, i.e, each having 4 elements. Howes f the length of an array is 9, ‘then the first sub-array will have 4 elements and the second 2 vill have 5 elements, //Program to sort array with 6 elements by using merge sorting methog #include
> * #include
void MergeSort(int (, int, int); void Merge(int (}, int, int, int); c
You might also like
Data Structures & Algorithms: Lecture # 6
PDF
No ratings yet
Data Structures & Algorithms: Lecture # 6
26 pages
Module 5 Basic Algorithm
PDF
No ratings yet
Module 5 Basic Algorithm
11 pages
Unit II Searching
PDF
No ratings yet
Unit II Searching
40 pages
DFS Lab File Final
PDF
No ratings yet
DFS Lab File Final
99 pages
Dsu Chapter
PDF
No ratings yet
Dsu Chapter
37 pages
Binary Search
PDF
No ratings yet
Binary Search
10 pages
Searching and Sorting Updated
PDF
No ratings yet
Searching and Sorting Updated
57 pages
Algo Assignment-P2 Binary SRCH
PDF
No ratings yet
Algo Assignment-P2 Binary SRCH
7 pages
Notes On Search
PDF
No ratings yet
Notes On Search
11 pages
PF Chapter 4 - PART 1 - Arrays and Struct
PDF
No ratings yet
PF Chapter 4 - PART 1 - Arrays and Struct
29 pages
Adobe Scan 11 Dec 2024
PDF
No ratings yet
Adobe Scan 11 Dec 2024
25 pages
Chapter 2
PDF
No ratings yet
Chapter 2
9 pages
ALGORITHMS LAB MANUAL - Updated
PDF
No ratings yet
ALGORITHMS LAB MANUAL - Updated
47 pages
Data Structures Se E&Tc List of Practicals
PDF
No ratings yet
Data Structures Se E&Tc List of Practicals
23 pages
Binary Search Algorithm Assignment
PDF
No ratings yet
Binary Search Algorithm Assignment
5 pages
DS_Unit 3
PDF
No ratings yet
DS_Unit 3
29 pages
DAA Lab Manual
PDF
No ratings yet
DAA Lab Manual
49 pages
Dsa Lab 2
PDF
No ratings yet
Dsa Lab 2
9 pages
Ds V UNIT
PDF
No ratings yet
Ds V UNIT
17 pages
13 Standard Algorithms: 13.1 Finding The Right Element: Binary Search
PDF
No ratings yet
13 Standard Algorithms: 13.1 Finding The Right Element: Binary Search
26 pages
Question: (IN C WITH COMMENTS) The Binary Search Algorithm That Foll
PDF
No ratings yet
Question: (IN C WITH COMMENTS) The Binary Search Algorithm That Foll
2 pages
Chapter 3 Stacks
PDF
No ratings yet
Chapter 3 Stacks
51 pages
Data
PDF
No ratings yet
Data
29 pages
LabManual 23967 Content Document 20240909125727PM
PDF
No ratings yet
LabManual 23967 Content Document 20240909125727PM
11 pages
DS-ass1
PDF
No ratings yet
DS-ass1
20 pages
Algorithms and Data Structures Sorting Algorithms
PDF
No ratings yet
Algorithms and Data Structures Sorting Algorithms
5 pages
M.Tech JNTUK ADS UNIT-2
PDF
100% (1)
M.Tech JNTUK ADS UNIT-2
20 pages
EENG212 - Algorithms & Data Structures
PDF
No ratings yet
EENG212 - Algorithms & Data Structures
5 pages
Week 7
PDF
No ratings yet
Week 7
72 pages
Searching Techniques
PDF
No ratings yet
Searching Techniques
17 pages
Operations On Arrays in DS
PDF
No ratings yet
Operations On Arrays in DS
15 pages
DATA STRUCTURES DIGITAL NOTES-72-81
PDF
No ratings yet
DATA STRUCTURES DIGITAL NOTES-72-81
10 pages
best sorting notes
PDF
No ratings yet
best sorting notes
19 pages
C UNIT-5
PDF
No ratings yet
C UNIT-5
41 pages
Module-1 (Searching & Sorting)
PDF
No ratings yet
Module-1 (Searching & Sorting)
27 pages
Introduction To Searching Algorithms
PDF
No ratings yet
Introduction To Searching Algorithms
27 pages
13
PDF
No ratings yet
13
32 pages
MCA I Handout 11 2013
PDF
No ratings yet
MCA I Handout 11 2013
12 pages
07-Linear and Binary Search
PDF
No ratings yet
07-Linear and Binary Search
81 pages
A7e55228 1639798147383
PDF
No ratings yet
A7e55228 1639798147383
36 pages
CS3401- Algorithm lab Manual
PDF
No ratings yet
CS3401- Algorithm lab Manual
73 pages
1 Module 5
PDF
No ratings yet
1 Module 5
65 pages
Chapter Two
PDF
No ratings yet
Chapter Two
26 pages
Unit 3
PDF
No ratings yet
Unit 3
32 pages
2 - Search SortArrays
PDF
No ratings yet
2 - Search SortArrays
36 pages
SORTINGS
PDF
No ratings yet
SORTINGS
22 pages
DSA Ch2
PDF
No ratings yet
DSA Ch2
44 pages
Searching Techniques
PDF
No ratings yet
Searching Techniques
20 pages
Exp 1
PDF
No ratings yet
Exp 1
8 pages
Atik
PDF
No ratings yet
Atik
8 pages
105365_10_19UCSES301_A_7_29Unit V Module (1) (1)
PDF
No ratings yet
105365_10_19UCSES301_A_7_29Unit V Module (1) (1)
23 pages
c++ Searching
PDF
No ratings yet
c++ Searching
5 pages
Unit 5 SearchingSortingHashing PDF
PDF
No ratings yet
Unit 5 SearchingSortingHashing PDF
53 pages
01 - Ca2 - Bcac 303
PDF
No ratings yet
01 - Ca2 - Bcac 303
21 pages
Lab
PDF
No ratings yet
Lab
14 pages
Binary Search
PDF
100% (1)
Binary Search
19 pages
Chapter 2 - Searching & Sorting Algorithm
PDF
No ratings yet
Chapter 2 - Searching & Sorting Algorithm
9 pages
Unit 5
PDF
No ratings yet
Unit 5
13 pages
Lab 8 Description
PDF
No ratings yet
Lab 8 Description
20 pages
Related titles
Click to expand Related Titles
Carousel Previous
Carousel Next
Data Structures & Algorithms: Lecture # 6
PDF
Data Structures & Algorithms: Lecture # 6
Module 5 Basic Algorithm
PDF
Module 5 Basic Algorithm
Unit II Searching
PDF
Unit II Searching
DFS Lab File Final
PDF
DFS Lab File Final
Dsu Chapter
PDF
Dsu Chapter
Binary Search
PDF
Binary Search
Searching and Sorting Updated
PDF
Searching and Sorting Updated
Algo Assignment-P2 Binary SRCH
PDF
Algo Assignment-P2 Binary SRCH
Notes On Search
PDF
Notes On Search
PF Chapter 4 - PART 1 - Arrays and Struct
PDF
PF Chapter 4 - PART 1 - Arrays and Struct
Adobe Scan 11 Dec 2024
PDF
Adobe Scan 11 Dec 2024
Chapter 2
PDF
Chapter 2
ALGORITHMS LAB MANUAL - Updated
PDF
ALGORITHMS LAB MANUAL - Updated
Data Structures Se E&Tc List of Practicals
PDF
Data Structures Se E&Tc List of Practicals
Binary Search Algorithm Assignment
PDF
Binary Search Algorithm Assignment
DS_Unit 3
PDF
DS_Unit 3
DAA Lab Manual
PDF
DAA Lab Manual
Dsa Lab 2
PDF
Dsa Lab 2
Ds V UNIT
PDF
Ds V UNIT
13 Standard Algorithms: 13.1 Finding The Right Element: Binary Search
PDF
13 Standard Algorithms: 13.1 Finding The Right Element: Binary Search
Question: (IN C WITH COMMENTS) The Binary Search Algorithm That Foll
PDF
Question: (IN C WITH COMMENTS) The Binary Search Algorithm That Foll
Chapter 3 Stacks
PDF
Chapter 3 Stacks
Data
PDF
Data
LabManual 23967 Content Document 20240909125727PM
PDF
LabManual 23967 Content Document 20240909125727PM
DS-ass1
PDF
DS-ass1
Algorithms and Data Structures Sorting Algorithms
PDF
Algorithms and Data Structures Sorting Algorithms
M.Tech JNTUK ADS UNIT-2
PDF
M.Tech JNTUK ADS UNIT-2
EENG212 - Algorithms & Data Structures
PDF
EENG212 - Algorithms & Data Structures
Week 7
PDF
Week 7
Searching Techniques
PDF
Searching Techniques
Operations On Arrays in DS
PDF
Operations On Arrays in DS
DATA STRUCTURES DIGITAL NOTES-72-81
PDF
DATA STRUCTURES DIGITAL NOTES-72-81
best sorting notes
PDF
best sorting notes
C UNIT-5
PDF
C UNIT-5
Module-1 (Searching & Sorting)
PDF
Module-1 (Searching & Sorting)
Introduction To Searching Algorithms
PDF
Introduction To Searching Algorithms
13
PDF
13
MCA I Handout 11 2013
PDF
MCA I Handout 11 2013
07-Linear and Binary Search
PDF
07-Linear and Binary Search
A7e55228 1639798147383
PDF
A7e55228 1639798147383
CS3401- Algorithm lab Manual
PDF
CS3401- Algorithm lab Manual
1 Module 5
PDF
1 Module 5
Chapter Two
PDF
Chapter Two
Unit 3
PDF
Unit 3
2 - Search SortArrays
PDF
2 - Search SortArrays
SORTINGS
PDF
SORTINGS
DSA Ch2
PDF
DSA Ch2
Searching Techniques
PDF
Searching Techniques
Exp 1
PDF
Exp 1
Atik
PDF
Atik
105365_10_19UCSES301_A_7_29Unit V Module (1) (1)
PDF
105365_10_19UCSES301_A_7_29Unit V Module (1) (1)
c++ Searching
PDF
c++ Searching
Unit 5 SearchingSortingHashing PDF
PDF
Unit 5 SearchingSortingHashing PDF
01 - Ca2 - Bcac 303
PDF
01 - Ca2 - Bcac 303
Lab
PDF
Lab
Binary Search
PDF
Binary Search
Chapter 2 - Searching & Sorting Algorithm
PDF
Chapter 2 - Searching & Sorting Algorithm
Unit 5
PDF
Unit 5
Lab 8 Description
PDF
Lab 8 Description