Cracking the coding interview

cracking-the-coding-interview:破解编码面试的测试,问题和解决方案 致谢 应该感谢Gayle Laakmann McDowell在“方面所做的出色工作。 为什么这个回购 Ctci通过提供不仅问题而且提供渐进式提示和解决方案而在众多访谈书中脱颖而出。 但是,Ctci没有附带测试。 此回购尝试通过为每个问题添加测试来填补这一空白。 首先,编写测试有助于理解问题。 其次,我们可以提高我们的测试技能 最后但并非最不重要的一点是,测试可以尝试许多不同的解决方案。 开始吧 此仓库包含两个git分支: 练习:仅提供测试。 寻找解决方案取决于您。 大师:同时提供测试和解决方案。 与我的比较。 要开始使用,请按照以下步骤操作: 分叉此存储库 结帐practice分支解决问题 与参考进行比较。 例如,您要检查IsUnique的最佳解决方案 git diff master -- src/main/java/arraystring/_01_01_IsUnique.ja 立即下载


转自:http://hawstein.com/posts/ctci-solutions-contents.html

Cracking the coding interview--问题与解答

March 14, 2013
作者:Hawstein
出处: http://hawstein.com/posts/ctci-solutions-contents.html
声明:本文采用以下协议进行授权:  自由转载-非商用-非衍生-保持署名|Creative Commons BY-NC-ND 3.0  ,转载请注明作者及出处。

前言

《Cracking the coding interview》是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book。 里面有150道程序员面试题目及相应的解答。书中大部分是编程题目, 并且配有相应的java程序(有些地方有错误或是有更优的方案)。我把书中的题目做了一遍, 并且记录下来,包含自己对问题的一些思路及看法,许多问题给出了两种以上的解答方案。 由于个人平时使用较多的是C++,所以程序是用C++编写,所有的代码都托管在Github上:

https://github.com/Hawstein/cracking-the-coding-interview

记录下来的主要目的是加深自己对问题的理解,如果此外还能对一两个人起到帮助作用, 那真真是再好不过了。:P

目录

Chapter 1 | Arrays and Strings

1.1 Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures?

1.2 Write code to reverse a C-Style String. (C-String means that “abcd” is represented as five characters, including the null character.)

1.3 Design an algorithm and write code to remove the duplicate characters in a string without using any additional buffer. NOTE: One or two additional variables are fine. An extra copy of the array is not. FOLLOW UP Write the test cases for this method.

1.4 Write a method to decide if two strings are anagrams or not.

1.5 Write a method to replace all spaces in a string with ‘ ’.

1.6 Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees. Can you do this in place?

1.7 Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0.

1.8 Assume you have a method isSubstring which checks if one word is a substring of another. Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 using only one call to isSubstring (i.e., “waterbottle” is a rotation of “erbottlewat”).

Chapter 2 | Linked Lists

2.1 Write code to remove duplicates from an unsorted linked list. FOLLOW UP How would you solve this problem if a temporary buffer is not allowed?

2.2 Implement an algorithm to find the nth to last element of a singly linked list.

2.3 Implement an algorithm to delete a node in the middle of a single linked list, given only access to that node. EXAMPLE Input: the node ‘c’ from the linked list a->b->c->d->e Result: nothing is returned, but the new linked list looks like a->b->d->e

2.4 You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1’s digit is at the head of the list. Write a function that adds the two numbers and returns the sum as a linked list. EXAMPLE Input: (3 –> 1 –> 5) + (5 –> 9 –> 2) Output: 8 –> 0 –> 8

2.5 Given a circular linked list, implement an algorithm which returns node at the beginning of the loop. DEFINITION Circular linked list: A (corrupt) linked list in which a node’s next pointer points to an earlier node, so as to make a loop in the linked list. EXAMPLE input: A –> B –> C –> D –> E –> C (the same C as earlier) output: C

Chapter 3 | Stacks and Queues

3.1 Describe how you could use a single array to implement three stacks.

3.2 How would you design a stack which, in addition to push and pop, also has a function min which returns the minimum element? Push, pop and min should all operate in O(1) time.

3.3 Imagine a (literal) stack of plates. If the stack gets too high, it might topple. Therefore, in real life, we would likely start a new stack when the previous stack exceeds some threshold. Implement a data structure SetOfStacks that mimics this. SetOfStacks should be composed of several stacks, and should create a new stack once the previous one exceeds capacity. SetOfStacks.push() and SetOfStacks.pop() should behave identically to a single stack (that is, pop() should return the same values as it would if there were just a single stack). FOLLOW UP Implement a function popAt(int index) which performs a pop operation on a specific sub-stack.

3.4 In the classic problem of the Towers of Hanoi, you have 3 rods and N disks of different sizes which can slide onto any tower. The puzzle starts with disks sorted in ascending order of size from top to bottom (e.g., each disk sits on top of an even larger one). You have the following constraints: (A) Only one disk can be moved at a time. (B) A disk is slid off the top of one rod onto the next rod. © A disk can only be placed on top of a larger disk. Write a program to move the disks from the first rod to the last using Stacks.

3.5 Implement a MyQueue class which implements a queue using two stacks.

3.6 Write a program to sort a stack in ascending order. You should not make any assump- tions about how the stack is implemented. The following are the only functions that should be used to write this program: push | pop | peek | isEmpty.

Chapter 4 | Trees and Graphs

4.1 Implement a function to check if a tree is balanced. For the purposes of this question, a balanced tree is defined to be a tree such that no two leaf nodes differ in distance from the root by more than one.

4.2 Given a directed graph, design an algorithm to find out whether there is a route between two nodes.

4.3 Given a sorted (increasing order) array, write an algorithm to create a binary tree with minimal height.

4.4 Given a binary search tree, design an algorithm which creates a linked list of all the nodes at each depth (i.e., if you have a tree with depth D, you’ll have D linked lists).

4.5 Write an algorithm to find the ‘next’ node (i.e., in-order successor) of a given node in a binary search tree where each node has a link to its parent.

4.6 Design an algorithm and write code to find the first common ancestor of two nodes in a binary tree. Avoid storing additional nodes in a data structure. NOTE: This is not necessarily a binary search tree.

4.7 You have two very large binary trees: T1, with millions of nodes, and T2, with hun- dreds of nodes. Create an algorithm to decide if T2 is a subtree of T1.

4.8 You are given a binary tree in which each node contains a value. Design an algorithm to print all paths which sum up to that value. Note that it can be any path in the tree – it does not have to start at the root.

Chapter 5 | Bit Manipulation

5.1 You are given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to set all bits between i and j in N equal to M (e.g., M becomes a substring of N located at i and starting at j). EXAMPLE: Input: N = 10000000000, M = 10101, i = 2, j = 6 Output: N = 10001010100

5.2 Given a (decimal – e.g. 3.72) number that is passed in as a string, print the binary representation. If the number can not be represented accurately in binary, print “ERROR”

5.3 Given an integer, print the next smallest and next largest number that have the same number of 1 bits in their binary representation.

5.4 Explain what the following code does: ((n & (n-1)) == 0).

5.5 Write a function to determine the number of bits required to convert integer A to integer B. Input: 31, 14 Output: 2

5.6 Write a program to swap odd and even bits in an integer with as few instructions as possible (e.g., bit 0 and bit 1 are swapped, bit 2 and bit 3 are swapped, etc).

5.7 An array A[1…n] contains all the integers from 0 to n except for one number which is missing. In this problem, we cannot access an entire integer in A with a single operation. The elements of A are represented in binary, and the only operation we can use to access them is “fetch the jth bit of A[i]”, which takes constant time. Write code to find the missing integer. Can you do it in O(n) time?

Chapter 6 | Brain Teasers

Cracking the coding interview—Q6.1~Q6.6

Chapter 7 | Object Oriented Design

XDDDDDD

Chapter 8 | Recursion

8.1 Write a method to generate the nth Fibonacci number.

8.2 Imagine a robot sitting on the upper left hand corner of an NxN grid. The robot can only move in two directions: right and down. How many possible paths are there for the robot? FOLLOW UP Imagine certain squares are “off limits”, such that the robot can not step on them. Design an algorithm to get all possible paths for the robot.

8.3 Write a method that returns all subsets of a set.

8.4 Write a method to compute all permutations of a string.

8.5 Implement an algorithm to print all valid (e.g., properly opened and closed) combinations of n-pairs of parentheses. EXAMPLE: input: 3 (e.g., 3 pairs of parentheses) output: ()()(), ()(()), (())(), ((()))

8.6 Implement the “paint fill” function that one might see on many image editing programs. That is, given a screen (represented by a 2 dimensional array of Colors), a point, and a new color, fill in the surrounding area until you hit a border of that color.

8.7 Given an infinite number of quarters (25 cents), dimes (10 cents), nickels (5 cents) and pennies (1 cent), write code to calculate the number of ways of representing n cents.

8.8 Write an algorithm to print all ways of arranging eight queens on a chess board so that none of them share the same row, column or diagonal.

Chapter 9 | Sorting and Searching

9.1 You are given two sorted arrays, A and B, and A has a large enough buffer at the end to hold B. Write a method to merge B into A in sorted order.

9.2 Write a method to sort an array of strings so that all the anagrams are next to each other.

9.3 Given a sorted array of n integers that has been rotated an unknown number of times, give an O(log n) algorithm that finds an element in the array. You may assume that the array was originally sorted in increasing order. EXAMPLE: Input: find 5 in array (15 16 19 20 25 1 3 4 5 7 10 14) Output: 8 (the index of 5 in the array)

9.4 If you have a 2 GB file with one string per line, which sorting algorithm would you use to sort the file and why?

9.5 Given a sorted array of strings which is interspersed with empty strings, write a method to find the location of a given string. Example: find “ball” in [“at”, “”, “”, “”, “ball”, “”, “”, “car”, “”, “”, “dad”, “”, “”] will return 4 Example: find “ballcar” in [“at”, “”, “”, “”, “”, “ball”, “car”, “”, “”, “dad”, “”, “”] will return -1

9.6 Given a matrix in which each row and each column is sorted, write a method to find an element in it.

9.7 A circus is designing a tower routine consisting of people standing atop one another’s shoulders. For practical and aesthetic reasons, each person must be both shorter and lighter than the person below him or her. Given the heights and weights of each person in the circus, write a method to compute the largest possible number of people in such a tower. EXAMPLE: Input (ht, wt): (65, 100) (70, 150) (56, 90) (75, 190) (60, 95) (68, 110) Output: The longest tower is length 6 and includes from top to bottom: (56, 90) (60,95) (65,100) (68,110) (70,150) (75,190)

Chapter 10 | Mathematical

Cracking the coding interview—Q10.1~Q10.7

Chapter 11 | Testing

Cracking the coding interview—Q11.1~Q11.6

Chapter 12 | System Design and Memory Limits

12.1 If you were integrating a feed of end of day stock price information (open, high, low,and closing price) for 5,000 companies, how would you do it? You are responsible for the development, rollout and ongoing monitoring and maintenance of the feed. Describe the different methods you considered and why you would recommend your approach. The feed is delivered once per trading day in a comma-separated format via an FTP site. The feed will be used by 1000 daily users in a web application.

12.2 How would you design the data structures for a very large social network (Facebook,LinkedIn, etc)? Describe how you would design an algorithm to show the connection, or path, between two people (e.g., Me –> Bob –> Susan –> Jason –> You).

12.3 Given an input file with four billion integers, provide an algorithm to generate an integer which is not contained in the file. Assume you have 1 GB of memory. FOLLOW UP What if you have only 10 MB of memory?

12.4 You have an array with all the numbers from 1 to N, where N is at most 32,000. The array may have duplicate entries and you do not know what N is. With only 4KB of memory available, how would you print all duplicate elements in the array?

12.5 If you were designing a web crawler, how would you avoid getting into infinite loops?

12.6 You have a billion urls, where each is a huge page. How do you detect the duplicate documents?

12.7 You have to design a database that can store terabytes of data. It should support efficient range queries. How would you do it?

Chapter 13 | C++

13.1 Write a method to print the last K lines of an input file using C++.

13.2 Compare and contrast a hash table vs. an STL map. How is a hash table implemented?If the number of inputs is small, what data structure options can be used instead of a hash table?

13.3 How do virtual functions work in C++?

13.4 What is the difference between deep copy and shallow copy? Explain how you would use each.

13.5 What is the significance of the keyword “volatile” in C?

13.6 What is name hiding in C++?

13.7 Why does a destructor in base class need to be declared virtual?

13.8 Write a method that takes a pointer to a Node structure as a parameter and returns a complete copy of the passed-in data structure. The Node structure contains two pointers to other Node structures.

13.9 Write a smart pointer (smart_ptr) class.

Chapter 14 | Java

Pass

Chapter 15 | Databases

15.1 Write a method to find the number of employees in each department.

15.2 What are the different types of joins? Please explain how they differ and why certain types are better in certain situations.

15.3 What is denormalization? Explain the pros and cons.

15.4 Draw an entity-relationship diagram for a database with companies, people, and professionals (people who work for companies).

15.5 Imagine a simple database storing information for students’ grades. Design what this database might look like, and provide a SQL query to return a list of the honor roll students (top 10%), sorted by their grade point average.

Chapter 16 | Low Level

16.1 Explain the following terms: virtual memory, page fault, thrashing.

16.5 Write a program to find whether a machine is big endian or little endian.

16.10 Write a function called my2DAlloc which allocates a two dimensional array. Minimize the number of calls to malloc and make sure that the memory is accessible by the notation arr[i][j].

Chapter 17 | Networking

17.1 Explain what happens, step by step, after you type a URL into a browser. Use as much detail as possible. 

17.2 Explain any common routing protocol in detail. For example: BGP, OSPF, RIP.

17.3 Compare and contrast the IPv4 and IPv6 protocols.

17.4 What is a network / subnet mask? Explain how host A sends a message / packet to host B when: (a) both are on same network and (b) both are on different networks. Explain which layer makes the routing decision and how.

17.5 What are the differences between TCP and UDP? Explain how TCP handles reliable delivery (explain ACK mechanism), flow control (explain TCP sender’s / receiver’s window) and congestion control.

Chapter 18 | Threads and Locks

18.1 What’s the difference between a thread and a process?

18.2 How can you measure the time spent in a context switch?

18.3 Implement a singleton design pattern as a template such that, for any given class Foo, you can call Singleton::instance() and get a pointer to an instance of a singleton of type Foo. Assume the existence of a class Lock which has acquire() and release() methods. How could you make your implementation thread safe and exception safe?

18.5 Suppose we have the following code:… i) Can you design a mechanism to make sure that B is executed after A, and C is executed after B? ii) Suppose we have the following code to use class Foo. We do not know how the threads will be scheduled in the OS. Can you design a mechanism to make sure that all the methods will be executed in sequence?

Chapter 19 | Moderate

19.1 Write a function to swap a number in place without temporary variables.

19.2 Design an algorithm to figure out if someone has won in a game of tic-tac-toe.

19.3 Write an algorithm which computes the number of trailing zeros in n factorial.

19.4 Write a method which finds the maximum of two numbers. You should not use if-else or any other comparison operator. 

19.5 The Game of Master Mind is played as follows:
The computer has four slots containing balls that are red ®, yellow (Y), green (G) or blue (B). For example, the computer might have RGGB (e.g., Slot #1 is red, Slots #2 and #3 are green, Slot #4 is blue). You, the user, are trying to guess the solution. You might, for example, guess YRGB. When you guess the correct color for the correct slot, you get a “hit”. If you guess a color that exists but is in the wrong slot, you get a “pseudo-hit”. For example, the guess YRGB has 2 hits and one pseudo hit. For each guess, you are told the number of hits and pseudo-hits. Write a method that, given a guess and a solution, returns the number of hits and pseudo hits.

19.7 You are given an array of integers (both positive and negative). Find the continuous sequence with the largest sum. Return the sum.

19.8 Design a method to find the frequency of occurrences of any given word in a book.

19.10 Write a method to generate a random number between 1 and 7, given a method that generates a random number between 1 and 5 (i.e., implement rand7() using rand5()). 

19.11 Design an algorithm to find all pairs of integers within an array which sum to a specified value.



cracking-the-coding-interview:C ++和Python解决方案,带有用于破解编码面试第六版的自动化测试 使用自动单元测试破解编码面试解决方案 :check_mark_button: C ++解决方案 :check_mark_button: Python解决方案 :check_mark_button: 自动化单元测试 :check_mark_button: 积极发展 :check_mark_button: 多平台支持:Mac,Linux和Windows 介绍 此回购包含Gayle Laakmann McDowell的《 C ++和Python解决方案。 诚然,还有其他GitHub存储库以及针对本书的解决方案。 但是您怎么知道他们的代码实际上是正确的呢? 如果未经测试,那么您就不用! 在这个项目中,每个C ++解决方案都使用进行单元测试,每个Python解决方案都使用单元测试。 我们使用自动执行测试正确性,以确保解决方案由活动代码构成,该活动代码在每次提交时均被执行和测试。 据我所知,这是Internet上唯一具有这种严格测试水平的解决方案存储库:> 90%的自动测试覆盖率意味着您可以放心地参考和提供解决方案。 目录 : : 9 / 9完成。 : 8 / 8 立即下载

相关推荐

Cracking the Coding Interview, 4 Edition

Cracking the Coding Interview, 4 Edition

谷歌面试官经典作品(CTCI)目录

1.1 判断一个字符串中的字符是否唯一1.2 字符串翻转1.3 去除字符串中重复字符1.8 利用已知函数判断字符串是否为另一字符串的子串2.1 从链表中移除重复结点2.2 实现一个算法从一个单链表中返回倒数第n个元素2.3 给定链表中间某结点指针,删除链表中该结点2.4 求由两个链表结点组成的数之和2.5 给定一个循环链表,实现一个算法返回这个环的开始结点3.1 如何只用一个数组实现三个栈3.2

专注Android开发 1372

串并装换器的设计及仿真结果

串/并转换是高速数据流处理的重要技巧之一。串/并转换的实现方法多种多样,根据数据的的顺序和数量要求,可以选用寄存器,双扣RAM,SRAM,FIFO,等实现。对于 数量比较小的设计可以采用移位寄存器完成串/并转换。       在工程中,如何体现串/并转换的设计思想呢? 怎样才能提高系统的处理速度呢 ?       一个简单的串/并转换框架如下图所示,串行输入的数据通过FPGA内部的 n 个移

stubben_bear的专栏 2273

【亲测免费】 探秘《Cracking the Coding Interview》——编程面试的黄金指南

探秘《Cracking the Coding Interview》——编程面试的黄金指南 该项目是一个开源版本的,由GitHub用户black-shadows维护。这本书是许多软件工程师准备技术面试的必备资源,它涵盖了数据结构、算法和问题解决策略等多个方面。在这里,我们将从技术角度深入剖析其价值,并分享如何利用它提升你的编程面试技巧。 技术分析 代码实现 - 项目中包含了大量与书本内容相对应的...

gitblog_00091的博客 821

搞定汽车座椅电机EMC超标:一个PCB滤波板的实战设计与避坑心得

本文详细介绍了汽车座椅电机EMC超标问题的解决方案,通过PCB滤波板的实战设计,解决了传导发射测试超标问题。文章分享了在空间受限条件下的滤波电路架构设计、接地系统优化及迭代验证过程,为汽车直流电机的EMC整改提供了实用方法论。

weixin_30336061的博客 379

计算机毕业设计springboot基于微信平台的二次元手办商场小程序【附源码】

选题背景: 随着二次元文化的兴起和普及,越来越多的人开始对二次元角色产生了浓厚的兴趣和喜爱。手办作为二次元文化的重要载体之一,成为了许多二次元爱好者收藏和展示的对象。然而,在传统的线下手办商场中,消费者往往面临着时间、空间和选择的限制。因此,基于微信平台的二次元手办商场小程序应运而生。 选题意义: 首先,基于微信平台的二次元手办商场小程序能够打破地域限制,使得用户可以随时随地通过手机进行购物。无论是在家中、上班途中还是旅行中,用户都能够方便地浏览和购买自己喜欢的手办,极大地提高了购物的便利性和灵活性。

拉期程序 452

Cracking the coding interview(中文版)

谷歌面试官经典作品(CTCI)目录 1.1 判断一个字符串中的字符是否唯一 1.2 字符串翻转 1.3 去除字符串中重复字符 1.8 利用已知函数判断字符串是否为另一字符串的子串 2.1 从链表中移除重复结点 2.2 实现一个算法从一个单链表中返回倒数第n个元素 2.3 给定链表中间某结点指针,删除链表中该结点 2.4 求由两个链表结点组成的数之和 2.5 给定一个循环链表,实现

6236

Windows Server 2012评估版过期自动关机问题:两种高效解决方案详解

本文针对Windows Server 2012评估版过期导致的自动关机问题,提供了两种高效解决方案。一是通过slmgr.vbs命令重置授权,临时延长评估期;二是使用DISM工具将评估版转换为正式版,一劳永逸。文章详细解析了两种方法的操作步骤、注意事项及适用场景,帮助用户快速恢复服务器稳定运行。

pytorchlight8的博客 1195

探索编程面试的奥秘:《Cracking the Coding Interview》JavaScript版

探索编程面试的奥秘:《Cracking the Coding Interview》JavaScript版 在这个快速发展的技术世界中,对优秀程序员的需求不断增长,而面试环节往往成为筛选的关键。《Cracking the Coding Interview》第六版,由Gayle Laakmann McDowell所著,已成为编程面试准备的经典指南。现在,为了让JavaScript开发者更好地准备面试,...

gitblog_00093的博客 410

代数拓扑与AI架构:AI应用架构师深入探索数学研究如何分析复杂系统的结构特性

随着人工智能技术的飞速发展,AI系统变得越来越复杂。AI应用架构师需要有效的工具和方法来理解、设计和优化这些复杂系统。代数拓扑作为数学的一个分支,提供了独特的视角和技术来分析复杂系统的结构特性。本文旨在帮助AI应用架构师深入了解代数拓扑,以及如何将其应用于AI架构设计中,提升对复杂系统的分析能力。首先,我们会介绍代数拓扑和AI架构相关的核心概念及其联系,通过有趣的故事引入主题,让读者轻松理解复杂概念。接着,深入探讨代数拓扑的核心算法原理,结合具体的编程语言代码示例详细阐述。

大模型应用工坊 670

TGRS 2026 即插即用 | 注意力篇 | SCFM:双向交叉显著性引导注意力,高层语义与低层细节的双向互补!

本文介绍了MPCNet中的语义引导交叉注意力融合模块(SCFM),该模块通过双向交叉显著性引导机制实现跨尺度特征融合。SCFM创新性地结合了高层语义和低层细节的互补信息,通过轻量局部空间注意力预增强和坐标注意力全局融合引导,显著提升了红外小目标检测的精度。实验表明,SCFM在多个数据集上达到SOTA性能,同时保持轻量高效的计算特性,支持端侧设备部署。 SCFM的核心贡献包括: 双向交叉显著性引导机制,实现语义与细节的互补融合 轻量局部空间注意力预增强模块,计算量仅为传统方法的1/10 坐标注意力全局融合引导

主要更新底层视觉(去噪、超分等)相关的科研内容,形式为【论文精读】+【论文复现】 146

Cracking the Coding Interview习题总结(一)

CC150-Chapter 1 数组与字符串 刷leetcode遇到瓶颈之后,开始打算分类学习面试中的算法,于是就开始学习Cracking the Coding Interview第六版,并且配合其中的练习题,以下是对第一章中题目的总结。 - 判断字符串中字符互异 - 判断两个字符串是否乱序同构 - URLify(字符替换) - 判断字符串是否可排列为回文序列 - 字符串压缩 - 矩

u012901209的博客 913

Docker 环境 Playwright MCP 部署全流程指南

Docker部署Playwright MCP全流程指南 本文详细介绍了使用Docker容器化部署Playwright MCP的完整流程,涵盖镜像拉取、容器启动、配置优化和问题排查。主要内容包括: 核心部署步骤:通过官方镜像快速搭建环境,支持自定义端口和数据持久化 关键配置要点:详解网络设置、持久化目录挂载和环境变量配置 服务验证方法:通过日志检查和服务连通性测试确保部署成功 客户端集成:提供VS Code等IDE的配置示例 常见问题解决:针对浏览器启动超时、跨域限制等问题给出解决方案 实战案例:演示自动化爬

勤奋的码农 1473

《Cracking the Coding Interview》读书笔记

《Cracking the Coding Interview》是适合硅谷技术面试的一本面试指南,因为题目分类清晰,风格比较靠谱,所以广受推崇。 以下是我的读书笔记,基本都是每章的课后习题解答,其中不包括第15章。 相关源码在此repo中可以找到:https://github.com/zhuli19901106/Cracking-the-Coding-Interview 《Cra...

weixin_30507481的博客 206

微信小程序|基于小程序+云开发制作一个菜谱小程序

今天吃什么?这是一个让强迫症左右为难的问题,跟随此文基于小程序+云开发制作一个菜谱小程序,根据现有食材一键生成菜谱,省心又省力。

商务合作 / 项目定制 / 学习交流。个人vx:lovely_wml 1万+

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

Cracking the coding interview--问题与解答

本文转自:http://blog.youkuaiyun.com/zhangyf_2014/article/details/9762847 ==================================================== March 14, 2013 作者:Hawstein 出处:http://hawstein.com/posts/ctci-solutions-con

小龙王2010 2834

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Cracking the Coding Interview 6th Edition 代码实现

Cracking the Coding Interview 6th Edition 代码实现 1. 项目基础介绍 该项目是基于《Cracking the Coding Interview》第六版的算法题目实现的开源项目。这本书是程序员面试准备的经典读物,提供了大量的编程面试问题和解决方案。本项目用代码实现了书中的问题,旨在帮助那些准备技术面试的开发者加深对算法和数据结构的理解。主要编程语言为Jav...

gitblog_01176的博客 389

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Cracking the Coding Interview 第6版 高清完整版PDF下载

Cracking the Coding Interview 第6版 高清完整版PDF下载 【下载地址】CrackingtheCodingInterview第6版高清完整版PDF下载 《Cracking the Coding Interview》第6版是程序员面试准备的经典之作,本资源提供高清完整PDF版本。书中全面覆盖各...

gitblog_06714的博客 441

Cracking the coding interview汇总目录

很久之前刷的CTCI的题目,都快忘记了,做个分类汇总,再重新好好复习一遍。 Chapter 1 | Arrays and Strings 1.1 Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data stru

cfanr 4229

cracking the coding interview 中文版

转自: CTCI面试系列——谷歌面试官经典作品 | 快课网 http://www.cricode.com/3083.html 谷歌面试官经典作品(CTCI)目录 1.1 判断一个字符串中的字符是否唯一 1.2 字符串翻转 1.3 去除字符串中重复字符 1.8 利用已知函数判断字符串是否为另一字符串的子串 2.1 从链表中移除重复结点 2.2 实现一个算法从一个单链

aliceyangxi1987的博客 1260

看cracking the coding interview时写的一些代码

指向算法练习的链接

swingseagull的专栏 293

Cracking the Coding Interview开源项目常见问题解决方案

Cracking the Coding Interview开源项目常见问题解决方案 1. 项目基础介绍和主要编程语言 Cracking the Coding Interview(简称CTCI)是一个开源项目,该项目基于畅销书《程序员面试攻略》的第六版。它提供了书中所有编程问题的解决方案,旨在帮助那些准备技术面试的人。项目主要使用Java语言编写,同时也包含了一些Shell脚本。 2. 新手使用项目...

gitblog_00407的博客 428

Cracking The Coding Interview 3rd -- 00

www.CrackingTheCodingInterview.com

OlympianZ的专栏 746

Cracking the Coding Interview

前言 对于即将要找工作的CODER,如何准备面试,这是一个很宽泛也很茫然的问题。 也许大家首先想到的是:算法导论+数据结构+面试题。 当然,每个人心中都有一个哈姆雷特。 以下我将记录下我的找工作前的暴风雨洗礼。 一、基本功部分 (1)数据结构,主要参考了《数据结构(用面向对象方法与C++语言描述)》殷人昆这本书,差不多两个星期看完,部分代码亲自实践了一下。同时结合《C++ Primer

Boyhou 的专栏 6008

Cracking the coding interview的习题解答

《Cracking the coding interview》是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book。 里面有150道程序员面试题目及相应的解答。hawstein同学对Cracking the coding interview的所有习题做了非常细致的解答:http://hawstein.com/posts/ctci-...

weixin_30436101的博客 163
上一篇: 怎么得到部署在weblogic下war包里面的文件夹路径
下一篇: 开源点评:Protocol Buffers介绍
大树叶
博客等级 码龄12年 1171粉丝 664原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值