-
Notifications
You must be signed in to change notification settings - Fork 84
Tri 2: TPT Week 10: Going Beyond CB
In APCSP 1-2, in the first two Tris, we focused on CB Big Ideas 1-5. These are the high level aspects of Creative Development/Social computing, Data, Algorithms and Programming, Computer Systems and Networks, Impact of Computing.
A data structure is a method of organizing data. Think of a variable holding a single integer value(ex: x=4) or sequences of numbers(ex: nums=[1,2,3]) or tables of data, or databases: these are all well-defined data structures. Data Structures and organizing data will require students to become more algorithmic in coding.
There are many algorithms for different purposes and they interact with different data structures. Think of algorithms as dynamic underlying pieces that interact with data structures. Together, data structures and algorithms combine and allow programmers to build whatever computer programs they’d like. Well managed data structures and algorithms ensures well-optimized and efficient code.
Data Structures and Algorithms can be written using different paradigms. A paradigm is an approach or a methodology or a strategy to be followed for writing software applications.
In computer science, imperative programming is a programming paradigm that uses statements that change a program's state. An imperative program consists of commands for the computer to perform to achieve a result. Imperative programming focuses on describing "how" a program code works.
Procedural programming is a type of imperative programming in which the program is built from one or more procedures (also termed subroutines or functions). Structured programming or modular programming in general have been promoted as techniques to improve the maintainability and overall quality of imperative programs.
Python allows programming in Procedural paradigm. Python is a versatile programming language with many user-defined data structures and algorithms.
Some examples of Common Data Structures and Algorithms:
Data Structures:
Lists (example: numbers = [1,2,3,4,5])
Dictionaries (example: personDict = {"name": "Tim Peters", "Age": 26})
Algorithms:
For example, Algorithm for SORT: How do we accomplish this? We take an input through a function and transform it to an output through a series of steps. In this case, we use a Python while/for loop to go through each value and shift it to a lower position if it is lower in value into a sub-selection of the list until every element in the array is dealt with.
Today's learning considerations will focus on the following(All of these concepts should be familiar and in your final Create Task):
- A. Observe variable assignments
- B. Study selection/if, iteration/loops and zero based counting
- C. Study lists, two-dimensional (2D) lists
- D. Do the above using the procedural paradigm using Python functions(def)
#Do these exercises now in Intellij, in pairs/trios, later we will be adding it to replit with menu similar to Nighthawk Replit Console Project:
-
Write a python function to swap two numbers. Identify variable assignment in your code.
For example:
age1 = 21
age2 = 16
print(age1,age2)
# write a python function to swap age with lowest age first
print(age1, age2) -
Write a python program to print a 3x3 formatted matrix as shown below, using lists and nested loops.
Make note of 2d array, loop/iteration and zero based counting.
matrix = [ [1,2,3],[4,5,6],[7,8,9] ] #write a function to output the formatted matrix :
1 2 3
4 5 6
7 8 9