code interview yingcai xiao hari krishna bodicharla

Post on 24-Feb-2016

56 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Code Interview Yingcai Xiao Hari Krishna Bodicharla. Code Interview. What is it? Books The process The questions How to prepare?. What is it?. Code Interview: job interview involves designing and writing programs. (the contents relate to coding.). Digital Interview. - PowerPoint PPT Presentation

TRANSCRIPT

Code Interview

Yingcai XiaoHari Krishna Bodicharla

Code Interview

• What is it?• Books• The process• The questions• How to prepare?

What is it?

• Code Interview: job interview involves designing and writing programs. (the contents relate to coding.)

Digital Interview

• Digital Interview: online interview, video interview. The format relates to digital media. Can be real-time or pre-recorded.

Digital Interview

"The Essential Digital Interview Handbook" by Paul J. Bailo

online interview, good reference even for face-to-face interview.

Books on Code Interview (not in Safari)

•"Cracking the Coding Interview: 150 Programming Interview Questions and Answers" by Gayle Laakmann McDowell

•"Cracking the C, C++, and Java Interview" by S G Ganesh

The Process

• Usually after HR screening interview• Or after a phone interview• Can be online (digital)• Or face-to-face• Usually one-on-one with your interviewer. • You may have something to write on.

The Process

• You will be asked to write some code. • May need to talk through the question first• May be in an actual programming language • May be as pseudo-code.

The Questions

Compare two integers without using any comparison

operators?

The Questions

Swap two integers without using a temp?

The Questions

Which one is faster?

int I, J = 8;I = 0.5 * J;I = J / 2;I = J >> 1;

• Array• Linked List• Array List• Hash Table• Queue• Stack• Tree• Graph

Data Structures

Why different data structures?• Use minimum space (Array).• Fast to retrieve (Array).• Easy to search (Array, Indexing / Hashing, Tree).• Easy to modify (Linked List).• Persistent. (IDs not Pointers/References)• Sharable over the Internet. (XML)• Reduce coding errors. (Padded Array)

Data Structures

Persistent. (IDs not Pointers/References)• There is no use to save pointers/references or transmit them over the Internet. • Serialization (memory automatically allocated during loading)• Use indexes to link data instead of pointers/references (indexed faceset)

Data Structures

INDEX LINKED DATA STRUCTURE

Data Structure for Graphics

and Visualization

SERIALIZATION OF OBJECTS

Serialization

• Converting an object into a form that can be persisted or transported.

• Save objects to permanent storages.• Sent over the network. • Pass on to another object.

Deserialization

• Converts a stream into an object.

Together, these processes allow data to be easily stored and transferred.

Requirements for Serialization To allow an object to be serializable:• In a serializable class, you must ensure that

every instance variable of the class is also serializable.

• The class must be visible at the point of serialization.

• All primitive types are serializable.

Sample Code for Serialization// serializable classclass SerializeEmployee{public: 

char character;unsigned int id;

 // serializing methodvoid Serialize(::std::ostream &os);//static deserializing methodstatic SerializeEmployee Deserialize(::std::istream &is);

};  void SerializeEmployee::Serialize(std::ostream &os){

if (os.good()){os.write((char*)&character, sizeof(character));os.write((char*)&id, sizeof(id));}

}

Sample Code for DeserializationSerializeEmployee SerializeEmployee::Deserialize(std::istream &is){

SerializeEmployee retval;

if (is.good()){is.read((char*)&retval.character, sizeof(retval.character));is.read((char*)&retval.id, sizeof(retval.id));}if (is.fail()) {throw ::std::runtime_error("failed to read full struct");}return retval;

}

Sharable over the Internet. (XML)• Text based• User defined tags• No header• Inefficient

Data Structures

Reduce coding errors. (Padded Array)• Bounds checker• Use padding cells at the beginning or end of an array.• Error if the padding cells were written to.

Data Structures

Space Partitioning• Quad Tree (for rectangular shapes)• Triangulation (for irregular shapes)

Data Structures

• Bubble• Merge• Quick • Heap• Insertion

Sorting

top related