/*
* Problem: Lattice Paths - Pure Recursion
*
* Prompt: Count the number of unique paths to travel from the top left
* corder to the bottom right corner of a lattice of M x N squares.
*
* When moving through the lattice, one can only travel to the adjacent
* corner on the right or down.
*
* Input: m {Integer} - rows of squares
* Input: n {Integer} - column of squares
* Output: {Integer}
*
* Example: input: (2, 3)
*
* (2 x 3 lattice of squares)
* __ __ __
* |__|__|__|
* |__|__|__|
*
* output: 10 (number of unique paths from top left corner to bottom right)
*
* Resource: https://projecteuler.net/problem=15
*
*/
Using Recursion
class LatticePaths {
public static int count;
public static int compute(int m, int n) {
// YOUR WORK HERE
count = 0;
countLatticePaths(0, 0, m, n);
return count;
}
private static void countLatticePaths(int i, int j, int m, int n) {
if(i == m && j == n) {
count++;
return;
}
if(i > m || j > n)
return;
countLatticePaths(i+1, j, m, n);
countLatticePaths(i, j+1, m ,n);
}
}
Using DP
private static int countLatticePathsDP(int m, int n) {
int[][] matrix = new int[m+1][n+1];
for(int i = 0; i < m; i++)
matrix[i][0] = 1;
for(int i = 0; i < n; i++)
matrix[0][i] = 1;
for(int i = 1; i <= m; i++) {
for(int j = 1; j <= n; j++) {
matrix[i][j] += matrix[i-1][j] + matrix[i][j-1];
}
}
return matrix[m][n];
}
/*
* Target Practice 01 - Recursion
*
* Problem 1: Powerset - Helper Method Recursion
*
* Prompt: Given a set S, return the powerset P(S), which is
* a set of all subsets of S.
*
* Input: {String}
* Output: {Array}
*
* Example: S = "abc", P(S) = ['', 'a', 'b','c','ab','ac','bc','abc']
*
* Notes: The input string will not contain duplicate characters
* The letters in the subset string must be in the same order
* as the original input.
*/
Diagramming
Solution
class Powerset {
public static List<String> result;
public static List<String> compute(String str) {
// YOUR WORK HERE
result = new ArrayList<String>();
createPowerSet(str, "", 0);
return result;
}
private static void createPowerSet(String str, String curr, int index) {
//base case
if(index == str.length()) {
result.add(curr);
return;
}
//call method with current string and index+1
createPowerSet(str, curr, index+1);
//call method with current string + character at index and index+1
createPowerSet(str, curr + str.charAt(index), index+1);
}
}
Have you ever seen the Russian Doll? If you open a Russion Doll from top, it has another smaller russian doll inside it. If you again open that Russian Doll, it has another small Russian Doll inside it, and so on. Until you reach the tinyest doll which cannot be opened. This is similar to recursion.
Recursion solves a problem by solving a smaller instance of the same problem, unless the problem is so small that we can just solve it directly.
Slower than iterative and stack methods and is rearely used. We need to know them because companies test them and some problems solve better by recursion
Recursion is useful with logic involving multiple branches, nested data structures, unknown count of loops or iterative approach is complex.
Recursion Terminology
Base Case – when to stop
Recursive Case – calls itself
Scope Variables – parent variables that can be accessed by child
State – current values of variables of stack that tracks where you are in your recursive algo
Single recursion – each recursive case calls itself one time, eg – factorial, fibonacci
Multiple recursion – each case calls itself multiple times creating a branching effect.
Top Down Approach – start at input, call itself recursively to reach base case. Could be single or multiple recusion
Bottom Up Approach – start at some defined value, build a path to reach input. Usually only single recursive pattern.
Implement Recursion
Helper Method – actual recursive method
Wrapper Method – method that calls recursive method, public method called by user
Example – Top-Down Approach
Class Fibonacci{
public static int fibonacci(int n){
return calculateFib(n);
}
private static int calculateFib(int n){
if(n == 0 || n == 1)
return n;
return calculateFib(n - 1) + calculateFib(n - 2);
}
}
Review – This specialization is a good place to learn Android Development. The first two courses and last two courses are great and fun. The middle two courses on concurrency and design patterns are very hard to understand. Those lectures contain lot of theory and hence becomes boring and difficult to understand. I specially enjoyed working on the capstone project – SelfieU app.
Overview-
*taken from coursera’s course description
Programming Mobile Applications for Android Handheld Systems: Part 1
This course focuses on following concepts
understand the components comprising the Android Platform
use various tools found in the Android Development Environment
recognize the four fundamental components of Android applications
work with the lifecycle of the Activity class
create a simple Android application
create applications comprising more than one Activity
understand how to define and enforce permissions
design applications that run on multiple, differently-sized devices
define and deploy applications with sophisticated and elegant user interfaces.
An app iRemember that allows user to capture ‘life stories’ by recording audio and video and taking pictures, as well as saving the date and location of events.
Programming Mobile Applications for Android Handheld Systems: Part 2
Threads, AsyncTask & Handlers
Networking
Display Tweet Data: Students build an app that downloads and displays Tweet data. The app uses an AsyncTask for downloading data over the network.
User Notifications
The BroadcastReceiver Class
Alarms
Tweet app: Students build an app that displays Twitter data. The app will use BroadcastReceivers and User Notifications to apprise the user of the app’s behavior and state.
Graphics & Animation
Multi-touch & Gestures
MultiMedia
Bubble Popper: Students write an application to display and animate bubbles on the device’s screen. When users touch the screen where a bubble is displayed, the bubble pops. The app will also accept gesture input, allowing the user to change the direction and speed of the bubble, using a fling gesture.
Sensors
Location & Maps
Data Management
Place Badge Collector: Students build an application that uses location information to collect Badges for the places they visit.
Programming Mobile Services for Android Handheld Systems: Concurrency
Overview of Patterns and Frameworks
Overview of Android Layers
Java Threading Mechanisms
Java Built-in Synchronization Mechanisms
Java Semaphores
Android Concurrency Frameworks: Programming
Overview of Android Concurrency Framework Classes
Overview of the Threaded Downloads Application
Overview of Handlers, Messages, and Runnables (HaMeR) Framework
Overview of the AsyncTask Framework
Evaluating Android Concurrency Frameworks
Android Concurrency Frameworks: Internals
Android Looper
Android Handler
Posting and Processing Runnables with the Android HaMeR Framework
Sending and Handling Messages with the Android HaMeR Framework
Blackbox and Whitebox Frameworks with AsyncTask
Overview of Android Concurrency Framework PatternsCoordinating Concurrent Access with the Monitor Object Pattern
Ensuring Only One Looper Per Thread with the Thread-Specific Storage Pattern
Passing Commands to Handlers with the Command Processor Pattern
Passing Messages to Handlers with the Active Object Pattern
Decoupling Synchronous and Synchronous Processing with the Half-Sync/Half-Async Pattern
Programming Mobile Services for Android Handheld Systems: Communication
Overview of Started and Bound Services
Activity and Service Communication
Service to Activity Communication Using Android Messenger
Programming Started Services
Android IntentService
Programming Bound Services with Messengers
Overview of the Android Interface Definition Language (AIDL)
Programming Bound Services with AIDL
Overview of Hyper-Text Transfer Protocol (HTTP)
Designing Mobile Applications with HTTP Communication
Better Client-side Communication Abstractions for HTTP
Communication Patterns in Android
Activating Services on Demand with the Activator Pattern
Passing Commands to Services with the Command Processor Pattern
Automating Marshaling and Demarshaling of Data with the Proxy Pattern
Supporting Object-Oriented Remote Method Calls with the Broker Pattern
Programming Cloud Services for Android Handheld Systems: Spring
This MOOC describes by example how to connect Android mobile devices to clouds via the use of object-oriented design techniques; Java programming language features; Android Content Providers, Content Resolvers, and SQLite databases; Jetty middleware; Java Servlets, the Java Spring Framework; and cloud computing platforms, such as Google App Engine.
An extended case study project will be used throughout the required core of the MOOC to showcase architectures for communicating with the cloud using HTTP, server-side processing of mobile data using servlets and the Java Spring Framework, and scalable storage of data using no-SQL databases and other platforms. Due to the importance of building secure and scalable mobile/cloud platforms, this MOOC will not only show you how to program handheld systems that talk to the cloud, but how to do so securely, scalably, and efficiently. Security and scalability topics will be woven into discussions of cloud service creation so that students learn, from the start, how to create robust cloud services for mobile devices.
Programming Cloud Services for Android Handheld Systems: Security
This MOOC describes, by example, the basics of securing mobile applications and back-end cloud services, OAuth.
Capstone Project – Daily Selfie Application
Github – https://github.com/megha14/SelfieU
Description – The app enables users to take pictures of themselves – selfies – over an extended period of time. It periodically reminds the user to take a selfie and presents the selfies in a list that makes it easy to see how the user has changed over time. This extended implementation also allows users to process their selfies to add effects, such as blurring or charcoaling.
App Features
App supports multiple users via individual user accounts
App contains at least one user-facing function available only to authenticated users
App comprises at least 1 instance of each of at least 2 of the following 4 fundamental Android components: Activity, BroadcastReceiver, Service, ContentProvider
App interacts with a remotely-hosted Java Spring-based service.
App interacts over the network via HTTP/HTTPS.
App allows users to navigate between 3 or more user interface screens at runtime.
App uses animation.
App supports an operation that is performed off the UI Thread in one or more background Threads of Thread pool using AsyncTask.
Detailed description of how these features are implemented can be seen in this document.
Review – This is one of the first courses that I completed back in 2014. The format of this course triggered my exploration of many more online courses. That time python was new to me.
It introduces python concepts through the development of small games. This feature especially makes the course fun and easy. The other thing that I liked was the online python editor on which one can develop and test applications. No need to install python on a machine. This was useful for me as I didn’t have any machine during that time. I would recommend this course totally to all python beginners.
Projects & Overview-
The concept of statements, expressions, variables, functions, logic, and conditions was introduced using a simple example and tested by developing a simple rock-paper-scissors game.
The next project “Guess the number” – a simple guessing game taught how to take user input in python and basics of event driven programming. The game involved taking user input and displaying whether user guessed number correctly based on that input(event).
The concepts involving drawing on canvas was taught using another simple game “Stopwatch“. Here we implemented buttons. The buttons controlled the display of stopwatch numbers on the screen.
The next project “PingPong” combined all the above concepts and introduced the concept of lists, keyboard input, and motion. Right paddle is controlled using “w” and “s” and left paddle is controlled using up and down key.
“Memory Game” also combines the concepts of lists, mouse events and draw methods.
The next mini project was “Blackjack” using concept of classes and objects.
Spaceship was the final graded project which combined all the concepts in the course. The game involved a spaceship hitting meteors using missiles. If missile hit meteor, your score increases and if spaceship hits a meteor, player looses one life.
iOS provides WebKit which contains WKWebView that can display both local/web content on the app
Replacing the textview in about page to webview displaying a HTML.
Remove the TextView and add WebView to the AboutViewController in Main.Storyboard
Create IBOutlet in AboutViewController for WebView and link it to the WebView in the Main.Storyboard
How to load an HTML in WebView
Bundle gives the path to the HTML file included in the app
That path is used to create a URL
URL is given to the URLRequest to generate a request
That request is then given to load to load the HTML page on the WebView
@IBOutlet weak var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
if let htmlPath = Bundle.main.path(forResource: "BullsEye", ofType: "html") {
let url = URL(fileURLWithPath: htmlPath)
let request = URLRequest(url: url)
webView.load(request)
}
}
AutoLayout
Currently, the app doesn’t look well on devices with bigger screens like iPhone 7, iPhone 8.
Using AutoLayout we can make sure the app is compatible with all the screen sizes.
AutoLayout allows us to select any view on the screen and set up the rules for how the size, position, or location of this view can be in relation to other items.
These rules are called constraints.
Here are the screens after adding constraints on both the ViewControllers in Main.Storyboard as visible on iPhone 8
This completes the Bulls Eye application development and also ends the “Your First Swift 4 & iOS 12 App Online” course.