Exam practice. Exam 1  Describe how a Boolean expression can control the operation of a loop  Describe the difference between a while loop and for loop.

Slides:



Advertisements
Similar presentations
Order of complexity. Consider four algorithms 1.The naïve way of adding the numbers up to n 2.The smart way of adding the numbers up to n 3.A binary search.
Advertisements

Recursion Chapter 14. Overview Base case and general case of recursion. A recursion is a method that calls itself. That simplifies the problem. The simpler.
Back to Sorting – More efficient sorting algorithms.
Equality Join R X R.A=S.B S : : Relation R M PagesN Pages Relation S Pr records per page Ps records per page.
Jyotishka Datta STAT 598Z – Sorting. Insertion Sort If the first few objects are already sorted, an unsorted object can be inserted in the sorted set.
Data Structures: A Pseudocode Approach with C 1 Chapter 5 Contd... Objectives Explain the design, use, and operation of a linear list Implement a linear.
Lesson Plan - 2: Bubble Sort, Quick Sort
CPS120: Introduction to Computer Science Searching and Sorting.
Search algorithm In computer science, a search algorithm is an algorithm that takes a problem as input and returns a solution to the problem, usually after.
Introduction to Data Structures and Algorithms Chapter 7 Quick Sort.
 1 Sorting. For computer, sorting is the process of ordering data. [ ]  [ ] [ “Tom”, “Michael”, “Betty” ]  [ “Betty”, “Michael”,
Computation for Physics 計算物理概論 Algorithm. An algorithm is a step-by-step procedure for calculations. Algorithms are used for calculation, data processing,
Algorithm An algorithm is a step-by-step set of operations to be performed. Real-life example: a recipe Computer science example: determining the mode.
Ver. 1.0 Session 5 Data Structures and Algorithms Objectives In this session, you will learn to: Sort data by using quick sort Sort data by using merge.
Flow Charting, Structured English and PseudoCode
General Computer Science for Engineers CISC 106 Lecture 08
Computer Programming Sorting and Sorting Algorithms 1.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (3) Recurrence Relation 11/11 ~ 11/14/2008 Yang Song.
Sorting and Searching Algorithms Week 11 DSA. Recap etc. Arrays are lists of data 1-D, 2-D etc. Lists associated with searching and sorting Other structures.
1 Two-Dimensional Arrays. 2 Can be visualized as consisting m rows, each of n columns Syntax: datatype arrayname [row] [ column] ; Example: int val[3]
Fall 2013 Instructor: Reza Entezari-Maleki Sharif University of Technology 1 Fundamentals of Programming Session 17 These.
Fall 2013 Instructor: Reza Entezari-Maleki Sharif University of Technology 1 Fundamentals of Programming Session 17 These.
HKOI 2006 Intermediate Training Searching and Sorting 1/4/2006.
Computer Science Searching & Sorting.
Merge Sort. What Is Sorting? To arrange a collection of items in some specified order. Numerical order Lexicographical order Input: sequence of numbers.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 19: Searching and Sorting.
SEARCHING. Vocabulary List A collection of heterogeneous data (values can be different types) Dynamic in size Array A collection of homogenous data (values.
LAB#7. Insertion sort In the outer for loop, out starts at 1 and moves right. It marks the leftmost unsorted data. In the inner while loop, in starts.
© M. Gross, ETH Zürich, 2014 Informatik I für D-MAVT (FS 2014) Exercise 12 – Data Structures – Trees Sorting Algorithms.
LAB#6. 2 Overview Before we go to our lesson we must know about : 1. data structure. 2.Algorithms. data structure is an arrangement of data in a computer.
1 Introduction to Sorting Algorithms Sort: arrange values into an order Alphabetical Ascending numeric Descending numeric Two algorithms considered here.
Sorting and Searching. Selection Sort  “Search-and-Swap” algorithm 1) Find the smallest element in the array and exchange it with a[0], the first element.
Review 1 Selection Sort Selection Sort Algorithm Time Complexity Best case Average case Worst case Examples.
Lecture No. 04,05 Sorting.  A process that organizes a collection of data into either ascending or descending order.  Can be used as a first step for.
ALGORITHMS.
1 Searching and Sorting Searching algorithms with simple arrays Sorting algorithms with simple arrays –Selection Sort –Insertion Sort –Bubble Sort –Quick.
Data Structures - CSCI 102 Selection Sort Keep the list separated into sorted and unsorted sections Start by finding the minimum & put it at the front.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 10 Lists 1.
M180: Data Structures & Algorithms in Java Sorting Algorithms Arab Open University 1.
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
Prime Numbers Damian Gordon. Prime Numbers So let’s say we want to express the following algorithm: – Read in a number and check if it’s a prime number.
Chapter 9: Sorting1 Sorting & Searching Ch. # 9. Chapter 9: Sorting2 Chapter Outline  What is sorting and complexity of sorting  Different types of.
Chapter 16: Searching, Sorting, and the vector Type.
1 compares each element of the array with the search key. works well for small arrays or for unsorted arrays works for any table slow can put more commonly.
OCR A Level F453: Data structures and data manipulation Data structures and data manipulation a. explain how static data structures may be.
Searching and Sorting Searching algorithms with simple arrays
Sort Algorithm.
Searching and Sorting Algorithms
Tips and tools for creating and presenting wide format slides
Python: Advanced Sorting Algorithms
Sorting Algorithms.
Department of Computer Science
Section 2.6: Searching and Sorting
Lesson Objectives Aims Understand the following “standard algorithms”:
Quick Sort.
Teach A level Computing: Algorithms and Data Structures
Advanced Sorting Methods: Shellsort
Searching and Sorting Topics Sequential Search on an Unordered File
Starter 15//2 = 7 (Quotient or Floor) (Modulus) 22%3 =1
CSC215 Lecture Algorithms.
Teaching Computing to GCSE
Linked List and Selection Sort
Sorting "There's nothing in your head the sorting hat can't see. So try me on and I will tell you where you ought to be." -The Sorting Hat, Harry Potter.
Sorting Chapter 13 presents several common algorithms for sorting an array of integers. Two slow but simple algorithms are Selectionsort and Insertionsort.
Quick-Sort 2/25/2019 2:22 AM Quick-Sort     2
Quick-Sort 4/8/ :20 AM Quick-Sort     2 9  9
Quick-Sort 4/25/2019 8:10 AM Quick-Sort     2
Unit 2: Computational Thinking, Algorithms & Programming
WJEC GCSE Computer Science
CS203 Lecture 15.
Presentation transcript:

Exam practice

Exam 1  Describe how a Boolean expression can control the operation of a loop  Describe the difference between a while loop and for loop  Explain the dangers of using global variables  In terms of function explain what a parameter is  Explain the difference between passing parameters by reference and by value  Explain the difference between a class and an object 159  Describe how a Boolean expression can control the operation of a loop  Describe the difference between a while loop and for loop  Explain the dangers of using global variables  In terms of function explain what a parameter is  Explain the difference between passing parameters by reference and by value  Explain the difference between a class and an object 159

Search algorithms  Linear search: involves methodically searching one location after another until the searched for value is found. It starts at the beginning of a list and checks each item in turn until the desired item is found. E FOUND AT LOCATION 4 WHAT LOCATION IS D DFCAEBHG

PSEUDOCODE  POINTER=0  WHILE POINTER<LENGTHOFLIST AND LIST[POINTER]!=SEARCHEDFOR  ADD ONE TO POINTER  ENDWHILE  IF POINTER>=LENGTHOFLIST THEN  PRINT(“ITEM IS NOT IN THE LIST”)  ELSE  PRINT(“ITEM IS AT LOCATION “+POINTER)  ENDIF  POINTER=0  WHILE POINTER<LENGTHOFLIST AND LIST[POINTER]!=SEARCHEDFOR  ADD ONE TO POINTER  ENDWHILE  IF POINTER>=LENGTHOFLIST THEN  PRINT(“ITEM IS NOT IN THE LIST”)  ELSE  PRINT(“ITEM IS AT LOCATION “+POINTER)  ENDIF

 Binary search works by dividing the list in two each time until being searched for is found. For binary search to work the list has to be in order.

 LOWERBOUND=0  UPPERBOUND=LENGTHOFLIST-1  FOUND=FALSE  WHILE FOUND==FALSE AND LOWERBOUND!=UPPERBOUND  MIDPOINT=ROUND(LOWERBOUND+UPPERBOUND)/2)  IFLIST[MIDPOINT]==SEARCHEDFOR THEN  FOUND=TRUE  LOWERBOUND=0  UPPERBOUND=LENGTHOFLIST-1  FOUND=FALSE  WHILE FOUND==FALSE AND LOWERBOUND!=UPPERBOUND  MIDPOINT=ROUND(LOWERBOUND+UPPERBOUND)/2)  IFLIST[MIDPOINT]==SEARCHEDFOR THEN  FOUND=TRUE

Insertion sort: Divide the list into two parts sorted and unsorted and insert it in the correct position in the sorted section.  Make the first item the sorted list, the remaining items are the unsorted list.  WHILE there are items in the unsorted list  Take the first item of the unsorted list.  WHILE there is an item to the left of it which is smaller than itself  Swap with that item  END WHILE  The sorted list is now one item bigger  END WHILE  Make the first item the sorted list, the remaining items are the unsorted list.  WHILE there are items in the unsorted list  Take the first item of the unsorted list.  WHILE there is an item to the left of it which is smaller than itself  Swap with that item  END WHILE  The sorted list is now one item bigger  END WHILE

CABEFD UNSORTED SORTED ACBEFD UNSORTED SORTED ABCEFD UNSORTED

Merge sort: Splits the size n into n lists of size 1. Each of these lists is merged with another. Each of the newly merged lists is merged with another. This is repeated until there is only one, sorted list. The key to this algorithm is the way the lists are merged.

Merge sort  IF the first item in list1<the first item in list2  THEN  Remove the first item from list1 and add it to newlist  ELSE  Remove the first item from list2 and add it to newlist  ENDIF  ENDWHILE  IF list1 is empty THEN  Add the reminder of LIST2 to newlist  ELSE  ADD the remainder of list1 to newlist  ENDIF  IF the first item in list1<the first item in list2  THEN  Remove the first item from list1 and add it to newlist  ELSE  Remove the first item from list2 and add it to newlist  ENDIF  ENDWHILE  IF list1 is empty THEN  Add the reminder of LIST2 to newlist  ELSE  ADD the remainder of list1 to newlist  ENDIF

BACFEDHG BACFE DH G AB CF DEGH AB CF DEGH ABCDEFGH

Quick sort: pick an item and call it the pivot, normally the first item is picked. Split the remainder of the list into two sub-lists where list 1 less than or equal to the pivot and list 2 greater than the pivot. Keep applying the split until the pivot can be combined and sorted.

Quick sort  Place leftPointer at first item in the list and rightPointer at the last item in the list.  WHILE leftPOINTER!=rightPOINTER  WHILE list[leftPointer] < list[rightPointer] AND leftPointer != rightPointer  Add one to leftPointer  END WHILE  Swap list[leftPointer] with list[[rightPointer]  END WHILE  Place leftPointer at first item in the list and rightPointer at the last item in the list.  WHILE leftPOINTER!=rightPOINTER  WHILE list[leftPointer] < list[rightPointer] AND leftPointer != rightPointer  Add one to leftPointer  END WHILE  Swap list[leftPointer] with list[[rightPointer]  END WHILE

CFDEAB AB CFDE PIVOT ACB D E F D E F ACB ABCDEF SUBLIST

Questions  In quick sort, a pivot is picked. Explain what this pivot is used for. 149  Describe what is checked during the feasibility study152  Describe what is meant by user documentation  In quick sort, a pivot is picked. Explain what this pivot is used for. 149  Describe what is checked during the feasibility study152  Describe what is meant by user documentation