Presentation is loading. Please wait.

Presentation is loading. Please wait.

OCR A Level F453: 3.3.5 Data structures and data manipulation 3.3.5 Data structures and data manipulation a. explain how static data structures may be.

Similar presentations


Presentation on theme: "OCR A Level F453: 3.3.5 Data structures and data manipulation 3.3.5 Data structures and data manipulation a. explain how static data structures may be."— Presentation transcript:

1 OCR A Level F453: 3.3.5 Data structures and data manipulation 3.3.5 Data structures and data manipulation a. explain how static data structures may be used to implement dynamic data structures; b. describe algorithms for the insertion, retrieval and deletion of data items stored in stack, queue and tree structures; c. explain the difference between binary searching and serial searching, highlighting the advantages and disadvantages of each; d. explain how to merge data files; e. explain the differences between the insertion and quick sort methods, highlighting the characteristics, advantages and disadvantages of each.

2 c. explain the difference between binary searching and serial searching, highlighting the advantages and disadvantages of each; OCR A Level F453: 3.3.5 Data structures and data manipulation

3 Serial search: Starts at one end of the list and checks every item to see if it is the one being looked for. This is very slow but is the only method it’s possible to use if the items are in a random order. Binary search: Can be used if the items in the list is ordered. It starts by checking the middle item. If this is higher than the item being searched for then the bottom half of the list is taken and the process is repeated. This happens until the item is found. Serial & Binary searching OCR A Level F453: 3.3.5 Data structures and data manipulation

4 d. explain how to merge data files; OCR A Level F453: 3.3.5 Data structures and data manipulation

5 Imagine you have two lists of names that you want to merge. The aim is to combine the two lists together whilst ensuring everything is in the correct order. This process is called merging. List 1: A, B, F, H, Z List 2: D, E, F, G, I Merged list: A, B, D, E, F, F, G, H, I, Z Notice that the merged list contains all the letters from both lists in the correct (alphabetical) order. Merging data files OCR A Level F453: 3.3.5 Data structures and data manipulation

6 e. explain the differences between the insertion and quick sort methods, highlighting the characteristics, advantages and disadvantages of each. OCR A Level F453: 3.3.5 Data structures and data manipulation

7 Insertion sort works by splitting a list into two sections, a sorted one and an unsorted one. Elements from the unsorted list are compared to the first item in the sorted list. If they are smaller they are swapped otherwise they remain in the same position. By repeating this process the sorted list grows larger and the unsorted list smaller. Until only the sorted list is left. This is best demonstrated using a video: http://www.youtube.com/watch?v=c4BRHC7kTaQ Insertion sort OCR A Level F453: 3.3.5 Data structures and data manipulation

8 Insertion sort 12311492 In this example the sorted list is white, the unsorted list grey and the item currently being compared is blue. Step 1: The leftmost number is said to be sorted, it’s by itself so it must be sorted. Step 2: Compare the next number (31) to the first number in the sorted list. If it’s smaller then swap them round, otherwise leave them as they are. Step 3: Move on to the next number (14) and compare this to the first number in the sorted list. Step 4: 14 is smaller than 31 so they are swapped. But 13 is larger than 12 so they stay the same. Step 5: Finally the last item in the unsorted list (92) is checked against the first item of the sorted list. It’s larger so they are not swapped. Sorted! 12311492 12311492 12311492 12311492 OCR A Level F453: 3.3.5 Data structures and data manipulation

9 1. Pick a random element of the array to be the Pivot. 2. Pick leftmost element of the array and the rightmost element. 3. If the item at the left of the array is less than the pivot it stays where it is and the next element along is selected. This step is repeated until the left pointer is pointing to an item that is greater than the pivot. 4. If the item at the right of the array is greater than the pivot it stays where it is and the next element along is selected. This step is repeated until the right pointer is pointing to an item that is less than the pivot. 5. When the left pointer is holding a value greater than the pivot AND the right most pointer is holding a value less than the pivot these two items are swapped. Quick sort OCR A Level F453: 3.3.5 Data structures and data manipulation

10 6. This process is repeated until the list has every item less than the pivot on the left and every item greater than the pivot on the right. 7. Quick sort now splits the list in half so you have two separate lists. One containing all the values less than the pivot the other containing all the values more than the pivot. Steps 1-7 are now repeated for each of these sub-lists. They keep being repeated until each sub list contains just one element. Then the lists are reassembled to give a list with all the items sorted. This sounds complicated but isn't really. It’s easier to understand by watching a video though: http://www.youtube.com/watch?v=y_G9BkAm6B8http://www.youtube.com/watch?v=y_G9BkAm6B8 Quick sort OCR A Level F453: 3.3.5 Data structures and data manipulation

11 Insertion sort: Very simple to implement and are quicker for small data sets. Quick sort: More complex to implement but much, much faster for large data sets Advantages & disadvantages OCR A Level F453: 3.3.5 Data structures and data manipulation


Download ppt "OCR A Level F453: 3.3.5 Data structures and data manipulation 3.3.5 Data structures and data manipulation a. explain how static data structures may be."

Similar presentations


Ads by Google