0% found this document useful (0 votes)
75 views4 pages

Pseudocode For Sorting N Numbers of Data Using Bubble Sort

The document contains pseudocode for several sorting and sequence generation algorithms: bubble sort, selection sort, insertion sort, finding prime numbers, Pascal's triangle, and the Fibonacci sequence. For each, it declares variables, reads input, performs the sorting/generation logic through loops and conditional statements, and outputs the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views4 pages

Pseudocode For Sorting N Numbers of Data Using Bubble Sort

The document contains pseudocode for several sorting and sequence generation algorithms: bubble sort, selection sort, insertion sort, finding prime numbers, Pascal's triangle, and the Fibonacci sequence. For each, it declares variables, reads input, performs the sorting/generation logic through loops and conditional statements, and outputs the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Pseudocode for sorting n numbers of data using bubble sort

1. Declare variable i, j, and counter as integer

2. Declare variable bubble as an array with the size of integer n

3. Read input and save them to bubble array

4. If n < 1

5. Write “please give more input”

6. Repeat to step 3

7. If n = 1

8. Print the element of bubble array

9. For i = 1 to n

10. For j = 1 to n-1

11. Set counter = 0

12. If bubble[j] is larger than bubble[j+1]

13. Switch the value of bubble[j] and bubble[j+1]

14. Increase counter by 1

15. Increase j by 1

16. If counter = 0

17. Break out of the loop

18. Else increase i by 1

19. Print all elements of bubble array

Pseudocode for sorting n numbers of data using selection sort

1. Declare variable i, j, and min as integer

2. Declare variable selection as an array with the size of integer n

3. Read input and save it to selection array

4. If n < 1

5. Write “please give more numbers”

6. Repeat step 3
7. If n = 1

8. Print the element of selection array

9. For i = 1 to n-1

10. Set min = i

11. For j = i + 1 to n

12. If jth element of selection is less than minth element of selection

13. Set min equals to j

14. Increase j by 1

15. Increase i by 1

16. Print all elements of selection

Pseudocode for sorting n numbers of data using insertion sort with two arrays

1. Declare variable

2. Declare variable insertion as an array with the size of integer m

3. Declare variable unsorted as an array with the size of integer n

4. Read input and save it to unsorted array

5. Set m equals to n

6. If n < 1

7. Write “give more input, please”

8. Repeat to step 3

9. If n = 1

10. Print the element of unsorted array

11. Set insertion[1] equals to unsorted[1]

12. For i = 1 to n

13. For j = 1 to i

14. If insertion[j] is higher than unsorted[i]

15. Set k equals to j

16. While k < i


17. Set insertion[k+1] equals to insertion[k]

18. Increase j by 1

19. Increase i by 1

20. Print all elements of insertion array

Pseudocode of finding first n prime number

1. Declare variable i, j as integer

2. Declare variable prime as an array with the size of integer n

3. Input how many prime numbers to be printed and save it to variable n

4. If n < 1

5. Write “must be higher than or equal to 1”

6. Repeat step 3 until n>1

7. Set prime[1] equals to 2

8. If n = 1

9. Write elements of prime

10. Else j = prime[1]+1

11. For i = 2 to n

12. If j mod all elements of prime is not zero

13. prime[i] = j

14. Increase i by 1

15. Increase j by 1

16. Write all elements of prime

Pseudocode for generating Pascal Triangle

1. Declare variable i, j as integer

2. Declare variable pascal as an array with the size of integer r and c

3. Input the size of Pascal Triangle and save the value to r and c

4. If r < 1

5. Write “must be higher than or equal to 1”


6. Repeat to step 3 until r > 1

7. For i = 1 to r

8. For j = 1 to c

9. If j = 1 or j = i

10. Set pascal[i,j] equals to 1

11. Else pascal[i,j] = pascal[i-1,j-1] + pascal[i-1,j]

12. Increase j by 1

13. Increase i by 1

14. Write all elements of pascal

Pseudocode for generating the first n Fibonacci sequence

1. Declare variable i as integer

2. Declare variable fibonacci as array with the size of integer n

3. Input how many numbers of Fibonacci sequence to be printed and save the value to n

4. If n < 1

5. Write “must be greater than or equal to 1”

6. Repeat step 3 until n >=1

7. For i = 1 to n

8. If i < 3

9. fibonacci[i] = 1

10. Else fibonacci[i] = fibonacci[i-1] + fibonacci[i-2]

11. Increase i by 1

12. Write all elements of fibonacci

You might also like