Search Results


27 matches found for 'C++'

How to convert a PPM image to grayscale in C++

... easy to work with, for modifying purposes. We'll create this image format from scratch, using C++. PPM Images can be opened with IfranView. Step 1 - The class for PPM image First, let's define a class for this PPM image.


A guide to const in C++

The Many Uses of const with Operator Overloading const can be used in different ways depending on how an operator is overloaded. There are two major cases to consider: If an operator is overloaded as a nonmember function (not part of the class definition) If an operator is overloaded as a member function (part of the class definition) Case 1: Overloaded as a Nonmember Function Here is an example of the + operator overloaded as a nonmember function: const Weight operator +(const Weight& w1, const Weight& w2); Notice we have three positions where we can place const and each one means something different.


Algorithm Handbook

Introduction Welcome to the algorithm handbook wiki! In this wiki you will find a mini-cheat sheet overview of data structures, and examples of their usages in modern languages. Algorithm problems can be found here.


Overlapping linked lists

Given two linked list nodes, one might overlap the other. That is, one linked list might contain a sequence that is already in the other linked list. The two linked lists share a common node. Problem Build a function that takes two singly linked lists and returns a boolean output that signifies whether or not the two linked lists share a common node.


Cyclic Permutation

This is an array/list trick that saves about O(n) in space complexity by taking advantage of a given array with integers representing indices. For this example problem, suppose that we want to apply some permutation P to an array A.


Detecting a cycle in a linked list

Problem Detect a cycle in a linked list and return the node that represents the start of the cycle. Input head: a pointer to the linked list Approach First, lets concentrate on how to detect a cycle in a linked list.


Java Essentials

... into machine code before execution. The JVM also handles garbage collection. Languages like C or C++ will compile the code into machine code (i.e. MASM), meaning that they skip one layer of abstraction.


Reversing sublists of singly linked lists

Singly linked lists can be tricky in its own right. Without the convenience of having a pointer to the previous node that is provided in doubly-linked lists, it can be really easy to be wasteful in performance with singly linked lists.


Phone Number Mnemonics in Python

Recursion is a great way to come up with permutations of strings or elements. Not necessarily because of the performance (iterative styles are usually faster) but because of simplicity and organization - like many algorithms with functional programming languages like Scala, recursive functions in general look neater, nicer, and easier to categorize.


Reversing words in a string : the double reverse

Problem Reverse all words (separated by space) in a string Input \(s\) - a string Approach Nice case and point for really examining the examples. First, a few examples of reversing words in a string.


Paint adjacent boundaries with distinct colors

In my recent A.I. class, I had an assignment where I had to write some code that will paint the countries of Africa with distinct colors. For the colors, I was given a domain of set(['red','blue','white','yellow','green']).


Python Essentials

... has finished executing. This is very different from multi-threading in other languages like C++ or Java, where compiled code can actually be executed in parallel among various CPU threads.


Javascript Essentials

Hoisting Hoisting is JavaScript's default behavior of moving declarations to the top. Given the following Javascript code, what is the expected output, and why? fcn2(); fcn1(); function fcn2(){ alert("hi"); } var fcn1 = function(){ alert("hey") } The expected output is a pop up alert that says "hi", followed by an error that fcn1 isn't defined.


Replace all occurrences of a space inside an array

Problem Given an array of characters, replace all occurrences of a space with another string. Assume that the array has enough space to contain all of the replacements. Input A - An array of characters which may or may not have spaces word - The string to replace spaces with.


String Manipulation in Python 3+

There are a few ways to search for a string in Python (3+): String operations str.find(sub[, start[, end]])] "shadow walker".find('w') => 5 This gives you the index of the first match. While the index might be nice to have, do remember that strings are immutable.


TCP/IP and HTTP - Part 1

A Very Brief History TCP/IP stands for Transmission Control Protocol / Internet Protocol. During the Cold War, in retaliation of the USSR's Sputnik, the U.S. Department of Defense (DoD) started ARPA, the Advanced Research Projects Agency.


Heroku login on a proxy (Windows 7)

I have had some issues logging into Heroku using a company proxy; if you are in the same boat, you might want to try the following in Command Prompt: C:\...\..> set HTTP_PROXY = <your proxy here> C:\.


CAP Patterns

The CAP Theorem dictates that only two of its three characteristics can be guaranteed at any given time. Intro to CAP Consistency Every read will be based off of the latest write Availability Every request will be given a response, although the response data might be stale Partition Tolerance It can handle network partitions or network failures MTV's The Real World If your service is in the cloud, the P in Partitioning has to always be accounted for.


Machine Learning Basics

Supervised Learning In supervised learning, we take some data and predict an output in a pre-defined structure. There are two categories: Regression: When a function is given some input variables, what is the continuous output? i.


NumPy vs. Pandas, and other flavors (Dask, Modin, Ray)

NumPy NumPy is a Python library for numerical computing that offers multi-dimensional arrays and indices as data structures and additional high-level math utilities. ndarray The unique offering of NumPy is the ndarray data structure, which stands for n-dimensional array.


Escape from the Strings

What is escaping? Escaping is used for characters that are not intended to be shown. Consider the following text: <strong>Hi there</strong> This text is saved onto a HTML file, foo.


Javascript Concepts

... Consequently, this leads to the function acting like a class in other notable languages like C++, Java, or Python. Since functions are first-class, callbacks are possible, as well as anonymous functions and closures.


Seattle Conference on Scalability: YouTube Scalability

Notes Apache isn't that great at serving static content for a large number of requests vs. NetScaler load balancing Python is fast enough There are many other bottlenecks such as waiting for calls from DB, cache, etc.


Misconceptions of ASCII and Unicode

Myth: ASCII characters take up one byte ASCII represented characters using numbers between 32 and 127. This accounted for characters used in the English language (lowercase and uppercase) and the numbers between 1-32 were reserved control characters.


4 Line Depth-first Search

Context Depth-first search (DFS) is a common searching algorithm for graphs, alongside Breadth-first search (BFS). DFS is useful for finding ways to solve mazes. It is also a vital ingredient for topological sorting.


Working with Production at Amazon Retail Website

A short background Prior to working at Amazon, I was developing software at a couple of startups, mostly working with products that were in the conceptual phase or the development phase. One of the things I desired the most was to have exposure to products that were live in production or to bring a development project to production.


Google Protocol Buffers

... or systems; it allows you to compile schemas for your data in popular languages such as Python, C++, Go, Java, etc. protobuf is backwards-compatible, meaning that your program can still use deprecated data without breaking anything.