Create 2 simple PYTHON programs by converting from  pseudo code to python code click here

Complete 4.2.6 and post answers to Google site page title "Tracing code"

Rework the assessment and also post answers to your blog under new page titled "Sorting and Searching"

Section 4.2 Connecting computational thinking and program design (22 hours)

4.2.1 Describe the characteristics of standard algorithms on linear arrays. 

4.2.2 Outline the standard operations of collections.

4.2.3 Discuss an algorithm to solve a specific problem.

4.2.4 Analyse an algorithm presented as a flow chart.

4.2.5 Analyse an algorithm presented as pseudo code.

4.2.6 Construct pseudo code to represent an algorithm.

4.2.7 Suggest suitable algorithms to solve a specific problem.

4.2.8 Deduce the efficiency of an algorithm in the context of its use.

4.2.9 Determine the number of times a step in an algorithm will be performed for given input data.

4.3.1 State the fundamental operations of a computer.

4.3.2 Distinguish between fundamental and compound operations of a computer.

4.3.3 Explain the essential features of a computer language.


4.2.1 Describe the characteristics of standard algorithms on linear arrays. 

Why we need to sort stuff:


Selection SORT The Algorithm 

Visualization Click Here 

More about Selection sort the good and bad


BUBBLE SORT The Algorithm

Visualization Click Here 


QUICK SORT The Algorithm

Visualization Click Here 

More about Quick sort the good and bad

Sorting Activities

Given an array sortmeplease = [3,6,9,2,7,0,8]

Create a solution in pseudo code to perform a selection sort ( set start position = 0 then compare the element the start position with the rest of the elements  ( performing  a swap ) if next is smaller than current at then end of the first iteration the smallest element should be in position 0, but you need to sort all elements.

Open Jupyter Notebook and write program to perform the selection sort

  • check
    Create a solution in pseudo code that when give a list of numbers, you will print out all occurrences of the digit 5, assume all numbers are single digit and positive : Use a function call in your solution   
  • check
    Convert pseudo code to program code and post both to your google site
  • Create a solution in pseudo code to perform a selection sort ( set start position = 0 then compare the element the start position with the rest of the elements  ( performing  a swap ) if next is smaller than current at then end of the first iteration the smallest element should be in position 0, but you need to sort all elements.
  • Open Jupyter Notebook and write program to perform the selection sort
  • Post both pseudo code and  python code to your google site:
  • check
    Include a paragraph on your google sites that 1, explains why sorting algorithms are important and then proceed to compare and contrast selection sort and quick sort

Post both pseudo code and  python code to your google site:


4.2.6 Construct pseudo code to represent an algorithm.

What is a Flow Chart

Activity A : Find the error 

Activity B Program Efficiency

Why is it inefficient how could you improve it ?

Activity C Following Pseudo code

User Enters 3,5,6,4,4

What is the Output ?

User Enters 6,5,3,2,1

What is the Output ?

User Enters 2,4,78,99

What is the Output ?

Activity D Efficiency

Rank above into how efficient they are

BIG O Measuring Efficiency


Implement the pseudo code below in python add comments to your code

COUNT=1

loop while COUNT < 15

     COUNT = COUNT +1

    output COUNT

end loop 

SUM = 0

loop COUNT from 0 to 5

     SUM = SUM + COUNT

   output SUM

end loop 

4.3.1 State the fundamental operations of a computer.

  • 1
    Add / Subtract 
  • 2
    Compare
  • 3
    Store
  • 4
    Fetch from memory / Retrieve 

4.3.2 Distinguish between fundamental and compound operations of a computer

  • 1
     Search  / Find Largest
  • 2
    Sort
  • 3
    A combination of fundamental operations

4.3.3 Explain the essential features of a computer language.

  • 1
    unambiguous
  • 2
    Unchanging - Fixed Vocabulary - Syntax Rules
  • 3
    Abstraction example data structures - built in functions - to print - to read

4.3.4 Explain the need for higher level languages.

  • 1
  • 2
  • 3

4.3.5 Outline the need for a translation process from a higher level language to machine executable code.

  • 1
  • 2
  • 3

4.3.6 Explain the need for higher level languages.

  • 1
  • 2
  • 3

4.3.7 Define the operators =, ≠, <, <=, >, >=, mod, div.

  • 1
  • 2
  • 3

4.3.8 Analyse the use of variables, constants and operators in algorithms.

  • 1
  • 2
  • 3

4.3.9 Construct algorithms using loops, branching.

  • 1
  • 2
  • 3

12/11 Nov Class Activity

  • 1
    Create Python code to set up a 1 dimensional array of items of your choice. 
  • 2
    Iterate thru the array and print out each array element.
  • 3
    Extend the array to be 2D by adding an additional row 
  • 4
    Iterate thru the 2D arrays printing out all elements in row 0 followed by all elements in row 1  
  • 5
    Write your solution to step 4 in IB Pseudo CODE
  • 6
    Create blog page and copy the python code and the pseudo code to that page and post solution to google classroom

1 Dimensional Arrays

An array is a data structure that lets you hold list of like items ( rather than use multiple variables)

Example if we wish to store a list of car manufactures we could hold as 1 dimensional array. Remember the first element starts at 0   

car_array = ["Volvo","BMW","Honda"]

In python we can iterate thru a list in 2 ways

car_array= ["bmw","honda"]

for i in range(len(car_array)):

    print(car_array[i])

car_array= ["bmw","honda"]

for element in car_array:

    print(element)

2 Dimensional Arrays

In real-world Often tasks have to store rectangular data table( board games for example). Such tables are called matrices or two-dimensional arrays. In Python any table can be represented as a list of lists (a list, where each element is in turn a list). 

When we process 2D arrays we use a loop with a loop : Write some code to print out each element in car_array 

car_array= [["bmw","honda"],["red","blue"]]

# row 0  =  bmw, honda

# row 1 = red, blue

print(car_array[1][0])

print(car_array[1][1])

a = [["bmw","honda"],["red","blue"]]

for  i in range (len(a)):

       for j in range (len(a[i])):

            #print each element in the array


print(car_array[1][1])

Stacks    LIFO: last in first out

Queues: First in First Out  FIFO

Array Exercises

Given an array of N integers ranging from (0,20). Write pseudo code to iterate thru and print out the average value and the number of zero values.  

Assume array contains the following integers [1,6,18,20,0,1,7,9,8,6,2,1,3,0]

  • 1
    Write Solution in Pseudo Code
  • 2
    Convert you pseudo code to Python

Trace Exercises

Example 1

This algorithm calculates the second hand price of different models of car. The variable condition is an integer between 1 and 4 where 1 is excellent and 4 is very bad.

Example 2

Collections

By copying the table below, trace the following algorithm using the data in the collection DATA. Note: B and C are also collections and are initially empty.