Skip to content

Instantly share code, notes, and snippets.

View anas-harby's full-sized avatar

Anas Harby anas-harby

View GitHub Profile
@anas-harby
anas-harby / oop2.md
Last active February 24, 2019 23:09

OOP Principles

What is Abstraction?

Abstraction is an OOPS concept to construct the structure of the real world objects. During this construction only the general states and behaviors are taken and more specific states and behaviors are left aside for the implementers.

What is Encapsulation?

Encapsulation is an OOPS concept to create and define the permissions and restrictions of an object and its member variables and methods. A very simple example to explain the concept is to make the member variables of a class private and providing public getter and setter methods. Java provides four types of access level modifiers: public, protected, no modifier and private.

@anas-harby
anas-harby / oop.md
Last active February 25, 2019 18:44

OOP Quick Review

Creational Patterns:

Factory Method:

Analogy: Logistics app, needs a separate logic for Trucks and Ships to deliver a package. factory_method

Abstract Factory:

Analogy: You have 3 types of chairs/sofas/beds (Victorian, IKEA, Art), client needs to interact only with the type and not choose the product directly.

Tree

  • Find height of a tree.
    • Easy, return 1 + max(maxDepth(left), maxDepth(right))
  • Find all paths to leaves.
    • Easy but check string builder stuff.
  • K_th smallest.
    • Traverse left using a stack until there is no left, the leftmost element is the smallest, then start traversing right, decrementing k with every step.
    public int kthSmallest(TreeNode root, int k) {
@anas-harby
anas-harby / DESIGNDOC2.md
Last active February 2, 2018 16:58
Design Document: Project #02: Userprograms

Design Document: Project #02: Userprograms

Argument Passing

Data Structures:

  • (A1) Copy here the declaration of each new or changed struct or struct member, global or static variable, typedef, or enum.

    None created or changed.

Algorithms:

@anas-harby
anas-harby / DESIGNDOC1.md
Last active February 2, 2018 16:57
Design Document: Project #01: Threads

Design Document: Project #01: Threads

Alarm Clock

Data Structures:

  • (A1)

     /* threads/thread.h */
     struct thread