Table of Contents
ToggleTata Consultancy Services interview pyqs with solutions:
Here are Tata Consultancy Services interview pyqs with solutions, you can practise them(Tata Consultancy Services interview pyqs with solutions) for your interview for TCS/Tata Consultancy Services(Tata Consultancy Services interview pyqs with solutions).
Q)What do you understand about round trip time? (Tata Consultancy Services interview pyqs with solutions)
Solution: Round Trip Time (RTT) is the time it takes for a signal or data packet to travel from a source to a destination and back again. It’s a key metric in networking, as it helps measure the latency or delay in communication between two points. RTT is crucial for assessing network performance and is influenced by factors like distance, transmission speed, and network congestion.
Q)What is a Ping? (Tata Consultancy Services interview pyqs with solutions)
Solution: Ping is a network utility used to test the reachability of a device on a network and measure the Round Trip Time (RTT). It sends an Internet Control Message Protocol (ICMP) echo request to the target device, and when the device responds, Ping calculates how long it took to receive the reply. This helps in diagnosing network connectivity and performance.
Q)What is an array? (Tata Consultancy Services interview pyqs with solutions)
Solution: An array is a data structure that stores a collection of elements, typically of the same data type, in a contiguous block of memory. Each element in an array can be accessed by its index, with indexing usually starting from 0. Arrays are commonly used in programming to store multiple values in a single variable and to perform operations on collections of data efficiently.
Q)Given an array of 1s and 0s arrange the 1s together and 0s together in a single scan of the array. Optimize the boundary conditions. (Tata Consultancy Services interview pyqs with solutions)
Solution:
- Initialize two pointers:
left
at the start of the array andright
at the end. - Move
left
forward until you find a 0. - Move
right
backward until you find a 1. - Swap the elements at
left
andright
. - Continue this process until
left
is greater than or equal toright
.
Q)Define Data Abstraction. What are their importance? (Tata Consultancy Services interview pyqs with solutions)
Solution:
Data abstraction is the concept of hiding the complex implementation details of data and showing only the essential features to the user. It allows interaction with data at a high level without needing to understand the underlying complexities.
Importance:
- Simplifies Complexity: Makes it easier to work with complex systems by focusing on what data does rather than how it’s implemented.
- Enhances Security: Protects data by controlling access to its implementation details.
- Improves Maintainability: Simplifies code updates and changes, as the implementation can be modified without affecting the interface.
- Encourages Reusability: Abstracted components can be reused in different parts of a program or in different projects.
Q)What is Ethernet? (Tata Consultancy Services interview pyqs with solutions)
Solution: Ethernet is a widely used networking technology that connects devices in a local area network (LAN). It defines the protocols for data transmission over wired networks, typically using cables like twisted pair or fiber optic. Ethernet provides reliable, fast communication between devices, such as computers, routers, and switches, and is the foundation for most wired internet and network connections today.
Q)What is the tunnel mode in networking? (Tata Consultancy Services interview pyqs with solutions)
Solution: Tunnel mode is a mode in networking, particularly in VPNs (Virtual Private Networks), where the entire original IP packet is encrypted and encapsulated within a new IP packet. This mode provides secure communication by protecting both the data and the original IP header as the packet travels across an untrusted network. Tunnel mode is commonly used in site-to-site VPNs to connect entire networks securely over the internet.
Q)Discuss the RSA algorithm in brief. (Tata Consultancy Services interview pyqs with solutions)
Solution:
The RSA algorithm is a widely used public-key cryptosystem for secure data transmission. It works on the principle of asymmetric encryption, using a pair of keys: a public key for encryption and a private key for decryption.
Key Steps:
- Key Generation: Two large prime numbers are selected and multiplied to produce a modulus. The public and private keys are derived from this modulus and the chosen primes.
- Encryption: A sender uses the recipient’s public key to encrypt a message, converting plaintext into ciphertext.
- Decryption: The recipient uses their private key to decrypt the ciphertext back into the original plaintext.
Importance:
- Security: RSA relies on the computational difficulty of factoring large numbers, making it highly secure.
- Authentication: It also supports digital signatures, ensuring the authenticity and integrity of the message.
Q)Write a function to swap two numbers without using a temporary variable. (Tata Consultancy Services interview pyqs with solutions)
Solution: Code- (Java)
def swap(a, b):
a = a + b # Step 1: Add both numbers
b = a – b # Step 2: Subtract b from the new value of a, now b becomes the original value of a
a = a – b # Step 3: Subtract the new value of b from a, now a becomes the original value of b
return a, b
# Example usage
x = 5
y = 10
x, y = swap(x, y)
print(“Swapped values:”, x, y) # Output will be x = 10, y = 5
Explanation:
- Step 1:
a = a + b
adds both numbers together and stores the result ina
. - Step 2:
b = a - b
subtracts the original value ofb
froma
, resulting inb
being assigned the original value ofa
. - Step 3:
a = a - b
subtracts the new value ofb
(which is the originala
) froma
, resulting ina
being assigned the original value ofb
.
Q)Memory Allocation in C/C++ (Tata Consultancy Services interview pyqs with solutions)
Solution:
Memory allocation in C/C++ refers to the process of reserving memory space for variables or data structures during program execution. There are two main types:
- Static Allocation:
- Memory is allocated at compile time.
- The size of memory is fixed and cannot be changed during runtime.
- Examples: Global variables, static variables.
- Dynamic Allocation:
- Memory is allocated at runtime using functions like
malloc()
,calloc()
,realloc()
(in C) andnew
(in C++). - Allows for flexible memory usage, where memory can be allocated and freed as needed.
- Must be manually managed, i.e., memory allocated dynamically must be freed using
free()
(in C) ordelete
(in C++), to avoid memory leaks.
- Memory is allocated at runtime using functions like
Q)Write output of the program?
printf(“%d%d%d”,i,++i,i++); (Tata Consultancy Services interview pyqs with solutions)
Solution:
The output of the program printf("%d%d%d",i,++i,i++);
is undefined due to the use of sequence points.
Explanation:
- The
++i
andi++
operations modify the value ofi
, but the order in which these operations are evaluated is not defined in C/C++. - In the statement
printf("%d%d%d",i,++i,i++);
, the order in which the argumentsi
,++i
, andi++
are evaluated is unspecified, leading to unpredictable results.
The output can vary depending on the compiler and its optimization settings. Therefore, relying on such code is considered bad practice and should be avoided.
Q)In a software program, what is cyclomatic complexity? (Tata Consultancy Services interview pyqs with solutions)
Solution:
Cyclomatic complexity is a software metric used to measure the complexity of a program’s control flow. It counts the number of linearly independent paths through the program’s source code.
Key Points:
- Calculation: Cyclomatic complexity is calculated using the formula: M=E−N+2P
- where M is the cyclomatic complexity, E is the number of edges (transitions), N is the number of nodes (decision points), and P is the number of connected components (usually 1 for a single program).
- Interpretation: A higher cyclomatic complexity indicates more potential paths through the code, which can make testing and maintaining the code more difficult.
- Use: It helps in identifying complex areas in the code that may need more thorough testing or refactoring to improve maintainability.
Q)Give an instance where there was a bug that you didn’t find in black box testing but discovered in white box testing. (Tata Consultancy Services interview pyqs with solutions)
Solution: An instance could be when a specific edge case was missed during black box testing but was caught in white box testing. For example, if there was a bug in a loop that only occurs when the loop iterates a very high number of times, black box testing might not test such high iteration values. However, during white box testing, where the internal code structure is examined, the bug was discovered because the loop’s implementation was directly analyzed, revealing the issue when the loop reaches its upper boundary.
Q)What is slice splicing in software testing? What are its two types? (Tata Consultancy Services interview pyqs with solutions)
Solution:
Slice splicing in software testing refers to a technique used to isolate and analyze specific parts of the code, particularly in debugging and testing. It involves examining “slices” of code that are relevant to a particular variable or computation.
Two Types:
- Forward Slicing:
- Starts from a particular point in the code and includes all statements that are affected by this point.
- Useful for understanding the impact of a variable or a computation on the rest of the program.
- Backward Slicing:
- Starts from a point of interest (e.g., a variable) and includes all statements that influence that point.
- Helps in tracing the origins and dependencies of a particular value or state in the code.
Q)what is virtual function and pure virtual function? (Tata Consultancy Services interview pyqs with solutions)
Solution:
Virtual Function:
A virtual function is a function in a base class that can be overridden by derived classes. It allows for dynamic (runtime) polymorphism, enabling the correct function to be called based on the object type, even when accessed through a base class pointer or reference.
Pure Virtual Function:
A pure virtual function is a virtual function in a base class that has no implementation and must be overridden by derived classes. It’s declared by assigning 0
in the base class, making the class abstract (i.e., it cannot be instantiated).
Code-(CPP)
class Base {
public:
virtual void show() { /* code */ } // Virtual function
virtual void display() = 0; // Pure virtual function
};
Q)What are WPF and WCF? (Tata Consultancy Services interview pyqs with solutions)
Solution:
WPF (Windows Presentation Foundation):
WPF is a UI framework for building visually rich Windows desktop applications. It provides a consistent programming model for building applications with advanced graphics, animations, and data binding, using XAML (Extensible Application Markup Language) for design and C# for logic.
WCF (Windows Communication Foundation):
WCF is a framework for building service-oriented applications. It enables developers to create and consume services across different platforms, using various protocols (like HTTP, TCP, etc.). WCF supports features like security, transactions, and reliable messaging, making it suitable for distributed and networked applications.
Key Difference:
WPF is focused on the user interface, while WCF is focused on communication and services.
Q)Enlist the differences between AWT and Swing in Java. (Tata Consultancy Services interview pyqs with solutions)
Solution:
AWT (Abstract Window Toolkit) vs. Swing in Java:
- Platform Dependence:
- AWT: Platform-dependent; uses native OS components, leading to a different look and feel on different platforms.
- Swing: Platform-independent; provides a consistent look and feel across all platforms using lightweight components.
- Component Hierarchy:
- AWT: Components are heavyweight (rely on native peers).
- Swing: Components are lightweight (rendered by Java, not the OS).
- Look and Feel:
- AWT: Limited to the OS’s native look and feel.
- Swing: Offers a pluggable look and feel, allowing customization.
- Features:
- AWT: Basic GUI components with limited functionality.
- Swing: Richer set of components (e.g., tables, trees, sliders), and more advanced features.
- Performance:
- AWT: Generally faster because it uses native components.
- Swing: Slower due to additional abstraction and flexibility, but this is often negligible with modern hardware.
- Event Handling:
- AWT: Uses the event delegation model, but with fewer event-handling features.
- Swing: More sophisticated event-handling mechanisms, with more options for customization.
Q)Explain memory leak in C++. How can you avoid it? (Tata Consultancy Services interview pyqs with solutions)
Solution:
A memory leak in C++ occurs when a program allocates memory dynamically (using new
or malloc
) but fails to release it (using delete
or free
). This unreleased memory remains occupied and is no longer accessible, leading to wasted memory and potentially causing the program to run out of memory over time.
How to Avoid Memory Leaks:
- Always free allocated memory: Ensure that every
new
has a correspondingdelete
and everymalloc
has afree
. - Use smart pointers: Utilize C++ smart pointers (
std::unique_ptr
,std::shared_ptr
) which automatically manage memory and release it when no longer needed. - Track allocations: Maintain a clear structure of your code to track all memory allocations and deallocations.
- Avoid raw pointers: Minimize the use of raw pointers; prefer using standard containers (like
std::vector
) or smart pointers. - Tools: Use memory profiling tools like Valgrind to detect and fix memory leaks during development.
Q)Write a program in C to swap two numbers without help of a third variable. (Tata Consultancy Services interview pyqs with solutions)
Solution: Code- (C)
#include <stdio.h>
int main() {
int a = 5, b = 10;
// Swap without using a third variable
a = a + b; // Step 1: a becomes 15 (5+10)
b = a – b; // Step 2: b becomes 5 (15-10)
a = a – b; // Step 3: a becomes 10 (15-5)
printf(“After swapping: a = %d, b = %d\n”, a, b);
return 0;
}
Thank You For visiting our website. In our website, you get more such educational content so don’t forget to allow the notification for more such content.
For more visit: https://deepblogs.net/category/educational-courses/
For part 1, visit:
Tcs technical interview pyqs with answers updated for 2024. Guaranteed Selection, No doubt.