[PDF] [PDF] CSE 1321L: Programming and Problem Solving I Lab Lab 8

Overview: In the last lab, you worked with 1D arrays to perform basic operations going to build on those concepts to better understand searching and sorting (i e filenames should be Lab8A( java, cs or cpp)) and class names should be 



Previous PDF Next PDF





[PDF] 1D Arrays (Searching and Sorting Methods)

2 Sorting Methods on 1D Array • The efficiency of data handling can often be substantially increased if the data are sorted according to some criteria of order



[PDF] 1D Arrays

11 Write a simple complete Java program merge java to merge two sorted arrays of integers a with m elements and b with n elements into a sorted array of 



[PDF] CSE 1321L: Programming and Problem Solving I Lab Lab 8

Overview: In the last lab, you worked with 1D arrays to perform basic operations going to build on those concepts to better understand searching and sorting (i e filenames should be Lab8A( java, cs or cpp)) and class names should be 



[PDF] Single-Dimensional Arrays

This section introduces how to declare array variables, create arrays, and Java has a shorthand notation, known as the array initializer that combines declaring an The Arrays sort Method: Since sorting is frequently used in programming, 



[PDF] Chapter 22 Working with Arrays

java util Arrays sort(numberList); // Sort the array or, if java util Arrays is of the first occurrence of a given element in a 1D array of integers; if the element is not



[PDF] Lab Manual

Programming practice on sort methods for sorting array elements Instructor Java by John R Hubbard and also the relevant instructor's slides Names I D 1 Ex-2 (home activity): (Sales Commissions) Use a one-dimensional array to solve 



[PDF] Java with BlueJ Part 2 - Applied Computer Science

27 mar 2016 · CHAPTER 1 ONE-DIMENSIONAL ARRAYS Example 6 Sorting and searching an array The interested student is referred to the Java Class 





Mathematical Notation

ally implemented as one-dimensional arrays, with elements being referred to Arrays can be sorted quickly using the static utility methods in the java util Arrays  



[PDF] JAVA PROGRAMMING LAB

When passing an array to a method, the reference of the array is passed to the Sorting, like searching, is a common task in computer programming Many A two-dimensional array consists of an array of one-dimensional arrays and a three

[PDF] sort array of array in javascript

[PDF] sources of aerosols

[PDF] sources of labour law

[PDF] sources of law

[PDF] soustraction avec retenue

[PDF] south africa allies or blocs

[PDF] south africa population 2019

[PDF] south africa population 2019 by race

[PDF] south africa trade agreements

[PDF] south africa's trade policy

[PDF] south america way

[PDF] south korea trade deal

[PDF] south korea trade policy

[PDF] southeast asia airport codes

[PDF] southern country international bank

Page 1 of 3

CSE 1321L: Programming and Problem Solving I Lab

Lab 8

Searching and Sorting Algorithms

What students will learn:

Declaring and initializing 1D arrays (review)

Searching arrays using different techniques

How to visualize searching and sorting

Overview: In the last lab, you worked with 1D arrays to perform basic operations (e.g. initializing going to build on those concepts to better understand searching and sorting.

Recall from lecture that we studied two different ways to search a 1D array of n elements (e.g. if there

are 10 elements in the array, then n searching for is called the target. If the data is unsorted, then a linear search is required which scans across all elements and therefore However, if the data is sorted, you can run a binary search. This search starts in

the middle of the array and compares it with the target. If the target is greater than that element, then

we know to search the right half of the array. If not, we search the left half of the array (or we found

the element). progressively working on less and less data. This search runs in log2n, which is unbelievably fast.

The three most common

For th

count the number of total swaps that this sort has done as well as visualize the array after the inner

loop has finished. print the array and the total number of swaps that have occurred. As always, your filenames and class names should follow the conventions used all semester (i.e. filenames should be Lab8A(.java, .cs or .cpp)) and class names should be either Lab8A or

Lab8B.

visualize the state of the array (or values of counters).

Page 2 of 3

Lab8A: For this part of the lab, refer to the lecture slides for a review of Bubble Sort.

Practice re-coding the program given in lecture.

Write a program that prompts the user to enter 10 numbers and stores the input in a 1D array of size

10. Now, use Bubble Sort to sort the arraycontinuously pushing the largest elements to the right

side of the array. Every time you swap two elements in the array, you need to increment a counter.

After the inner loop has completed, you need to print out the current state of the array and the total

number of swaps that have occurred. The sample outputs are shown below and the user input is in bold. the number of swaps.

Sample output #1

Enter slot 0: 10

Enter slot 1: 9

Enter slot 2: 8

Enter slot 3: 7

Enter slot 4: 6

Enter slot 5: 5

Enter slot 6: 4

Enter slot 7: 3

Enter slot 8: 2

Enter slot 9: 1

9|8|7|6|5|4|3|2|1|10| Num swaps: 9

8|7|6|5|4|3|2|1|9|10| Num swaps: 17

7|6|5|4|3|2|1|8|9|10| Num swaps: 24

6|5|4|3|2|1|7|8|9|10| Num swaps: 30

5|4|3|2|1|6|7|8|9|10| Num swaps: 35

4|3|2|1|5|6|7|8|9|10| Num swaps: 39

3|2|1|4|5|6|7|8|9|10| Num swaps: 42

2|1|3|4|5|6|7|8|9|10| Num swaps: 44

1|2|3|4|5|6|7|8|9|10| Num swaps: 45

1|2|3|4|5|6|7|8|9|10| Num swaps: 45

Sample output #2

Enter slot 0: 5

Enter slot 1: 10

Enter slot 2: 8

Enter slot 3: 2

Enter slot 4: 1

Enter slot 5: 6

Enter slot 6: 7

Enter slot 7: 3

Enter slot 8: 9

Enter slot 9: 4

5|8|2|1|6|7|3|9|4|10| Num swaps: 8

5|2|1|6|7|3|8|4|9|10| Num swaps: 14

2|1|5|6|3|7|4|8|9|10| Num swaps: 18

1|2|5|3|6|4|7|8|9|10| Num swaps: 21

1|2|3|5|4|6|7|8|9|10| Num swaps: 23

1|2|3|4|5|6|7|8|9|10| Num swaps: 24

1|2|3|4|5|6|7|8|9|10| Num swaps: 24

1|2|3|4|5|6|7|8|9|10| Num swaps: 24

1|2|3|4|5|6|7|8|9|10| Num swaps: 24

1|2|3|4|5|6|7|8|9|10| Num swaps: 24

Page 3 of 3

Lab8B: For this part of the lab, you will practice using Linear Search and Binary Search. Please review the lecture slides and try to re-code them. The goal of this lab is for you to perform these two searches and visualize the behavior. For this first part of the lab, write a program that prompts the user to enter 15 numbers in sorted order (meaning the user enters them in ascending order). Store the inputted numbers into a 1D array of size 15. Then, ask the user for a number to search for in the array (i.e. th

Now, print the array.

Next, use Linear Search to search the array. Print out each of the indices being examined until the algorithm finds the target. Finally, use Binary Search to search the array. Print out each of the indices are being examined until the algorithm finds the target. indices of a linear search and 3) the indices of a binary search. Your output should look like the sample output below. User input is in bold.

Sample output #1

Enter slot 0: 0

Enter slot 1: 1

Enter slot 2: 2

Enter slot 3: 3

Enter slot 4: 4

Enter slot 5: 5

Enter slot 6: 6

Enter slot 7: 7

Enter slot 8: 8

Enter slot 9: 9

Enter slot 10: 10

Enter slot 11: 11

Enter slot 12: 12

Enter slot 13: 13

Enter slot 14: 14

Enter a target: 15

0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14

7 11 13 14

Sample output #2

Enter slot 0: 3

Enter slot 1: 11

Enter slot 2: 45

Enter slot 3: 57

Enter slot 4: 81

Enter slot 5: 125

Enter slot 6: 129

Enter slot 7: 311

Enter slot 8: 333

Enter slot 9: 361

Enter slot 10: 402

Enter slot 11: 412

Enter slot 12: 475

Enter slot 13: 499

Enter slot 14: 501

Enter a target: 402

0 1 2 3 4 5 6 7 8 9 10

7 11 9 10

Instructions:

Programs must be working correctly.

Programs must be saved in files with the correct file name. If working in Java or C#, class names must be correct. Programs must be working and checked by the end of the designated lab session. Programs (.java, .cs or .cpp files) must be uploaded to Gradescope by due date.quotesdbs_dbs17.pdfusesText_23