Monday, July 8, 2013

Recursive Interview Questions Tutorial (WIP)


The most important thing to learn is how to think recursively. This allows you to solve a large class of problems relatively simply. It's important to know for job interviews. I had interviewed at Google six months ago and because I botched an interview question that could have been solved recursively, the interviewer told the recruiter I "lacked fundamental understanding of computer science". 

To solve a problem recursively:

1)  Think about how to solve the problem for simple cases (base case). 
2)  Determine how to break down larger cases into smaller instances (recursive decomposition).

Remember that every recursive algorithm has two components: the base case and the recursive decomposition. 

Problem #1 Reverse A String
Base Case:  When the string is the empty string is it the same backwards as it is forwards
Recursive Decomposition: For strings, to shrink the string to make forward progress is the same as solving the problem for substrings of the string, and then combining the sub-solutions.


/* Returns the reverse of the indicated string. */
string reverseString(string line) {
 if (line == "")
  return "";
 else
  return reverseString(line.substr(1)) + line[0];
}

Problem #2 Count Spaces in A String
Base Case:  When the string is empty is cannot have a space so the count of spaces is 0.
Recursive Decomposition: Check character by character by working with substrings of the string, and then sum the counts of the strings. 


/* Returns the count of white spaces in a string*/
int countSpaces(string line){
  if (line.length() == 0)
    return 0;
  else
    return ((isspace(line[0]) ? 1 : 0) + countSpaces(line.substr(1)));
}
Problem #3 Find Last Occurrence of Character in String
Base Case: Well if you are at the end of the string and no characters follow, it must be the last occurrence if there is a match. 
Recursive Decomposition: Start at the end of the string and after each call remove the last character. 


/* Return the index of the last occurence of a character in the string */
int find_last_occurence(string line, char character){
  if (line[line.length()-1] == character)
    return (int)line.length();
  else if(line.length() == 0)
    return -1;
  else
    return find_last_occurence(line.substr(0,line.length()-1), character);
}

Spark Notes Article That I Thought Was Useful: http://www.sparknotes.com/cs/recursion/whatisrecursion/section2.rhtml

Problem #4 Traversing a Binary Tree. Inorder, preorder, postorder.

Problem #5 Print all subsets of a set. 

Problem #6 Print all alphanumeric combinations of a phone number. 

These are the slides that I found on the Stanford Engineering Everywhere site that I found useful to learn more about recursion. 
























58 comments :

Packers Movers Jaipur said...

"Enjoyed every bit of your blog article.Really looking forward to read more. Really Cool."
Packers And Movers Jaipur charges

YO YO HONEY SINGH said...

QuickBooks Support Phone Number
QuickBooks 24/7 Support Phone Number
QuickBooks Technical Support Phone Number
QuickBooks Tech Support Phone Number
QuickBooks Support Number

Mathew said...

Quickbooks made accounting easy for beginners and provide a helping hand to complete the task before the time for standard users. It is an easy way to navigate the financial reports as a result of getting to know about the business transactions and cash in and outflows.


Quickbooks Support Phone Number

QuickBooks Support Number

QuickBooks Tech Support Phone Number

QuickBooks Technical Support Phone Number

QuickBooks Customer Service Phone Number

Mathew said...

Are You Facing Problem in your Quickbooks? Call us today at QuickBooks Tech Support Phone Number +1-888-396-0208 for QuickBooks upgrades, updates, company file repair and data recovery services. 24 hours service delivery guaranteed. QuickBooks Technical Support Call use for QuickBooks error resolution and any kind of technical support. Call us Now.

Anonymous said...

Were you just searching for Intuit QuickBooks Payroll for Mac ?QuickBooks software for Mac users does not have a built-in payroll service like the Windows version. You need to click on the Payroll link that will direct you to an external website for processing employee checks. As QuickBooks fails to accord built-in method for manually tracking payroll, the employers who wish to track payroll for employees in QuickBooks must subscribe and pay a monthly fee to access the online QuickBooks Payroll for Mac service.

YO YO HONEY SINGH said...

QuickBooks Payroll Tech Support Number is a capable programming composed by Intuit. It is utilized for Small and medium size business to keep up records of working representatives bookkeeping data, pay including all the duties and exchanges are finished with them.

jameswill11 said...

The enterprise solution streamlines all the critical tasks in such a way that you find accounting and financial transactions easier. The software suite keeps track of all information and documents in a single space. And that's why, the enterprise solution is best recommended for small and mid-sized industries. For more Details you can contact QuickBooks Enterprise Support 1888-396-0208.

QuickBooks Support Phone Number said...

Having problems with sending or receiving your W2's ? QuickBooks Support Phone Number.This software can keep the record of all the transactions and produce reports for various needs.
Call on 1888-567-1159 and have a conversation with one of our experts now.

rdsraftaar said...

QuickBooks Technical Support Phone Number Support Phone Number for Technical Support & Customer Service , working 24*7 Just dial ++1800-291-2485 (Toll Free) for any requirement including set-up, purchase , installation , bookkeeping, and many more. Simply Dial and Feel Secure.

YO YO HONEY SINGH said...

Presently you can undoubtedly get to any sort of data without much problem to make a report. With the choice of pursuit and channel now you can tweak the reports according to your benefit and preference. New Customers of Quickbooks can Call Quickbook Tech Support Phone Number 1888-396-0208 and get in touch with us .

rdsraftaar said...

To get the customized online answer for all QuickBooks Enterprise Users. Our support benefit is open to Windows and Mac PC clients to settle the issue according to the similarity of their PC framework. It works for Mac and different gadgets utilizing QuickBooks Enterprise however having an issue while utilizing or introducing this product. The Operating System (OS) master group of nerds to determine such issues with finish security and protection.QuickBooks Enterprise Support Phone Number

Mathew said...

POS Support 1800-291-2485 is proposed to influence skilled client to profit and to make customers chipper. It tracks the stock and customer's information and passes on various features to hold them returning. Also, moreover with this product; you can in like manner know customer's necessity for a particular thing and what stamp they get a kick out of the opportunity to shop.

Mathew said...

The Enterprise Support 1800-291-2485 Has Many Professional Technicians Who Are Expert And Provides Instant Solution Of The Problems You Are Facing. Side By Side The Quickbooks Enterprise Support Is Equipped With Many Certified Technicians Who Can Handle All Kind Of Issues Related To Your Quickbooks Issues At The Same Time.

lucky said...


This product can keep the record of the considerable number of exchanges and deliver reports for different requirements. In any case, such profoundly appraised programming can likewise demonstrate the issue however QuickBooks Payroll Phone Number is accessible here.

accountingwizards said...

We give proficient help and specialized help for QuickBooks clients on QuickBooks Support Number 1800-291-2485. Our group comprise of affirmed QuickBooks ProAdvisors. With the assistance of devoted 24×7 supports framework and superb client benefit, 247 QuickBooks gives your bookkeeping a fix.

accountingwizards said...

QuickBooks Enterprise version is one of the most powerful versions of all the three, that is, QuickBooks Pro, Enterprise and Enterprise. This version of QuickBooks software was designed keeping the financial needs of businesses having a large team of accounts in mind. Subscriber of QuickBooks Enterprises version Call the Toll-Free Quickbooks Enterprise Support Phone Number Canada 1888-557-6950 to connect with the USA.

robinjack said...

I as of late discovered numerous helpful data in your site particularly this web journal page. Among the bunches of remarks on your articles. A debt of gratitude is in order for sharing. HMRC Tax Investigation Accountants

seo said...

I needed to thank you for this fabulous read!! I certainly cherished each and every piece of it. I have you bookmarked your site to look at the new stuff you pos HMRC Tax Enquiry Advice

seo said...

Much obliged to you for such an elegantly composed article. It's brimming with astute data and diverting depictions. Your perspective is the best among numerous. Let Campaign Tax Enquiry

Manish Packers and Movers Pvt Ltd said...

Packers and Movers Jamnagar
Packers and Movers Gandhidham
Packers and Movers Nashik
Packers and Movers Gwalior
Packers and Movers Visakhapatnam
Packers and Movers Patna
Packers and Movers Ranchi
Packers and Movers Bilaspur
Packers and Movers Korba
Packers and Movers Raigarh

Manish Packers and Movers Pvt Ltd said...

Packers and Movers Sector 14, 17, 19 Gurgaon
Packers and Movers Sector 23 Gurgaon
Packers and Movers Sector 45, 46, 47 Gurgaon
Packers and Movers Sector 55, 56, 57 Gurgaon

basha said...

Superb blog I visit this blog it's extremely marvelous. Interestingly, in this blog content composed plainly and justifiable. The substance of data is exceptionally instructive.
oracle fusion financials classroom training
Workday HCM Online Training
Oracle Fusion Financials Online Training
Oracle Fusion HCM Online Training
Oracle Fusion SCM Online Training
Oracle Fusion HCM Classroom Training

Komali said...

Very Nice Blog...

brand new outlook

Bigo live for Windows

Rajesh said...

thanks for sharing this information
aws training in bangalore
Amazon web services training in bangalore
best AWS Training institute in Bangalore
aws training institutes in bangalore
devops training in bangalore
devops certification course in bangalore
data science training in bangalore
data science classroom training in bangalore
best training institute for data science in bangalore

Ilead said...

QuickBooks accounting software created a benchmark in the area of accounting & bookkeeping. In the past few years, the demand for this software increased so much that the Intuit has to double the productivity. In this post, we are going to discuss the quickbooks error code 80029c4a. This informative post includes topics like its causes & resolution.However, if the error code persists – you can contact the certified QuickBooks technicians of QuickBooks Error Support. Or you can get in touch with them by making a call on their toll-free number .i.e. +1(800)396-7703.

quickbboks tech support phone number +1(855)-236-7529 said...

For availing sturdy resolutions near your doors, just contact us on QuickBooks Tech Support Phone Number +1-855-236-7529 without any hesitation. QuickBooks Tech Support Number +1-855-236-7529: We have everything under our hood. QuickBooks Tech Support Phone Number +1-855-236-7529. Or contact at QuickBooks Error 6000, 205
Read more: https://www.techiesupportnumber.com/

qb enterprise support number said...

If you are looking for an accounting software that can help you to manage your financial reports then QuickBooks is a great option for you. You can easily use and install this software. In case you discover any inconvenience in your software then kindly contact our team at QuickBooks Technical Support Phone Number 1-888-238-7409. We will provide you best technical support for your QuickBooks problems. Visit us:- https://www.enetquickbookenterprise.com/quickbooks-technical-support/

usman said...

Being one of the leading accounting software, QuickBooks plays a vital role in managing business accounting. But sometimes the lucrative features of this software are challenged by few errors. In such a situation seek our instant help and support for QuickBooks software at QuickBooks Support Phone Number +1 800-417-3165. Visit us- https://www.qbcustomersupportphonenumber.com/

usman said...

QuickBooks is a great platform that provides iconic features to its users though it appears with some errors. This error occurs due to the unfamiliarity of users with software. Thus, whenever any technical error arises, dial our QuickBooks Support Phone Number +1 800-417-3165 and get feasible solutions for QuickBooks errors. Visit us-https://qbcustomersupportphonenumber.site123.me/

usman said...

QuickBooks is a remarkable accounting software but unlike any other software, QuickBooks is also not far from technical glitches. At times while working on this software you may come across some errors that may bother you. So, to eliminate these errors kindly contact our team at QuickBooks Support Phone Number +1 800-417-3165. Visit us- http://qbcustomersupportnumber.mystrikingly.com/

Anonymous said...

Hey, what a delightful post, it will help the readers in having a better understanding. This is
an amazing post and a reader’s delight, I must say. QuickBooks is astounding accounting
software that assists users in several ways. All their accounting, bookkeeping and financial
tasks are done within a just few clicks with the help of this amazing software. This software is
also prone to glitches and errors and thus to fix them in an optimal way you to need to call
our QuickBooks Support Phone Number 1-844-235-3996 and avail instant solution.visit us:-herf="https://tinyurl.com/y5vx3u4g

Get Support Phone Number said...

I am truly very impressed with your writing skills and the vocabulary used by you in your every content. I know that it takes a lot of effort and hard work to write this much awesome content. I must suggest you to write more and more on daily basis. A lot of people are getting benefitted with your content. In case you are also a QuickBooks software user and looking for a professional help than connect with experts at QuickBooks tech support phone number 1-800-311-5657. They have the world-class tech support services that can beavailed remotely by sitting at home.

Anonymous said...

Hi Mate!
What a scintillating Post! You have posted this in a while, but you have simply nailed it my
friend. Thank you for this amazing post! If you are using QuickBooks for your organization and
want to know about How to Access QuickBooks Desktop Remotely? Then all you have to do is
simply call our QuickBooks POS Support Phone Number 1-844-235-3996 and know all the detail about this
service.viste us:-https://tinyurl.com/y25qk529

QuickBooks Support Phone Number said...

Once again you have presented such as unique and engaging content. I wonder how you come across such ideas. I appreciate and admire your work and share it with my friends. Hey, you can use QuickBooks for managing important businesses. Check out more about the utility of QuickBooks and the assistance at QuickBooks Support Phone Number 1-833-441-8848.

Hannah said...

Hello friend. I am impressed by your outstanding blog. Your blog has a balance for all the information and supporting statements. Wish you a successful blogging career ahead. If you are using QuickBooks software as your business accounting solutions, then you may be wondering When QuickBooks Error Code 3140 Occurs? Error 3140 is a run-time error it generally occurs when the user is trying to install his/her QuickBooks software. To get solution for this error, call us on our tollfree error support phone number 1-833-422-8848. Our error support line is open for you 24X7 with solutions for all the errors.

Anonymous said...

Hey, your post is so engaging and capturing. I just finished reading the whole blog in a breath. I appreciate your content quality and eagerness to write. Hope a great success for you. You can save your precious time in business management through QuickBooks. Learn more about it at QuickBooks Support Phone Number 1-844-235-3996.

Tech Customer Support Number said...

Hey, greetings and applause for your excellent post. You never fail to provide quality information in an appropriate quantity. I must say you must be consistent in this activity of yours. Hey, if you are a QuickBooks user, then pay attention to my advice. Consult the best tech support service providers for 24*7 services at QuickBooks Helpline Number +1 833-228-2822.
QuickBooks Error 6000

QuickBooks Support Phone Number said...

Hi! Great post. Thank you for sharing a big amount of valuable information with us. I really appreciate your work and kind words. Do you know QuickBooks POS is one of the best accounting
software? By installing this software, you can save your time and resources. You can even get live help and support at QuickBooks Support Phone Number 1-833-441-8848.

Anonymous said...

I liked your blog. It can get difficult for you to manage your blogging career with your accounts. To solve this dilemma, use QuickBooks as your accounting software. You can take help from the experts on Quickbooks Helpline Number +1-800-329-0391. They are available for you 24X7 at an affordable price.

Read More: Quickbooks Error 3371

Anonymous said...

Your blog is the best blog that I have read on the internet today. QuickBooks great features are available for the users at an affordable rate. It has easy to use and interactive interface, which can be used by users with no accounting history. To get support for the software, call us on tollfree Quickbooks Customer Care Number +1-800-329-0391

QuickBooks Support Phone Number said...

The information provided in your post is unique and amazing. It contains all the information that is required. You have explained every single point precisely that helped me in completing my task and hope will help others in many ways. Learn to manage your time efficiently, with QuickBooks Payroll software. There, are certain cases, where users get trapped in the error. Hence, to remove such errors, contact QuickBooks Support Phone number +1-844-200-2627.

qb enterprise support number said...

Wow! What a marvel piece of content. I am completely mesmerized as going through your post. Very few bloggers show their interest in such topics. With QuickBooks accounting software one can easily and accurately manage all their accounting and financial tasks without any human error. For more details, you can call our experts at QuickBooks Technical Support Phone Number 1 (888) 238-7409 and avail timely help you need. Visit us: - https://www.qbtechnicalsupportphonenumber.com/

Anonymous said...

Wow! This blog is amazing. Keeping writing such blogs. Your blog has great content with the best information related to the topic. If you are facing difficulty in managing your business accounting process. Use QuickBooks accounting software which has the best features for managing your business accounting process. If you face any difficulty in using the software, call us on tollfree QuickBooks Support Phone Number +1-844-235-3996. Our support provides the best solutions at an affordable price rate.https://tinyurl.com/y5vx3u4g

qb enterprise support number said...

Wow! Nice blog, with the perfect quality of content. Keep writing such blogs. With QuickBooks Payroll, managing employees pay is an easy task. You can easily use its bank deposit feature and can pay your employee and contactor within 24hres. To get support for this software, call us on QuickBooks Payroll Support +1 (888) 238-7409. Visit us: - https://www.enetquickbookenterprise.com/quickbooks-payroll-support/

Anonymous said...

Hey, what a fantastic post! Great job done my mate, you know what, I read a lot of posts but have never come across a post as such. I love this topic, you made up to my blogger bucket list. Now, you can save big money and time, by installing QuickBooks software. For any queries associated with QuickBooks contact our experts at QuickBooks Support Phone Number 1-844-235-3996 and avail incredible help anytime.https://tinyurl.com/y47a3rpp

Tech Customer Support Number said...

I would like to express the gratitude for presenting such an elaborated description. This topic is an important one and I seriously required a deep insight. Well, do you know why your functioning on QuickBooks becomes difficult? To receive the understanding of technical problems, I advise you to connect with the tech support team at QuickBooks Payroll Support Phone Number +1 833-228-2822.
Read More: QuickBooks Error 6000 83

QuickBooks Support Phone Number said...

Outstanding blog! This is amazing, the way you portray, the words are commendable. What is commendable apart from this post, is QuickBooks which offers great features to its users to ease out complex work. However, you may come up with few problems, but that’s not an issue as Phone Number for QuickBooks Payroll Support 1-833-441-8848 is there to help you out
round the clock. Hurry, call now!

QuickBooks Support Phone Number said...

Thumbs up for the good work…! I like your style and wish you all the best for your blog. In case, maintaining accounts is becoming difficult for you, take help from Quickbooks Support Phone Number +1-833-441-8848. Here, you get the certified solutions for all the accounting errors. It is a third-party service, certified by QuickBooks to provide quick assistance in times of need.

QuickBooks Support Phone Number said...

What an amazing piece of work! It is always fun to visit your blog. You possess indiscriminate talent. Keep sharing the good work. In case you are looking for reliable accounting software, try using QuickBooks. It is as amazing as your work. To know more about it call us on QuickBooks Desktop Support Phone Number +1-844-200-2627. We will provide all related information.

QuickBooks Support Phone Number said...

Wow…! What a tremendous piece of work. You have covered all the topics with brevity. I liked your style. QuickBooks is accounting software that has made it easy for businesses and enterprises to perform auditing. It even allows the businesses to manage inventory by keeping track of sales and purchase of stock. To know more about it call on QuickBooks Error Support +1-844-200-2627.

The Qb Payroll said...

Looking for a consistent support that can resolve every issues? Then, you are at the right place to attain the solution, from our QuickBooks Desktop Support Phone Number +1(833)401-0005. One-stop solution for all your riddles which our service team deliver to the customers. Before moving into the desktop support, let’s take a glance, at how Quickbooks has flourished small & medium size businesses. For More visit: http://www.santrasolutions.com/quickbooks-desktop-support/

quickbooks technical support phone number said...

Hey! Outstanding Post. I appreciate all the time and effort that you have given in composing such informative content. Thanks for sharing such a remarkable work. In case you are looking for powerful accounting software, then I will recommend you to give QuickBooks software a shot. To know how to get started with the software, seek instant help at QuickBooks Support Phone Number +1-833-401-0204. Read more: https://www.probfix.com/

paloma said...

Hello Mate, thank you for this great post, the post is very interesting and informative. Thank you for sharing such a post and I would love to read more of your post. Thus, would like more frequent post from your side. QuickBooks is one of the most amazing accounting applications that manage all your accounts and finance-related tasks. So, if you need more information about this application, you can contact the experts at QuickBooks Support Phone Number +1-833-401-0204 and avail all the perfect answers to your queries.

Amily said...

Nice Blog ! Stop your search here if you are looking for help to get your QuickBooks issues resolved. Our QuickBooks Support Phone Number 1-855-9O7-O4O6 is meant to help customers with reliable solutions.

jasonbob said...

kevin durant
yeezy boost 350 v2
supreme clothing
kobe shoes
hermes birkin
yeezy boost 350 v2
kevin durant shoes
supreme clothing
supreme clothing
jordan shoes

Laila Thakur said...

Great article. Your blogs are unique and simple that is understood by anyone.

hpu 1st year result 2022

FMovies said...

I thoroughly enjoyed reading your post! The depth of valuable information presented in such an accessible and engaging manner made it a standout piece. Your ability to make intricate topics relatable is truly impressive.
fmovies

james said...

great article thankyou for sharing power bi career opportunities and job roles