n Source ...ber 2012

Page 61

CODE Sandya Mannarswamy

SPORT

Over the last couple of months, this column has covered dynamic languages such as JavaScript, and how they differ from traditional statically compiled languages like C or C++. Since many readers have requested a discussion on programming interview questions, this month’s column takes a break from JavaScript and features a medley of interview questions. Let’s first list this month’s interview questions: 1. You have been asked to design a price comparison website for online gold jewellery sellers. One of the ways of getting the data from online stores is to crawl their websites and get their product price lists. Hence, you need to design a code snippet that, given a URL, will crawl all URLs reachable from the page at that URL, and store the page contents of each URL as separate files in a directory. Write a C code snippet to do this. (Clue: Try to consider this a graph traversal problem.) 2. We are all familiar with the spanning trees of a graph. A spanning tree of a graph G(V,E) is a subset of the graph’s edges, such that it forms a tree spanning all vertices of the graph. The Minimum Spanning Tree (MST) of a graph with weighted edges is a spanning tree whose sum of edge weights is the minimum among all the spanning trees possible for a graph. Questions on spanning trees and MSTs are quite popular in software interviews, so do make sure you read up on algorithms to construct MSTs. Kruskal’s algorithm and Prim’s algorithms are popular for constructing MSTs. Both are greedy algorithms, which we have discussed in one of the earlier columns. Here is a variant of the standard MST question: If you are given a weighted graph, how can you find the maximum spanning tree? (The maximum spanning tree is the spanning tree whose sum of edge weights is the maximum.) Is it possible to use a greedy algorithm to

determine the maximum spanning tree? 3. Given a sequence of ‘n’ integers a1, a2, a3, …. an, what is the maximum number of inversions that are possible in any permutation of the sequence? An inversion is a pair of elements that are out of sorted order. For instance, an array of integers sorted in ascending order has zero inversions. Can you write a code snippet to determine the number of inversions, given a permutation of ‘n’ integers? What is the expected time complexity of your algorithm? 4. Many of the popular programming languages like Java, Ruby, Scala, JavaScript, etc, support automatic memory management, which means that dynamically allocated memory can be freed automatically by the language runtime once it is no longer needed. This is popularly known as garbage collection, and a number of complex algorithms have been developed for this purpose. However, C/ C++ requires the programmer to perform explicit memory management by freeing the memory through free/delete calls. What makes it difficult to implement an automatic memory reclamation facility for C? How would you design a garbage collector for C? What language features would you ask your developers to forego if you wanted to design an efficient garbage collector for C? 5. We are all familiar with the concept of adjacency in a graph. Two vertices are said to be adjacent if there is an edge connecting OCTOber 2012 | 61


Turn static files into dynamic content formats.

Create a flipbook

Articles inside

An Introduction to CloudBees

7min
pages 96-98

An Introduction to the Yocto Project

8min
pages 89-91

"OpenStack has emerged as a really important component for cloud

9min
pages 92-95

Ctags and Cscope

5min
pages 87-88

Android Push Notifications with GCM

5min
pages 85-86

Kernel Uevent: How Information is Passed from Kernel to User Space

6min
pages 72-74

The Semester Project-VI: File System on Block Device

5min
pages 78-80

Git Version Control Explained Advanced Options

10min
pages 81-84

Kernel Ticks and Task Scheduling

9min
pages 69-71

A Simple Guide to Building Your Own Linux Kernel

3min
pages 67-68

Get started with Kernel Module Programming

8min
pages 63-66

CodeSport

7min
pages 61-62

PHP Development: A Smart Career Move

5min
pages 56-57

Linux at Work

19min
pages 51-55

Track Time in Your Driver with Kernel Timers

6min
pages 58-60

"For developers who really question if Microsoft is serious about open source, my answer would be 'absolutely"— Mandar Naik,

16min
pages 39-42

Exploring Software ReviewBoard

4min
page 50

Web-based Platforms for Localisation

3min
pages 48-49

Using OpenBSD for the Server Infrastructure

17min
pages 43-47

GNOME Extensions: Spicing Up the Desktop Experience

10min
pages 34-38
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.